471,357 Members | 1,077 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

Paste a image into another

Hi, I'm trying to use the function paste() to paste a image into another image but I can't get it work! Is it the right function to use or is there any other function that's better?

Here's my very simple code:
Expand|Select|Wrap|Line Numbers
  1. from PIL import Image
  2. import ImageDraw
  3.  
  4. im = Image.new("RGB", (500,500), "white")
  5. draw = ImageDraw.Draw(im)
  6.  
  7. icon = Image.open("icon1.jpg")
  8. im.paste(icon, (0,0,86,62))
  9.  
  10. del draw
  11. im.save("test.jpg", "JPEG")
and the message:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Program Files\Eclipse 3.2.2\plugins\org.python.pydev.debug_1.3.4\pysrc\pydevd.py", line 754, in <module>
  3.     debugger.run(setup['file'], None, None)
  4.   File "C:\Program Files\Eclipse 3.2.2\plugins\org.python.pydev.debug_1.3.4\pysrc\pydevd.py", line 597, in run
  5.     execfile(file, globals, locals) #execute the script
  6.   File "C:\Documents and Settings\eviceng\My Documents\Python\cellTestare\src\paste.py", line 8, in <module>
  7.     im.paste(icon, (0,0,86,62))
  8.   File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1076, in paste
  9.     self.im.paste(im, box)
  10. ValueError: images do not match
/flaerpen
Jul 17 '07 #1
1 16562
ilikepython
844 Expert 512MB
Hi, I'm trying to use the function paste() to paste a image into another image but I can't get it work! Is it the right function to use or is there any other function that's better?

Here's my very simple code:
Expand|Select|Wrap|Line Numbers
  1. from PIL import Image
  2. import ImageDraw
  3.  
  4. im = Image.new("RGB", (500,500), "white")
  5. draw = ImageDraw.Draw(im)
  6.  
  7. icon = Image.open("icon1.jpg")
  8. im.paste(icon, (0,0,86,62))
  9.  
  10. del draw
  11. im.save("test.jpg", "JPEG")
and the message:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Program Files\Eclipse 3.2.2\plugins\org.python.pydev.debug_1.3.4\pysrc\pydevd.py", line 754, in <module>
  3.     debugger.run(setup['file'], None, None)
  4.   File "C:\Program Files\Eclipse 3.2.2\plugins\org.python.pydev.debug_1.3.4\pysrc\pydevd.py", line 597, in run
  5.     execfile(file, globals, locals) #execute the script
  6.   File "C:\Documents and Settings\eviceng\My Documents\Python\cellTestare\src\paste.py", line 8, in <module>
  7.     im.paste(icon, (0,0,86,62))
  8.   File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1076, in paste
  9.     self.im.paste(im, box)
  10. ValueError: images do not match
/flaerpen
I got this from the PIL website:
Expand|Select|Wrap|Line Numbers
  1. im.paste(image, box)
  2.  
  3. Pastes another image into this image. The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted image must match the size of the region.
  4.  
So either give a 2-tuple or make the coordinates match icon.jpg's.
Jul 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by jean-Baptiste Cazier | last post: by
2 posts views Thread by Caleb Hattingh | last post: by
3 posts views Thread by Scott Friedrich | last post: by
7 posts views Thread by lgbjr | last post: by
1 post views Thread by Peter Bengtsson | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.