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

Support saving JPEG comments #1

Merged
merged 3 commits into from Dec 3, 2022

Conversation

radarhere
Copy link

Suggestions for python-pillow#6774

  1. Save comments from any image format by default. At the moment, your code doesn't produce a comment when saving a GIF.
from PIL import Image
im = Image.open("Tests/images/multiple_comments.gif")
im.seek(1)
print(im.info.get("comment"))  # b'Test comment 1\nTest comment 2'

im.save("out.jpg")
print(Image.open("out.jpg").info.get("comment"))  # None

This PR allows that to happen.

  1. Use _binary instead of struct. This isn't a correction to your code. It's actually taking advice from your code that _binary can be used instead of struct and applying that to another place in JpegImagePlugin.

  2. Test that comment is reread. Your test currently saves info["comment"] and then checks that it appears in app["COM"]. It seems more logical to me to check that it appears in info["comment"].

@smason smason merged commit e71f7c1 into smason:write-jpeg-com Dec 3, 2022
@smason
Copy link
Owner

smason commented Dec 3, 2022

Those all look sensible, thanks!

I wasn't sure about where to pull any prior comment from; im.info['comment'] looks much better.

I also wasn't sure about whether it was appropriate to clean up other parts of the code base, e.g. your struct vs. _binary change. It seemed like there were going to be quite a few, so I was going to open another pull request for that when I'd got a few together.

@radarhere radarhere deleted the write-jpeg-com branch December 3, 2022 20:45
smason pushed a commit that referenced this pull request Jul 7, 2023
smason pushed a commit that referenced this pull request Jul 7, 2023
smason pushed a commit that referenced this pull request Jul 7, 2023
Call init() if mimetype is not found with preinit()
smason pushed a commit that referenced this pull request Jul 7, 2023
Only assert image is similar
radarhere pushed a commit that referenced this pull request Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants