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

Fixes #2504 in artresizer #3029

Merged
merged 2 commits into from
Sep 10, 2018
Merged

Fixes #2504 in artresizer #3029

merged 2 commits into from
Sep 10, 2018

Conversation

architek
Copy link
Contributor

@architek architek commented Sep 9, 2018

This PR fixes #2504

PIL Image.save() requires a string parameter [1] while with python3 we call it with bytes.
This leads to wrong format detection (b'.png' isn't a key in supported formats list whereas '.png' is).

I haven't found a better existing function to do this (feel free to change patch) nor a unit test using PIL Image.save.

[1] https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.save

PIL Image.save() requires a string parameter [1] while under python3 we call it with bytes.
This leads to wrong format detection (b'.png' isn't a key in supported formats list).

[1] https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.save
@sampsyo
Copy link
Member

sampsyo commented Sep 10, 2018

Cool! Thanks for looking into this.

displayable_path, however, is a lossy function that is just for printing out paths for human consumption. Can you please try our py3_path utility function, which is just for these poorly-behaved libraries that demand Unicode paths?

@architek
Copy link
Contributor Author

I've updated the PR to use py3_path
Thank you

@sampsyo
Copy link
Member

sampsyo commented Sep 10, 2018

Great! And just to check what should probably be obvious: have you tried this latest version of the change out on Python? Which Python version? Did it work on an example that it previously didn’t work for?

@architek
Copy link
Contributor Author

Sure I did test that.

But your question was a good opportunity to install and test with python 3.7 ;-)

In the end, using 2.7, 3.5 and 3.7 (ImageMagick not installed), I can confirm that:

  • KeyError bug when resizing images exists with 3.5 and 3.7,
  • It is not present anymore after using py3_path,
  • Using 2.7, still works fine

For reference, Python Image Library is Pillow 5.2.0.

Thank you

@sampsyo
Copy link
Member

sampsyo commented Sep 10, 2018

That is awesome! Thank you for the exhaustive testing! ✨ I'll merge this now. 🚀

@sampsyo sampsyo merged commit f3c48d0 into beetbox:master Sep 10, 2018
sampsyo added a commit that referenced this pull request Sep 10, 2018
sampsyo added a commit that referenced this pull request Sep 10, 2018
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.

fetchart: Catch PIL file type exception (KeyError) when resizing art
2 participants