473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 17709
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

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

Similar topics

0
by: jean-Baptiste Cazier | last post by:
Sæl ! I am trying to rotate some text and paste it into a larger PIL Image. ( cannot use PyFT for some reasons) However I have a problem of transparency and my new images in a box shape are...
2
by: Caleb Hattingh | last post by:
Here's hoping effbot is around :) I have a really simple situation where I have 2 png images, and open them so: '>>> iconBallImage =...
1
by: James | last post by:
I'm very interested to hear if anyone has created an access database that enables a user to cut and paste an image from a web page into a database. The database then stores the image and then...
6
by: MLH | last post by:
I have a logo image that I can paste into MS Paint as an image with clear background. Think of the logo as a black circle in a white, rectangular background. When I paste into Paint, the white...
3
by: Scott Friedrich | last post by:
Hi group I am using a 3rd party AX control in a VB.NET application. One of the methods of this control is to capture the current map within the control to the windows clipboard as .WMF. I am...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: Peter Bengtsson | last post by:
I love the dropshadow effect I managed to make with this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474116 Here's what it can look like:...
0
by: Durand | last post by:
Hi! I'm trying to paste a png with a transparent layer into an image using "image.paste(tesla,(20,10), tesla)" but I'm getting this error: ValueError: bad transparency mask I have used...
2
by: crapycoder | last post by:
hi all, please help....!! i have added a kodak image edit control on my form. when i click get image button, "abc.img" will be displayed. i have a button named "copy to clipboard". when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.