开发者

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

开发者 https://www.devze.com 2022-12-17 11:08 出处:网络
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.

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

精彩评论

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

关注公众号