472,989 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 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 17463
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:
Sl ! 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, Im 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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.