Python Forum
[Tkinter] LANCZOS
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] LANCZOS
#1
HI,
I have an app that uses (PIL) Image.LANCZOS while resizing a TIF file.
The app runs fine on windows 11. No messages.
It also runs fine on my laptop with windows 10. But it produces a warning message
that Image.LANCZOS is going to be deprecated in 2023 and replaced by : Image.Resampling.LANCZOS

When I replace Image.LANCZOS by Image.Resampling.LANCZOS, i get an error.
What should I try?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
You could try
try:
    from PIL.Image.Resampling import LANCZOS
except ModuleNotFoundError: # for pre 2023 versions of PIL
    import warnings
    with warnings.catch_warnings():
        from PIL.Image import LANCZOS
Reply
#3
Thanks Gribouillis.
Runs smoothly on win 11 and win 10.
Win 10 still produces the message:
Output:
Warning (from warnings module): File "C:\VVF\20220523\search.py", line 129 resized_img = img.resize((newW,newH),Image.LANCZOS) DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
I also import PIL:
Output:
from PIL import ImageTk, Image
Not a big deal, but why refer to a release that is a year away?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#4
(May-28-2022, 07:48 AM)DPaul Wrote: why refer to a release that is a year away?
Really I don't know why. You could define
def resize(img, *args, **kwargs):
    with warnings.catch_warnings():
        img.resize(*args, **kwargs)
...
resized_img = resize(img, Image.LANCZOS)
Aso perhaps a better solution in Warnings Control
Reply
#5
I have a partial explanation, but no solution yet.
1) Running win 11, no warning -->Pillow 9.0 was installed !
2) running win 10, warning --> Pillow 9.1 was installed !

I have upgraded both to 9.1.1, and now both give the warning. Smile

I'll need to try the second suggestion. UPDATE: (tried it, still a warning)
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#6
Read perhaps the pymotw3 about warnings for hints about how to silence these warnings.
Reply
#7
Quote:Read perhaps the pymotw3 about warnings for hints about how to silence these warnings.
After some trial and error, this seems to do the trick:
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            resized_img = img.resize((newW,newH),Image.LANCZOS)
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020