Merge pull request #6539 from PySimpleGUI/Dev-latest
Replaced PIL's deprecated constant ANTIALIAS with LANCZOS
This commit is contained in:
commit
03ed1948e2
|
@ -26,7 +26,7 @@ def resize_base64_image(image64, size):
|
||||||
'''
|
'''
|
||||||
image_file = io.BytesIO(base64.b64decode(image64))
|
image_file = io.BytesIO(base64.b64decode(image64))
|
||||||
img = Image.open(image_file)
|
img = Image.open(image_file)
|
||||||
img.thumbnail(size, Image.ANTIALIAS)
|
img.thumbnail(size, Image.LANCZOS)
|
||||||
bio = io.BytesIO()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format='PNG')
|
img.save(bio, format='PNG')
|
||||||
imgbytes = bio.getvalue()
|
imgbytes = bio.getvalue()
|
||||||
|
|
|
@ -81,7 +81,7 @@ def convert_to_bytes(source, size=(None, None), subsample=None, zoom=None, fill=
|
||||||
elif zoom is not None:
|
elif zoom is not None:
|
||||||
scale = zoom
|
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:
|
if fill and scale is not None:
|
||||||
resized_image = make_square(resized_image)
|
resized_image = make_square(resized_image)
|
||||||
# encode a PNG formatted version of image into BASE64
|
# encode a PNG formatted version of image into BASE64
|
||||||
|
|
|
@ -92,7 +92,7 @@ def convert_to_bytes(file_or_bytes, resize=None, fill=False):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height / cur_height, new_width / cur_width)
|
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 fill:
|
||||||
if resize is not None:
|
if resize is not None:
|
||||||
img = make_square(img, resize[0])
|
img = make_square(img, resize[0])
|
||||||
|
|
|
@ -44,7 +44,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height/cur_height, new_width/cur_width)
|
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()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format="PNG")
|
img.save(bio, format="PNG")
|
||||||
del img
|
del img
|
||||||
|
|
|
@ -45,7 +45,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height/cur_height, new_width/cur_width)
|
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:
|
with io.BytesIO() as bio:
|
||||||
img.save(bio, format="PNG")
|
img.save(bio, format="PNG")
|
||||||
del img
|
del img
|
||||||
|
|
|
@ -55,7 +55,7 @@ def resize(input_file, size, output_file=None, encode_format='PNG'):
|
||||||
new_width, new_height = size
|
new_width, new_height = size
|
||||||
if new_width != width or new_height != height: # if the requested size is different than original 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)
|
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:
|
else:
|
||||||
resized_image = image
|
resized_image = image
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ def convert_to_bytes(file_or_bytes, resize=None, fill=False):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height / cur_height, new_width / cur_width)
|
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 fill:
|
||||||
img = make_square(img, THUMBNAIL_SIZE[0])
|
img = make_square(img, THUMBNAIL_SIZE[0])
|
||||||
with io.BytesIO() as bio:
|
with io.BytesIO() as bio:
|
||||||
|
|
|
@ -890,7 +890,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height/cur_height, new_width/cur_width)
|
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:
|
with io.BytesIO() as bio:
|
||||||
img.save(bio, format="PNG")
|
img.save(bio, format="PNG")
|
||||||
del img
|
del img
|
||||||
|
|
|
@ -15,7 +15,7 @@ button64 = 'iVBORw0KGgoAAAANSUhEUgAAAoAAAAFACAMAAAAbEz04AAAABGdBTUEAALGPC/xhBQAA
|
||||||
def image_file_to_bytes(image64, size):
|
def image_file_to_bytes(image64, size):
|
||||||
image_file = io.BytesIO(base64.b64decode(image64))
|
image_file = io.BytesIO(base64.b64decode(image64))
|
||||||
img = Image.open(image_file)
|
img = Image.open(image_file)
|
||||||
img.thumbnail(size, Image.ANTIALIAS)
|
img.thumbnail(size, Image.LANCZOS)
|
||||||
bio = io.BytesIO()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format='PNG')
|
img.save(bio, format='PNG')
|
||||||
imgbytes = bio.getvalue()
|
imgbytes = bio.getvalue()
|
||||||
|
|
|
@ -60,7 +60,7 @@ def convert_to_bytes(source, size=(None, None), subsample=None, zoom=None, fill=
|
||||||
elif zoom is not None:
|
elif zoom is not None:
|
||||||
scale = zoom
|
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:
|
if fill and scale is not None:
|
||||||
resized_image = make_square(resized_image)
|
resized_image = make_square(resized_image)
|
||||||
# encode a PNG formatted version of image into BASE64
|
# encode a PNG formatted version of image into BASE64
|
||||||
|
|
|
@ -59,7 +59,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height / cur_height, new_width / cur_width)
|
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:
|
with io.BytesIO() as bio:
|
||||||
img.save(bio, format="PNG")
|
img.save(bio, format="PNG")
|
||||||
del img
|
del img
|
||||||
|
@ -69,7 +69,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
# def image_file_to_bytes(filename, size):
|
# def image_file_to_bytes(filename, size):
|
||||||
# try:
|
# try:
|
||||||
# image = Image.open(filename)
|
# image = Image.open(filename)
|
||||||
# image.thumbnail(size, Image.ANTIALIAS)
|
# image.thumbnail(size, Image.LANCZOS)
|
||||||
# bio = io.BytesIO() # a binary memory resident stream
|
# bio = io.BytesIO() # a binary memory resident stream
|
||||||
# image.save(bio, format='PNG') # save image as png to it
|
# image.save(bio, format='PNG') # save image as png to it
|
||||||
# imgbytes = bio.getvalue()
|
# imgbytes = bio.getvalue()
|
||||||
|
@ -80,7 +80,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
|
|
||||||
def set_image_to_blank(key):
|
def set_image_to_blank(key):
|
||||||
img = PIL.Image.new('RGB', (100, 100), (255, 255, 255))
|
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()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format='PNG')
|
img.save(bio, format='PNG')
|
||||||
imgbytes = bio.getvalue()
|
imgbytes = bio.getvalue()
|
||||||
|
|
|
@ -29,7 +29,7 @@ def resize_base64_image(image64, size):
|
||||||
"""
|
"""
|
||||||
image_file = io.BytesIO(base64.b64decode(image64))
|
image_file = io.BytesIO(base64.b64decode(image64))
|
||||||
img = Image.open(image_file)
|
img = Image.open(image_file)
|
||||||
img.thumbnail(size, Image.ANTIALIAS)
|
img.thumbnail(size, Image.LANCZOS)
|
||||||
bio = io.BytesIO()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format='PNG')
|
img.save(bio, format='PNG')
|
||||||
imgbytes = bio.getvalue()
|
imgbytes = bio.getvalue()
|
||||||
|
|
|
@ -2664,7 +2664,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height/cur_height, new_width/cur_width)
|
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()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format="PNG")
|
img.save(bio, format="PNG")
|
||||||
del img
|
del img
|
||||||
|
@ -2747,7 +2747,7 @@ def convert_to_bytes(file_or_bytes, resize=None):
|
||||||
if resize:
|
if resize:
|
||||||
new_width, new_height = resize
|
new_width, new_height = resize
|
||||||
scale = min(new_height/cur_height, new_width/cur_width)
|
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()
|
bio = io.BytesIO()
|
||||||
img.save(bio, format="PNG")
|
img.save(bio, format="PNG")
|
||||||
del img
|
del img
|
||||||
|
|
Loading…
Reference in New Issue