fix: improve upscaling for pixel art icons
- Use integer scaling (2x, 3x, 4x) instead of fractional for sharp pixels - Use NEAREST neighbor resampling (better for pixel art than Lanczos) - Add sharpening filter after upscale - Reduced padding to 85% so icons fill more of canvas This produces much sharper results for game icons!
This commit is contained in:
parent
c4aab56a9e
commit
da52b99a36
|
|
@ -420,7 +420,7 @@ class TGAConverter:
|
|||
Returns:
|
||||
New image with canvas size, source image centered
|
||||
"""
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
canvas_w, canvas_h = canvas_size
|
||||
img_w, img_h = image.size
|
||||
|
|
@ -430,14 +430,23 @@ class TGAConverter:
|
|||
|
||||
# Calculate scaling
|
||||
if upscale:
|
||||
# Scale up to fit within canvas with some padding (e.g., 90%)
|
||||
max_size = int(min(canvas_w, canvas_h) * 0.9)
|
||||
# Scale up to fit within canvas with some padding (e.g., 85%)
|
||||
max_size = int(min(canvas_w, canvas_h) * 0.85)
|
||||
scale = min(max_size / img_w, max_size / img_h)
|
||||
|
||||
if scale > 1: # Only upscale, never downscale
|
||||
new_w = int(img_w * scale)
|
||||
new_h = int(img_h * scale)
|
||||
image = image.resize((new_w, new_h), Image.Resampling.LANCZOS)
|
||||
# For pixel art/game icons, use integer scaling + NEAREST for sharpness
|
||||
# Round scale to nearest integer for clean pixel edges
|
||||
int_scale = max(1, round(scale))
|
||||
new_w = img_w * int_scale
|
||||
new_h = img_h * int_scale
|
||||
|
||||
# Use NEAREST neighbor for pixel art - keeps edges sharp
|
||||
image = image.resize((new_w, new_h), Image.Resampling.NEAREST)
|
||||
|
||||
# Apply slight sharpening to reduce blur from the upscale
|
||||
image = image.filter(ImageFilter.SHARPEN)
|
||||
|
||||
img_w, img_h = new_w, new_h
|
||||
|
||||
# Calculate centered position
|
||||
|
|
|
|||
Loading…
Reference in New Issue