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 #773: Accept a tuple as blur radius and ensure to call PIL blur filter with a tuple #774

Merged

Conversation

SvenBroeckling
Copy link
Contributor

This pr fixes #773. Pillow has changed the accepted type of the blur radius from int to tuple(int, int).

xy = self.radius
if isinstance(xy, (int, float)):
xy = (xy, xy)
return image.gaussian_blur(xy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about importing GaussianBlur from PIL.ImageFilter instead of copy-pasting pillow code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between those two classes was the base class, pillows GaussianBlur is a MultibandFilter, although the only occurance of ImageFilter.Filter in pil_engine.py is GaussianBlur. Maybe there was a reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, the ImageFilter is only imported when no ImportError happens, i.E. PIL is available. Would it make sense to change this and import the GaussianBlur from Pillow in this PR? Or is that a case for another refactoring PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to test some refactoring in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I'd love to see some test around this functionality (I think there are no currently).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an engine test in the SimpleTestCase and changed the pil_engine to use pillows GaussianBlur filter. I ran tox locally, but only with python 3.12.

I noticed that the other engines don't support blur anyways (so i borrowed the pil_engine unittest skipif). But each library has support for some kind of blur. I'd be happy to contribute to this feature with docs and tests in another PR.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.04%. Comparing base (f00421d) to head (8a6b366).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #774      +/-   ##
==========================================
+ Coverage   73.79%   74.04%   +0.25%     
==========================================
  Files          26       26              
  Lines        1675     1676       +1     
==========================================
+ Hits         1236     1241       +5     
+ Misses        439      435       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@claudep claudep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

The order of commits is a bit counterintuitive, but anyway, I think I'll squash them eventually.

@SvenBroeckling
Copy link
Contributor Author

Thanks!

@claudep claudep merged commit 594418a into jazzband:master Oct 22, 2024
34 checks passed
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.

Pillow 10.1 has changed the accepted type for gaussian_blur
2 participants