开发者

How do I rotate/flip an image without using photologue/ImageModel?

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜