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

Copy info in Image.transform #4128

Merged
merged 1 commit into from Nov 13, 2019
Merged

Copy info in Image.transform #4128

merged 1 commit into from Nov 13, 2019

Conversation

radarhere
Copy link
Member

from PIL import Image
im = Image.open("Tests/images/hopper.gif")

print(im.rotate(180).info)  # {'version': b'GIF89a', 'background': 0, 'duration': 0, 'comment': b'File written by Adobe Photoshop\xa8 4.0'}
print(im.rotate(181).info)  # {}

This inconsistency is because for some angles, rotate will copy or transpose for the sake of efficiency

Pillow/src/PIL/Image.py

Lines 1924 to 1932 in 8c94f01

if not (center or translate):
if angle == 0:
return self.copy()
if angle == 180:
return self.transpose(ROTATE_180)
if angle == 90 and expand:
return self.transpose(ROTATE_90)
if angle == 270 and expand:
return self.transpose(ROTATE_270)

instead of its usual transform.

return self.transform((w, h), AFFINE, matrix, resample, fillcolor=fillcolor)

transpose uses _new to create the new image, while transform uses new.

This PR resolves the inconsistent behaviour by ensuring that info is copied into transform images.

@hugovk hugovk merged commit 54e5776 into python-pillow:master Nov 13, 2019
@radarhere radarhere deleted the info branch November 13, 2019 19:42
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

Successfully merging this pull request may close these issues.

None yet

2 participants