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:
LemonNexus 2026-02-11 16:53:44 +00:00
parent c4aab56a9e
commit da52b99a36
1 changed files with 15 additions and 6 deletions

View File

@ -420,7 +420,7 @@ class TGAConverter:
Returns: Returns:
New image with canvas size, source image centered New image with canvas size, source image centered
""" """
from PIL import Image from PIL import Image, ImageFilter
canvas_w, canvas_h = canvas_size canvas_w, canvas_h = canvas_size
img_w, img_h = image.size img_w, img_h = image.size
@ -430,14 +430,23 @@ class TGAConverter:
# Calculate scaling # Calculate scaling
if upscale: if upscale:
# Scale up to fit within canvas with some padding (e.g., 90%) # Scale up to fit within canvas with some padding (e.g., 85%)
max_size = int(min(canvas_w, canvas_h) * 0.9) max_size = int(min(canvas_w, canvas_h) * 0.85)
scale = min(max_size / img_w, max_size / img_h) scale = min(max_size / img_w, max_size / img_h)
if scale > 1: # Only upscale, never downscale if scale > 1: # Only upscale, never downscale
new_w = int(img_w * scale) # For pixel art/game icons, use integer scaling + NEAREST for sharpness
new_h = int(img_h * scale) # Round scale to nearest integer for clean pixel edges
image = image.resize((new_w, new_h), Image.Resampling.LANCZOS) 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 img_w, img_h = new_w, new_h
# Calculate centered position # Calculate centered position