user167139
user167139

Reputation: 279

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

I need a functionality in Django to rotate 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?

Upvotes: 2

Views: 584

Answers (1)

Dominic Rodger
Dominic Rodger

Reputation: 99811

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.

Upvotes: 3

Related Questions