PIL question

Peter Otten __peter__ at web.de
Tue Apr 6 11:47:51 CEST 2010


Tim Eichholz wrote:

> I think maybe I am using the wrong function. I want to paste the
> entire 192x192 contents of cols[f] into newimage. I would think it
> works like newimage.paste(cols[f], (x, 0, 192+x, 192)) if that's not
> it I think I'm missing a function

Don't "think"! Read the documentation or, if that is hard to understand, 
write a tiny script that excercises only the function in question.


I can't test your script because it's not "self-contained" (doesn't run 
without user input), but I'm quite certain that the images that you generate 
with

c = 1
while c <= ncols:
        cols += [image.crop((framew*c, 0, frameh*(c+1), frameh*(c+1)))]
        c += 1

are not of the size 192x192. Assuming 

>>> framew = frameh = 192
>>> ncols = 3
>>> c = 1
>>> while c <= ncols:
...     box = framew*c, 0, frameh*(c+1), frameh*(c+1)
...     print "width =", box[2] - box[0], "height =", box[3] - box[1]
...     c += 1
...
width = 192 height = 384
width = 192 height = 576
width = 192 height = 768

See? You need to redo the maths and go through every step of your script, 
throw in some diagnostics code to verify that it does what you expect, and 
only then proceed to the next operation.

My hunch is that crop() doesn't do what you want rather than paste(), but to 
be sure you'd have to explain in plain English what the final image should 
look like.

Peter




More information about the Python-list mailing list