[Tutor] PIL paste-in problems

kromag@nsacom.net kromag@nsacom.net
Wed, 8 Aug 2001 14:10:15 -0700 (PDT)


I am attempting to paste two images to either top corner of another image:

---------------begin pasty------------

import Image
import os
import sys
bg=Image.open("\windows\desktop\doug.jpg").crop()
paste_in=Image.open("\windows\desktop\robo.gif").crop()
#get the boundaries
bg_size=bg.getbbox()
paste_in_size=paste_in.getbbox()
#offset 10 pixels from the sides
offset=(10)
#establish positions
pos0=(bg_size[0]+offset, bg_size[1]+offset, paste_in_size[2]+offset, 
paste_in_size[3]+offset)
pos1=(bg_size[2] -paste_in_size[0] -offset,  bg_size[1] +offset,  bg_size[2] -
offset,  bg_size[1]+offset+paste_in_size[3])
#paste `em into the background image.
bg.paste(paste_in,pos0)
bg.paste(paste_in,pos1)
bg.save("\windows\desktop\test.jpg","JPEG")
#run dancing into the sunset wearing a lavender loincloth...

-----------------end pasty----------------


I get the error:

>pythonw -u card_builder.py
Traceback (most recent call last):
  File "card_builder.py", line 16, in ?
    bg.paste(paste_in,pos1)
  File "c:python20pilImage.py", line 571, in paste
    self.im.paste(im, box)
ValueError: images do not match
>Exit code: 1

Now I don't think my image is out of bounds. How can the images not match, 
since they are the same image? I must confess extreme confusion.