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?
精彩评论