Simple photo collage using Python and PIL

Thomas Guettler niemand.leermann at thomas-guettler.de
Wed Nov 23 10:27:32 EST 2005


Am Tue, 22 Nov 2005 16:10:10 -0800 schrieb Callum  Prentice:

> i need a "script" that i can use locally as well as online that will:
> 
> * create a large (maybe something like 2k x 2k) master image in memory
> * open a text file and read all the lines from it (maybe 1000 lines
> max)
> * each line is composed of an x, y, name and a png image filename
> * for each line,  open the png image and position it in the master
> image at the location given by x & y
> * save off the master image to a png at the end

Hi,

I would convert[1] the image to binary pnm[2]. This is a very easy
uncompressed image format. You don't need PIL to parse it.

Read the file into memory. You could use a matrix:

pic[0][0] first pixel
pic[-1][-1] last pixel

Then you coping or changing pixels is easy:

for x in xrange(?, ?):
    for y in xrange(?, ?):
        ...

At the end create png from pnm with convert.

I hope this helps.

 Thomas

[1] convert: http://www.imagemagick.org
[2] pnm: http://netpbm.sourceforge.net/doc/pnm.html

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: niemand.leermann at thomas-guettler.de




More information about the Python-list mailing list