Closed lene closed 2 years ago
Does this patch lead to compatible behaviour over different versions of Pillow?
Does this patch lead to compatible behaviour over different versions of Pillow?
No because of the Pillow version specifier that was added. https://github.com/python-pillow/Pillow/releases/tag/9.0.0 dropped support for Python 3.6 and below This should probably instead dynamically check for the installed pillow version in code then use the appropriate image resampling constant. As simple as:
from PIL import Image, __version__
__PIL_VERSION = tuple(map(int, __version__.split('.')))
if __PIL_VERSION >= (9, 1):
_RESAMPLING = Image.Resampling.LANCZOS
else:
_RESAMPLING = Image.ANTIALIAS
I am worried that if someone uses imagehash with some version of pillow, and now reinstalls imagehash with this PR applied, that the previously computed hashes do not match the same images any more, if the aliasing behaviour is different.
That's why I am wondering: is there is a pillow flag which brings back the exact aliasing behaviour of Image.ANTIALIAS?
https://pillow.readthedocs.io/en/stable/deprecations.html suggests that it is a rename
two users provided anecdotes that the behaviour is the same: https://www.reddit.com/r/learnpython/comments/uxb8b4/help_pillow_deprecation_warning/
I don't like the version checks, we should minimize this as much as possible, in favor of behaviour checks.
Maybe something like:
try:
ANTIALIAS = Image.Resampling.LANCZOS
except AttributeError:
ANTIALIAS = Image.ANTIALIAS
I don't like the version checks, we should minimize this as much as possible, in favor of behaviour checks.
Maybe something like:
try: ANTIALIAS = Image.Resampling.LANCZOS except AttributeError: ANTIALIAS = Image.ANTIALIAS
Oh yeah that's much better. Sometimes I forget that exceptions are totally valid for flow control in Python.
This is fixed in master.
Closes #164