Mailing List Archive

DeprecationWarning but replacement doesn't work
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.


The code is very simple:-

...
...
from PIL import Image
...
...
im = Image.open(srcFile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(dstFile, "JPEG")


But if I change line 80 to:-

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


So, presumably there's more I need to change. Where can I find out what
I need to do?

--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list
Re: DeprecationWarning but replacement doesn't work [ In reply to ]
On Sun, 5 Feb 2023 at 07:52, Chris Green <cl@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
--
https://mail.python.org/mailman/listinfo/python-list
Re: DeprecationWarning but replacement doesn't work [ In reply to ]
Chris Green schreef op 4/02/2023 om 16:17:
> 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.
>
>
> But if I change line 80 to:-
>
> 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
>
>
> So, presumably there's more I need to change. Where can I find out what
> I need to do?
There's some information about changes in constants in the release notes
for version 9.1.0, see
https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html. At
first sight it looks like that indicates you have to do either

    from PIL import Image.Resampling as Resampling
    ...
    im.thumbnail(size, Resampling.LANCZOS)

or

    from PIL import Image.Resampling
    ...
    im.thumbnail(size, Image.Resampling.LANCZOS)

BUT according to the release notes of version 9.4.0 (see
https://pillow.readthedocs.io/en/stable/releasenotes/9.4.0.html#restored-image-constants)
the constants in Image will remain (it's not clear to me if the ones in
Image.Resample will remain too). As far as I can see ANTIALIAS is still
deprecated in favor of LANCZOS though. All in all, it looks like the way
to go is to use Image.LANCZOS. In versions 9.1.0 up to but not including
9.4.0 that will give you a deprecation warning but that can safely be
ignored.

--
"Life ain't no fairy tale
Just give me another ale
And I'll drink to Rock 'n Roll"
-- Barkeep (The Scabs)

--
https://mail.python.org/mailman/listinfo/python-list
Re: DeprecationWarning but replacement doesn't work [ In reply to ]
Roel Schroeven <roel@roelschroeven.net> wrote:
> Chris Green schreef op 4/02/2023 om 16:17:
> > 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.
>
> >
> >
> > But if I change line 80 to:-
> >
> > 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
> >
> >
> > So, presumably there's more I need to change. Where can I find out what
> > I need to do?
> There's some information about changes in constants in the release notes
> for version 9.1.0, see
> https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html. At
> first sight it looks like that indicates you have to do either
>
>     from PIL import Image.Resampling as Resampling
>     ...
>     im.thumbnail(size, Resampling.LANCZOS)
>
> or
>
>     from PIL import Image.Resampling
>     ...
>     im.thumbnail(size, Image.Resampling.LANCZOS)
>
> BUT according to the release notes of version 9.4.0 (see
> https://pillow.readthedocs.io/en/stable/releasenotes/9.4.0.html#restored-image-constants)
> the constants in Image will remain (it's not clear to me if the ones in
> Image.Resample will remain too). As far as I can see ANTIALIAS is still
> deprecated in favor of LANCZOS though. All in all, it looks like the way
> to go is to use Image.LANCZOS. In versions 9.1.0 up to but not including
> 9.4.0 that will give you a deprecation warning but that can safely be
> ignored.
>
Thank you Roel (and Chris in the previous reply) for your helpful
explanations, it's all cleared up now.

--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list