开发者

Upload image from webform in Python

I am new to python and I am assigned the task of making an ima开发者_运维百科ge uploade script from a webform in python. We are using Pylons.

I have a form submitting to a page and am trying to run the follow but I am getting this error

AttributeError: read

My code is this:

im = Image.open(request.POST['image'])  
im = im.convert("RGB")  
im = im.resize((70,70), Image.ANTIALIAS)  
im.save("/avatars/q5.png")

Any help is greatly, greatly appreciated!


I think you want to do this:

im = Image.open(StringIO(request.POST['image']))

since the Image.open function takes a file-like object not a buffer. The StringIO packages turns a buffer into a file-like object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜