I need a functionality in Django to rota开发者_如何转开发te an image posted by users using a form. I need a method I can maybe put in imageutils.py and then use it in my form.
How can it be achieved?
Use the Python Imaging Library directly:
from PIL import Image
im = Image.open("yourfilename.jpg")
im = im.rotate(90)
im.save("yourrotatedfilename.jpg", "JPEG")
This is tested, and works. You'll need to have the Python Imaging Library installed and on your Python path, obviously, and you'll need to find the appropriate place to run this code (which is probably when your form is being saved).
This makes the assumption that you're dealing with JPEG files, but PIL a bunch of formats are supported.
精彩评论