DeprecationWarning but replacement doesn't work

Chris Angelico rosuav at gmail.com
Sat Feb 4 15:59:27 EST 2023


On Sun, 5 Feb 2023 at 07:52, Chris Green <cl at isbd.net> wrote:
>
> I am using Image from PIL and I'm getting a deprecation warning as
> follows:-
>
> /home/chris/bin/picShrink.py:80: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
>
>
>         im = Image.open(srcFile)
>         im.thumbnail(size, Image.ANTIALIAS)
>         im.save(dstFile, "JPEG")
>
>         im.thumbnail(size, Resampling.LANCZOS)
>
> I simply get an error as follows:-
>
>     picShrink.py
>     Traceback (most recent call last):
>       File "/home/chris/bin/picShrink.py", line 80, in <module>
>         im.thumbnail(size, Resampling.LANCZOS)
>     NameError: name 'Resampling' is not defined
>

It looks like Resampling is an enumeration. The warning said
"ANTIALIAS" as a bare name, and you were using Image.ANTIALIAS; it
looks like Image.Resampling.LANCZOS has the same effect.

In fact, it looks like they're actually the same value:

>>> Image.ANTIALIAS is Image.Resampling.LANCZOS
<stdin>:1: DeprecationWarning: ANTIALIAS is deprecated and will be
removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
True

So that should be a safe move forward.

ChrisA


More information about the Python-list mailing list