Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pillow 3.0.0] Wrong rotate behavior #1500

Closed
novadev94 opened this issue Oct 21, 2015 · 8 comments
Closed

[Pillow 3.0.0] Wrong rotate behavior #1500

novadev94 opened this issue Oct 21, 2015 · 8 comments

Comments

@novadev94
Copy link

I've noticed this bug today. This happens in our production server.

from PIL import Image

img = Image.new('RGB', (1, 10), 'white')
print img.rotate(-90).size

With Pillow<=2.9.0 the size supposed to be (10, 1) as the image is rotated. However with the newest version Pillow==3.0.0, the size is (1, 10).

I've gone through the Changelog and haven't seen any changes related to rotation.

Could you guys please take a look? And I'm always ready to provide extra information.

@hugovk
Copy link
Member

hugovk commented Oct 21, 2015

Sounds like a regression. Time for git bisect!

1500.py:

from PIL import Image

img = Image.new('RGB', (1, 10), 'white')
assert(img.size == (1, 10))

assert(img.rotate(-90).size == (10, 1))

doit.sh:

python setup.py develop && python 1500.py

And:

git bisect good 2.9.0
git bisect bad 3.0.0
git bisect run ./doit.sh

Results in:

f6d11a2803aa0c04a9470e94e658e28a767c0426 is the first bad commit
commit f6d11a2803aa0c04a9470e94e658e28a767c0426
Date:   Thu Aug 6 00:23:14 2015 +1000

    Only use fast rotate operations if the expand flag is in use or the image is square

:040000 040000 25af01324a4ff8dd253cac961f8c1ed0c289ce50 1ff4ddc0c1aa6bda0db9a385560066bd09db8139 M  PIL
:040000 040000 009faaddc34798649998a1e12ae119ad1b4e28de a71b1b69646d881016b2bb6a63bdc1208422a356 M  Tests
:100644 100644 895faac545dfb24c40e3c5d8f1467d3253f15d38 7fd2da88e18cc570f809a0ac130824e7794f66fd M  _imaging.c

Here's the commit: f6d11a2. Ping @radarhere.

@radarhere
Copy link
Member

Hi. Yes, my commit is responsible for this change. However, this is actually correct behaviour. If you want the image to change size when rotated, you need to include the expand argument, e.g. img.rotate(-90, expand=1)

From the documentation -

expand – Optional expansion flag. If true, expands the output image to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image.

If you feel like Pillow should run differently, please feel free to suggest it.

@hugovk
Copy link
Member

hugovk commented Oct 22, 2015

OK, so a bug in 2.9.0, fixed in 3.0.0. Thanks @radarhere!

@novadev94 Please use expand.

@darkowic
Copy link

Thank you for @novadev94 for this issue. @radarhere why this is not added to changelog? This is big change of default behavior...

@radarhere
Copy link
Member

@darkowic hi. It's listed in the changelog as 'Fix fast rotate operations #1373'. The only other thing that I think I can say is that the change was a bug fix. If you think it should be listed more prominently, please feel free to submit a PR for review.

acdha added a commit to acdha/NativeImaging that referenced this issue Oct 23, 2017
These broke due to an upstream API change in PIL/Pillow (see
python-pillow/Pillow#1500) but this is also
fairly rarely used.
acdha added a commit to acdha/NativeImaging that referenced this issue Oct 30, 2017
These broke due to an upstream API change in PIL/Pillow (see
python-pillow/Pillow#1500) but this is also
fairly rarely used.
acdha added a commit to acdha/NativeImaging that referenced this issue Oct 30, 2017
These broke due to an upstream API change in PIL/Pillow (see
python-pillow/Pillow#1500) but this is also
fairly rarely used.
@darpan5552
Copy link

Hi. Yes, my commit is responsible for this change. However, this is actually correct behaviour. If you want the image to change size when rotated, you need to include the expand argument, e.g. img.rotate(-90, expand=1)

From the documentation -

expand – Optional expansion flag. If true, expands the output image to make it large enough to hold the entire rotated image. If false or omitted, make the output image the same size as the input image.

If you feel like Pillow should run differently, please feel free to suggest it.

Can you keep this documentation text in rotate method. I wasted my half day searching internet for a fix, but can't find this.
Meanwhile, i read rotate docs a 100 times. If it was there, i could have saved lot of time and may be others also who gave up and can't reach this page for a fix.

@hugovk
Copy link
Member

hugovk commented Mar 23, 2021

Which text exactly are you referring to? The quoted bit is still in the docs (highlighted in orange below):

image

@darpan5552
Copy link

Oh, i see, It was there but i was confused.
As i was using both resize and rotate, my whole focus was on issues with resize method.
For improvement, you can make it bit more catchy by adjusting language or make expand default to 1. I regret for my ignorance though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants