1

I have a photo on my disk and I want to rotate it clockwise in 90 degrees. I'm trying to use PIllow as described here: https://pillow.readthedocs.io/en/stable/handbook/tutorial.html#geometrical-transforms

pill_img = Image.open(abs_img_src)
pill_img.rotate(90)

But nothing changes. Did I miss something?

1 Answer 1

1

It looks like it returns a new image, so you'll want something like

from PIL import Image

abs_img_src = 'test.png'

pill_img = Image.open(abs_img_src)
pill.show()

rotated_img = pill_img.rotate(90)
rotated_img.show()

If we let our 'test.png' be the Python logo

Python Logo

pill.show()

will output

Python Logo using pillow

rotated_img = pill_img.rotate(90)
rotated_img.show()

will result in

Python Logo rotated with pillow

Just to double check, let's now call im.show() after the im.rotate(90):

enter code here

Sure enough, we get the result we expected -- i.e., im.rotate does not mutate im, but rather it returns a new rotated Image.

Sign up to request clarification or add additional context in comments.

2 Comments

so I have to save rotated photo on disk? rotated_img.save(abs_img_src) ?
@ИгорьОлешко -- Correct. You'll want to save with rotated_img.save("rotated-" + abs_img_src) or some such.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.