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

Reply via email to