diff --git a/modules/tga_converter.py b/modules/tga_converter.py index 02342d1..75e1482 100644 --- a/modules/tga_converter.py +++ b/modules/tga_converter.py @@ -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