#Python script to automatically upscale your 1x folder

1 messages · Page 1 of 1 (latest)

loud prawn
#
import os
from PIL import Image

input_dir = "./assets/1x/"
output_dir = "./assets/2x/"

os.makedirs(output_dir, exist_ok=True)

for filename in os.listdir(input_dir):
    if filename.endswith(".png"):
        if not os.path.exists(os.path.join(output_dir, filename)) or os.path.getmtime(os.path.join(output_dir, filename)) < os.path.getmtime(os.path.join(input_dir, filename)):
            if os.path.exists(os.path.join(output_dir, filename)):
                os.remove(os.path.join(output_dir, filename))
                print(f"❌ Deleted 2x of {filename}")
            else:
                print(f"🫥 2x of {filename} already doesn't exist")
            input_path = os.path.join(input_dir, filename)
            output_path = os.path.join(output_dir, filename)

            img = Image.open(input_path)
            scaled_img = img.resize((img.width * 2, img.height * 2), Image.NEAREST)
            scaled_img.save(output_path)

            print(f"✅ Upscaled {filename} to 2x")
        else:
            print(f"↪️ Ignored {filename} in 2x folder (1x hasn't been changed)")
    else:
        print(f"↪️ Ignored {filename} in 1x folder (not a PNG)")

Save this in your mod's root folder as something like upscale.py and run it after you make changes to the 1x atlases
This is a tweaked version of a script I found in someone else's mod that I don't remember anymore <.< Most relevant change I made is that it only does the upscaling if the 2x is older than the 1x (indicating that the 1x has been updated since last time the script was run)

eternal linden
#

Here's a Windows Batch script and Linux/Mac Shell script that do the same thing with ImageMagick instead of Python and Pillow (these expect to live in ./assets, but that's not hard to change)

#

also! I recommend including a shebang (#!/usr/bin/env python3) as the first line of the script, which makes this nicer to use on Linux

long sparrow
#

i wish there was an asprite extension so i could just do it straight from export

eternal linden
#

you can put one of these in a pre-commit hook so it happens without thinking whenever you push it to github

long trench
long sparrow