python - Can someone help me with my PIL function? -


def pad_image(f, width=500, height=none):     if height==none:         height = width     image = image.new("rgb", (800, 600),  (0, 0, 0, 0))     image.paste(stringio(f), (0,0, 50, 50))     res = stringio()     image.save(res, 'jpeg')     res.seek(0)     return res 

i trying paste image, f, in 500x500 white canvas. (in middle).

this function far, i'm having lots of trouble. i'm having many problems, , haven't touched height/width part.

traceback (most recent call last):   file "resizer.py", line 23, in <module>     thumbnail = tools.create_thumbnail(pic,300)   file "../lib/tools.py", line 84, in create_thumbnail     thumbnail_file = pad_image(thumbnail_file.read())   file "../lib/tools.py", line 92, in pad_image     image.paste(f, (0,0, 50, 50))   file "/usr/lib/python2.6/dist-packages/pil/image.py", line 1085, in paste     im = imagecolor.getcolor(im, self.mode)   file "/usr/lib/python2.6/dist-packages/pil/imagecolor.py", line 101, in getcolor     color = getrgb(color)   file "/usr/lib/python2.6/dist-packages/pil/imagecolor.py", line 97, in getrgb     raise valueerror("unknown color specifier: %r" % color) valueerror: unknown color specifier: '\xff\xd8\xff\ 

the first argument paste should image not stringio so

use image.paste(image.open(stringio(f)), (0,0, 50, 50)) instead

but should check size of f before pasting it paste upper left corner if it's bigger 50x50


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -