Python . tilemap tool. Where to start?

Hi,

I want to make a little tool for creating tilemaps from a series of images. Such as : http://i.imgur.com/Q1OQM.png for instance.

My tool will simply get the size of each images, check they are all the same, and fit them all, aligned, into a bigger image².

I want to do this tool in Python to start learning it a bit more, it seem to me fairly simple enough, perfect for starting slowly.
Python would maybe not the best choice to do this tool, but I already have some Maxscript experience and Python is the next thing I want to learn (And I really really want to do this tool).

I have found some library in searching a bit on google and especially this one that’s sounds good :
http://effbot.org/imagingbook/introduction.htm
http://effbot.org/zone/pil-index.htm

But maybe do you know some other better for what I want to achieve ? (or maybe this one isn’t good ? I am fairly noob in Python :D:)

Thanks
Bloby

[QUOTE=Bloby;24583]I already have some Maxscript experience[/QUOTE]

You can do this with maxscript using pasteBitmap…
first you calculate the finale bitmap size…
create the final bitmap image…

bFinal = bitmap finalWidth finalHeight

then you paste the images in the final bitmap image using pasteImage

pasteBitmap bTemp bFinal (box2 0 0 bTemp.width bTemp.height) [xOffset,yOffset]

Hi, well, thanks, but I want to do it in Python really :slight_smile: The purpose is to learn python on a tool I actually need :).

  • I don’t want this tool being “in a software”, I will make it executable from windows directly.

as for python…

from PIL import Image

to get the image size from the images you can do

img = Image.open(pImg)
width, height = img.size

same make final image with the calculated size

iFinal = Image.new( 'RGB', (255,255), "black")

paste iamges…

iFinal.paste(iTemp, (0,0), iTemp.convert("RGB") )

Arg don’t spoil me like this ! I just wanted advises on where to find the code I need. Not the code itself :smiley: . In max I know where to look for it, in the Maxscript reference. For python… well I havn’t really find one equivalent.

I have first found this : The Python Standard Library — Python 3.12.6 documentation but havnt found anything in there usefull for me (or I don’t know how to use it.) Then I have found this : http://effbot.org/imagingbook/overview.htm which seems to go in the direction I want.
Actually I would be very interested to know where you get this code you pasted here, the “where” is exactly what I am looking for.

Thanks
Bloby

i also know python quite well…
one of the python scripts that i made was to crop image…
so some of the code is from that…
and since you know you are going to use Image from PIL in python it’s quite easy to see the commands…
open python

from PIL import Image
help(Image)
# help(Image.new)

that will show you what you can do with the Image module… and you can start from there :slight_smile:

Anytime,
Remus

Note PIL does not come with python…
you can find almost all the python modules here…
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow

Hi, wonderfull ! thanks, that’s what I’m looking for :slight_smile: I wasnt sure about PIL (there was maybe something else better ? This is quite new for me). Looks like I have all I need now (and more!) :slight_smile:
Thanks very much !
Bloby.

There are several python bindings for imageMagick: http://www.imagemagick.org/

Im working on a similar tool doing this with renderend out frames from maya dynamics. What im still trying to figure out is the best way to have the code layout the images into a grid, and what scale factor has to be used in cases where they wont all fit.

Anyone got insight on this?
Knowen info would be the final image res, and the res for the input images, and how many images…

What about the series of image give you the final image size (so no scale factor) ? That’s what I will do actually.

Using the surface of each images.
Getting the number of pixel for all of the images (width * height * number of images), I get the square root to get a square capable of containing this total surface of my images and I roundup to the next power of two above.
if I have 21 images of 3264
the surface give me 21
3264= 43008
the square root of 43008 give me 207 and bananas.
If I roundup to the next power of two I get 256
256.

Only problem I get only squares, and depending on my series of images, in some cases, I could end up using only half of the map. So it will need another step after to get the blank space, how many lines the tool did on the square, and somehow get a ratio out of that to make the map longer while croping the height, while keeping a power of 2. something like that.

ya that sounds right, but like you said you can only use power of 2 textures and squares, how are you doing your rounding, something like this?


import math

rounded = int(pow(2, math.ceil(math.log(res, 2))))

I don’t know yet how I will be doing my rounding : ) I have just thinking to the theory and gather references, framework ready for my next Pizza/Code weekend : ) Haven’t look in details yet : )

Have you figured out a way to work with non square textures yet?

I was experimenting a bit with the Photoshop api, and got something similar working with the squarert method, but this is very limiting since both my input textures and the final texture must be square.

[QUOTE=passerby;24628]Have you figured out a way to work with non square textures yet?

I was experimenting a bit with the Photoshop api, and got something similar working with the squarert method, but this is very limiting since both my input textures and the final texture must be square.[/QUOTE]

Havent started yet :slight_smile: No time outside the weekend.
With “my” methode input textures dont have to be square, only the output will. I am sure there is some way to then optimize that by looking at the free space on the texture and the nulber of “row” but I am not here yet.

Edit : not sure how to delete posts.