Python

Smart Sprite Scaling with Pillow

Original game assets were designed as 16 times 16 pixel sprite sheets in 3 times 10 grids. While perfect for a retro engine, they were too small for modern web display. Manual resizing was out of the question, as I needed to maintain pixel-perfect integrity (no blurring) and keep the animation frames aligned.

April 4, 2026

The Solution:

I developed a Python script using Pillow (PIL) to automate the transformation:

  • Intelligent Slicing: The script calculates grid coordinates to "harvest" individual $16 \times 16$ frames from bulk sheets.

  • Nearest-Neighbor Scaling: Resizes sprites to $48 \times 48$ while preserving the crisp, pixel-art aesthetic.

  • Categorized Reassembly: It identifies the monster’s "stage" (Egg, Rookie, Mega, etc.) from the filename and sorts them into specific directories.

  • Reference Generation: It automatically generates a combined_sprites.png sheet, providing a quick visual "atlas" for testing and debugging.

 

The Result:

What would have taken hours of manual cropping and scaling is now a sub-second operation, ensuring every monster and item in the game is perfectly uniform.

More Projects

View All Projects