开发者

Rotate image uploaded via email using PIL for Django website

My website allows users to upload photos to their gallery via email and it works perfectly. However, photos taken on the iPhone in portrait mode do NOT rotate correctly. I would like to rotate the photo using PIL during the "mail filtering" proces开发者_JAVA技巧s. Here is the code that I am using to successfully retrieve the image from the email and save to my Django model

    image = ContentFile(b64decode(part.get_payload()))
    img = Photo(user=user)
    filename = part.get_filename().lower()
    img.img.save(filename, image)
    img.save()

*Updated code that successfully rotates temp image to local dir *

     image = ContentFile(b64decode(part.get_payload()))
     im = Image.open(image)
     tempfile = im.rotate(90)
     tempfile.save("/srv/www/mysite.com/public_html/media/images/rotate.jpg", "JPEG")
     img = Photo(user=user)
     img.img.save('rotate.jpg', tempfile)
     img.save()

Now, I'm trying to take the "temp image" and save it to my model. Unfortunately, it is not saving. Any suggestions would be greatly appreciated.


http://effbot.org/imagingbook/image.htm

clearly states that rotate() returns an new image instance.

There is nothing in the documentation about in-place operations. Or?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜