Reputation: 61
I've been messing around in python with PIL and I'm working on a function that mirrors and image in 4 quadrants. Obviously I got an error and I can't seem to figure it out. My function is as follows:
def mirror_four(image):
x = image.size[0]
y = image.size[1]
temp = Image.new("RGB", (image.size[0], image.size[1]), "black")
tl = image
tr = mirror_left(image)
bl = mirror_verticle(image)
br = mirror_verticle(tr)
image.paste(temp,(0,0,int(x/2),int(y/2)),tl)
image.paste(temp,(int(x/2),0,0,int(y/2)),tr)
image.paste(temp,(0,int(y/2),int(x/2),0),bl)
image.paste(temp,(x/2,y/2,x,y),br)
return temp
This returns the error: ValueError: Images do not match
I'm a little lost and the PIL documentation doesn't help me much.
Upvotes: 6
Views: 9373
Reputation: 383
The parameter you provided for box is wrong.
It should be image.paste(the_second_image, (x, y, x+w, y+h)
Do not change the the last two parameters. What you can do is, w, h = the_second_image.size() image.paste(the_second_image, (x, y, x+w, y+h)
This will work, it worked for me.
Upvotes: 1
Reputation: 1039
Using your first paste line as an example - for the 'box' argument of 'paste', you have specified (0,0,int(x/2),int(y/2) - half the size of the image. However, the image are trying to paste does not match the size of the box. Changing the 'box' argument to (0,0,int(x),int(y)) will fix your immediate problem, although I suspect you actually want to crop the image being pasted.
I'll also note that you don't have to provide the size of the image being pasted if you don't want to - (0,0) as x and y works as well.
Upvotes: 5