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.
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: f6d11a2803aa0c04a9470e94e658e28a767c0426. Ping @radarhere.
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)
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.
OK, so a bug in 2.9.0, fixed in 3.0.0. Thanks @radarhere!
@NovaDev94 Please use expand.
Thank you for @NovaDev94 for this issue. @radarhere why this is not added to changelog? This is big change of default behavior...
@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.
Most helpful comment
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
expandargument, e.g.img.rotate(-90, expand=1)From the documentation -
If you feel like Pillow should run differently, please feel free to suggest it.