Jump to content

Tileset Resizer (python script)


Recommended Posts

Hey there !


I've been looking a way to resize every tile in a tileset but didn't find any tool, so ... here is a script to do it :

from PIL import Image
import os

tileBaseSize = int(input("Tile base size ? (ex : 48)"))
tileNewSize = int(input("Tile new size ? (ex : 32)"))

for x in os.listdir():
    if x.endswith(".png"):
        # Read the image
        im = Image.open(x)
        width, height = im.size
        newim = Image.new(mode="RGBA", size=(width, height))
        i = 0
        j = 0
        for w in range(0,width, tileBaseSize):
            for h in range(0,height,tileBaseSize):    
                # Image size
                size = (tileNewSize, tileNewSize)
                bx = (w, h, tileBaseSize+w,tileBaseSize+h)
                # Resize image
                out = im.resize(size,box=bx)
                newim.paste(out, (i*tileNewSize,j*tileNewSize))
                j = j+1
            i= i +1
        # Save resized image

Prerequired :


Pillow library


Usage :

Put the script in a folder with tileset to resize, it will resize every tileset in folder and create new ones in the folder.


For instance :

I put my 48x48 tilset in my "ToResizeFolder", also my script in "ToResizeFolder".

I want my tileses to be 32x32 so I launch my script (on windows : python.exe .\ResizeTile.py)

It prompt me wich size is my base tileset so it's 48, press enter and which size I want my tileset instead, I enter 32 then press enter. 

Here it is. Your file is named 32x32_thebasename.png


Well, cheers !


Link to comment
Share on other sites

I did this with a photoshop batch and I ended up with wrapping tiles not looking right because the edges were off from like artifacts or whatever upscale compression (I'm obviously not a graphics artist). Does this mess up the edges?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...