| | |
Paste a image into another
Thread Solved |
•
•
Join Date: Jun 2007
Posts: 23
Reputation:
Solved Threads: 1
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:
and the message:
Here's my very simple code:
python Syntax (Toggle Plain Text)
from PIL import Image import ImageDraw im = Image.new("RGB", (500,500), "white") draw = ImageDraw.Draw(im) icon = Image.open("icon1.jpg") im.paste(icon, (0,0,86,62)) del draw im.save("test.jpg", "JPEG")
and the message:
Python Syntax (Toggle Plain Text)
Traceback (most recent call last): File "C:\Program Files\Eclipse 3.2.2\plugins\org.python.pydev.debug_1.3.4\pysrc\pydevd.py", line 754, in <module> debugger.run(setup['file'], None, None) File "C:\Program Files\Eclipse 3.2.2\plugins\org.python.pydev.debug_1.3.4\pysrc\pydevd.py", line 597, in run execfile(file, globals, locals) #execute the script File "C:\Documents and Settings\eviceng\My Documents\Python\cellTestare\src\paste.py", line 8, in <module> im.paste(icon, (0,0,86,62)) File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1076, in paste self.im.paste(im, box) ValueError: images do not match
Make sure you give it the correct size of the icon ...
python Syntax (Toggle Plain Text)
from PIL import Image import ImageDraw im = Image.new("RGB", (500,500), "white") draw = ImageDraw.Draw(im) icon = Image.open("icon1.jpg") # get the correct size x, y = icon.size im.paste(icon, (0,0,x,y)) del draw im.save("test.jpg", "JPEG") # optional, show the saved image in the default viewer (works in Windows) import webbrowser webbrowser.open("test.jpg")
May 'the Google' be with you!
•
•
Join Date: Jun 2007
Posts: 23
Reputation:
Solved Threads: 1
Are you really sure? Because I know (86,62) is the right height and width. I can't test your code but I'll do first thing in the morning.
If I remember right I changed that line to icon.getbbox(), like this, before I went home from work:
and I got a white image, nothing in there when I opened the image.
If I remember right I changed that line to icon.getbbox(), like this, before I went home from work:
python Syntax (Toggle Plain Text)
im.paste(icon, icon.getbbox())
and I got a white image, nothing in there when I opened the image.
Strange, either method works fine for me!
I have Windows XP. What OS are you using? Shouldn't make a difference. Is your icon file a true JPEG?
Use ...
this should show "RGB"
I have Windows XP. What OS are you using? Shouldn't make a difference. Is your icon file a true JPEG?
Use ...
python Syntax (Toggle Plain Text)
print icon.mode
Last edited by vegaseat; Jul 17th, 2007 at 6:04 pm.
May 'the Google' be with you!
•
•
Join Date: Jun 2007
Posts: 23
Reputation:
Solved Threads: 1
Ahh, your code is working! But I now know why my script didn't work: I'm using the aggdraw module with PIL. my code look like this:
and it's mostly the same and the only thing, that i can see, that isn't the same is:
draw = aggdraw.Draw(im)
and
draw.flush()
python Syntax (Toggle Plain Text)
from PIL import Image import ImageDraw import aggdraw im = Image.new("RGB", (500,500), "white") draw = aggdraw.Draw(im) icon = Image.open("icon.jpg") # get the correct size x, y = icon.size im.paste(icon, (0,0,x,y)) draw.flush() im.save("test.jpg", "JPEG")
and it's mostly the same and the only thing, that i can see, that isn't the same is:
draw = aggdraw.Draw(im)
and
draw.flush()
![]() |
Similar Threads
- How get Image byte size & transfer Image over Socket? (Java)
- GlobalSpec ad blocks notebooks of forum menu (DaniWeb Community Feedback)
- Unknown Bootup Command (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Cookie retrieval works in python but not IE
- Next Thread: Data View
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






