From 377673070981329149108f9e088da0ed305ce835 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Thu, 5 Oct 2023 16:11:51 -0400 Subject: [PATCH] Replaced PIL's deprecated constant ANTIALIAS with LANCZOS --- DemoPrograms/Demo_Buttons_Nice_Graphics.py | 2 +- DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py | 2 +- DemoPrograms/Demo_Emoji_Toolbar_PIL.py | 2 +- DemoPrograms/Demo_Graph_Elem_Image_Album.py | 2 +- DemoPrograms/Demo_Image_Elem_Image_Viewer_PIL_Based.py | 2 +- DemoPrograms/Demo_Image_Resize_and_Base64_Encode.pyw | 2 +- DemoPrograms/Demo_Image_Viewer_Thumbnails.py | 2 +- DemoPrograms/Demo_Matplotlib_Grid_of_Graphs_Using_PIL.py | 2 +- DemoPrograms/Demo_Nice_Buttons.py | 2 +- DemoPrograms/Demo_PIL_Use.py | 2 +- DemoPrograms/Demo_PNG_Thumbnail_Viewer.py | 6 +++--- DemoPrograms/Demo_System_Tray_Reminder.py | 2 +- docs/cookbook.md | 4 ++-- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/DemoPrograms/Demo_Buttons_Nice_Graphics.py b/DemoPrograms/Demo_Buttons_Nice_Graphics.py index 3d372416..45b3c915 100644 --- a/DemoPrograms/Demo_Buttons_Nice_Graphics.py +++ b/DemoPrograms/Demo_Buttons_Nice_Graphics.py @@ -26,7 +26,7 @@ def resize_base64_image(image64, size): ''' image_file = io.BytesIO(base64.b64decode(image64)) img = Image.open(image_file) - img.thumbnail(size, Image.ANTIALIAS) + img.thumbnail(size, Image.LANCZOS) bio = io.BytesIO() img.save(bio, format='PNG') imgbytes = bio.getvalue() diff --git a/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py b/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py index 8aec989c..2e5f6bb0 100644 --- a/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py +++ b/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py @@ -81,7 +81,7 @@ def convert_to_bytes(source, size=(None, None), subsample=None, zoom=None, fill= elif zoom is not None: scale = zoom - resized_image = image.resize((int(width * scale), int(height * scale)), Image.ANTIALIAS) if scale is not None else image + resized_image = image.resize((int(width * scale), int(height * scale)), Image.LANCZOS) if scale is not None else image if fill and scale is not None: resized_image = make_square(resized_image) # encode a PNG formatted version of image into BASE64 diff --git a/DemoPrograms/Demo_Emoji_Toolbar_PIL.py b/DemoPrograms/Demo_Emoji_Toolbar_PIL.py index 0ff22ce9..ee4b84b5 100644 --- a/DemoPrograms/Demo_Emoji_Toolbar_PIL.py +++ b/DemoPrograms/Demo_Emoji_Toolbar_PIL.py @@ -92,7 +92,7 @@ def convert_to_bytes(file_or_bytes, resize=None, fill=False): if resize: new_width, new_height = resize scale = min(new_height / cur_height, new_width / cur_width) - img = img.resize((int(cur_width * scale), int(cur_height * scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width * scale), int(cur_height * scale)), PIL. Image.LANCZOS) if fill: if resize is not None: img = make_square(img, resize[0]) diff --git a/DemoPrograms/Demo_Graph_Elem_Image_Album.py b/DemoPrograms/Demo_Graph_Elem_Image_Album.py index 115f72c5..90f2770e 100644 --- a/DemoPrograms/Demo_Graph_Elem_Image_Album.py +++ b/DemoPrograms/Demo_Graph_Elem_Image_Album.py @@ -44,7 +44,7 @@ def convert_to_bytes(file_or_bytes, resize=None): if resize: new_width, new_height = resize scale = min(new_height/cur_height, new_width/cur_width) - img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL. Image.LANCZOS) bio = io.BytesIO() img.save(bio, format="PNG") del img diff --git a/DemoPrograms/Demo_Image_Elem_Image_Viewer_PIL_Based.py b/DemoPrograms/Demo_Image_Elem_Image_Viewer_PIL_Based.py index 715bb351..9cb05b8c 100644 --- a/DemoPrograms/Demo_Image_Elem_Image_Viewer_PIL_Based.py +++ b/DemoPrograms/Demo_Image_Elem_Image_Viewer_PIL_Based.py @@ -45,7 +45,7 @@ def convert_to_bytes(file_or_bytes, resize=None): if resize: new_width, new_height = resize scale = min(new_height/cur_height, new_width/cur_width) - img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL. Image.LANCZOS) with io.BytesIO() as bio: img.save(bio, format="PNG") del img diff --git a/DemoPrograms/Demo_Image_Resize_and_Base64_Encode.pyw b/DemoPrograms/Demo_Image_Resize_and_Base64_Encode.pyw index 12e880be..f1a00789 100644 --- a/DemoPrograms/Demo_Image_Resize_and_Base64_Encode.pyw +++ b/DemoPrograms/Demo_Image_Resize_and_Base64_Encode.pyw @@ -55,7 +55,7 @@ def resize(input_file, size, output_file=None, encode_format='PNG'): new_width, new_height = size if new_width != width or new_height != height: # if the requested size is different than original size scale = min(new_height / height, new_width / width) - resized_image = image.resize((int(width * scale), int(height * scale)), Image.ANTIALIAS) + resized_image = image.resize((int(width * scale), int(height * scale)), Image.LANCZOS) else: resized_image = image diff --git a/DemoPrograms/Demo_Image_Viewer_Thumbnails.py b/DemoPrograms/Demo_Image_Viewer_Thumbnails.py index c766fed2..43742cc8 100644 --- a/DemoPrograms/Demo_Image_Viewer_Thumbnails.py +++ b/DemoPrograms/Demo_Image_Viewer_Thumbnails.py @@ -56,7 +56,7 @@ def convert_to_bytes(file_or_bytes, resize=None, fill=False): if resize: new_width, new_height = resize scale = min(new_height / cur_height, new_width / cur_width) - img = img.resize((int(cur_width * scale), int(cur_height * scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width * scale), int(cur_height * scale)), PIL. Image.LANCZOS) if fill: img = make_square(img, THUMBNAIL_SIZE[0]) with io.BytesIO() as bio: diff --git a/DemoPrograms/Demo_Matplotlib_Grid_of_Graphs_Using_PIL.py b/DemoPrograms/Demo_Matplotlib_Grid_of_Graphs_Using_PIL.py index f42f26ee..fb253de3 100644 --- a/DemoPrograms/Demo_Matplotlib_Grid_of_Graphs_Using_PIL.py +++ b/DemoPrograms/Demo_Matplotlib_Grid_of_Graphs_Using_PIL.py @@ -890,7 +890,7 @@ def convert_to_bytes(file_or_bytes, resize=None): if resize: new_width, new_height = resize scale = min(new_height/cur_height, new_width/cur_width) - img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL. Image.LANCZOS) with io.BytesIO() as bio: img.save(bio, format="PNG") del img diff --git a/DemoPrograms/Demo_Nice_Buttons.py b/DemoPrograms/Demo_Nice_Buttons.py index a1cefe13..9e782d11 100644 --- a/DemoPrograms/Demo_Nice_Buttons.py +++ b/DemoPrograms/Demo_Nice_Buttons.py @@ -15,7 +15,7 @@ button64 = 'iVBORw0KGgoAAAANSUhEUgAAAoAAAAFACAMAAAAbEz04AAAABGdBTUEAALGPC/xhBQAA def image_file_to_bytes(image64, size): image_file = io.BytesIO(base64.b64decode(image64)) img = Image.open(image_file) - img.thumbnail(size, Image.ANTIALIAS) + img.thumbnail(size, Image.LANCZOS) bio = io.BytesIO() img.save(bio, format='PNG') imgbytes = bio.getvalue() diff --git a/DemoPrograms/Demo_PIL_Use.py b/DemoPrograms/Demo_PIL_Use.py index ca7a37a4..0854e242 100644 --- a/DemoPrograms/Demo_PIL_Use.py +++ b/DemoPrograms/Demo_PIL_Use.py @@ -60,7 +60,7 @@ def convert_to_bytes(source, size=(None, None), subsample=None, zoom=None, fill= elif zoom is not None: scale = zoom - resized_image = image.resize((int(width * scale), int(height * scale)), Image.ANTIALIAS) if scale is not None else image + resized_image = image.resize((int(width * scale), int(height * scale)), Image.LANCZOS) if scale is not None else image if fill and scale is not None: resized_image = make_square(resized_image) # encode a PNG formatted version of image into BASE64 diff --git a/DemoPrograms/Demo_PNG_Thumbnail_Viewer.py b/DemoPrograms/Demo_PNG_Thumbnail_Viewer.py index 36e1d8c6..3056c3ad 100644 --- a/DemoPrograms/Demo_PNG_Thumbnail_Viewer.py +++ b/DemoPrograms/Demo_PNG_Thumbnail_Viewer.py @@ -59,7 +59,7 @@ def convert_to_bytes(file_or_bytes, resize=None): if resize: new_width, new_height = resize scale = min(new_height / cur_height, new_width / cur_width) - img = img.resize((int(cur_width * scale), int(cur_height * scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width * scale), int(cur_height * scale)), PIL. Image.LANCZOS) with io.BytesIO() as bio: img.save(bio, format="PNG") del img @@ -69,7 +69,7 @@ def convert_to_bytes(file_or_bytes, resize=None): # def image_file_to_bytes(filename, size): # try: # image = Image.open(filename) -# image.thumbnail(size, Image.ANTIALIAS) +# image.thumbnail(size, Image.LANCZOS) # bio = io.BytesIO() # a binary memory resident stream # image.save(bio, format='PNG') # save image as png to it # imgbytes = bio.getvalue() @@ -80,7 +80,7 @@ def convert_to_bytes(file_or_bytes, resize=None): def set_image_to_blank(key): img = PIL.Image.new('RGB', (100, 100), (255, 255, 255)) - img.thumbnail((1, 1), PIL.Image.ANTIALIAS) + img.thumbnail((1, 1), PIL. Image.LANCZOS) bio = io.BytesIO() img.save(bio, format='PNG') imgbytes = bio.getvalue() diff --git a/DemoPrograms/Demo_System_Tray_Reminder.py b/DemoPrograms/Demo_System_Tray_Reminder.py index b93d883e..94bba7cb 100644 --- a/DemoPrograms/Demo_System_Tray_Reminder.py +++ b/DemoPrograms/Demo_System_Tray_Reminder.py @@ -29,7 +29,7 @@ def resize_base64_image(image64, size): """ image_file = io.BytesIO(base64.b64decode(image64)) img = Image.open(image_file) - img.thumbnail(size, Image.ANTIALIAS) + img.thumbnail(size, Image.LANCZOS) bio = io.BytesIO() img.save(bio, format='PNG') imgbytes = bio.getvalue() diff --git a/docs/cookbook.md b/docs/cookbook.md index 3637ddd3..cc8789b6 100644 --- a/docs/cookbook.md +++ b/docs/cookbook.md @@ -2664,7 +2664,7 @@ def convert_to_bytes(file_or_bytes, resize=None): if resize: new_width, new_height = resize scale = min(new_height/cur_height, new_width/cur_width) - img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL. Image.LANCZOS) bio = io.BytesIO() img.save(bio, format="PNG") del img @@ -2747,7 +2747,7 @@ def convert_to_bytes(file_or_bytes, resize=None): if resize: new_width, new_height = resize scale = min(new_height/cur_height, new_width/cur_width) - img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL.Image.ANTIALIAS) + img = img.resize((int(cur_width*scale), int(cur_height*scale)), PIL. Image.LANCZOS) bio = io.BytesIO() img.save(bio, format="PNG") del img