• Re: DeprecationWarning but replacement doesn't work

    From Stefan Ram@21:1/5 to Chris Green on Sat Feb 4 15:31:51 2023
    Chris Green <cl@isbd.net> writes: Where can I find out what
    I need to do?

    In the World-Wide Web! But don't worry, I have already gone
    to the World-Wide Web and got that piece of information for you!
    Apparently (I have not tested it), it's "Image.Resampling.LANCZOS"
    (after "from PIL import Image"). (I have not tested this, only
    read it on the World-Wide Web.) Should also be in the documentation
    of PIL.

    The World Wide Web (WWW), commonly known as the Web, is an
    information system enabling documents and other web resources
    to be accessed over the Internet. You may ask the party
    that now is providing Usenet access to you, whether it also
    supports the Internet. Then, you can use "search engines" that
    will find pieces of information from the Web, the so-called
    "Web pages", that contain a certain text. I carefully typed
    that "Resampling.LANCZOS" into one such search engine and
    then got that piece of information.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Green@21:1/5 to All on Sat Feb 4 15:17:38 2023
    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
    ·

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Chris Green on Sun Feb 5 07:59:27 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roel Schroeven@21:1/5 to Chris Green on Sat Feb 4 22:06:59 2023
    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Green@21:1/5 to Roel Schroeven on Sun Feb 5 06:42:38 2023
    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
    ·

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)