MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / resize_base64_image

Function resize_base64_image

DemoPrograms/Demo_System_Tray_Reminder.py:23–40  ·  view source on GitHub ↗

Resize a base64 image. Good to use for Image elements, Button Images, etc. :param image64: The Base64 image :type image64: bytes :param size: Size to make the image in pixels (width, height) :type size: Tuple[int, int] :return: A new Base64 image :rtype: bytes

(image64, size)

Source from the content-addressed store, hash-verified

21POPUP_TEXT_COLOR, POPUP_BACKGROUND_COLOR = 'white', 'red'
22
23def resize_base64_image(image64, size):
24 """
25 Resize a base64 image. Good to use for Image elements, Button Images, etc.
26
27 :param image64: The Base64 image
28 :type image64: bytes
29 :param size: Size to make the image in pixels (width, height)
30 :type size: Tuple[int, int]
31 :return: A new Base64 image
32 :rtype: bytes
33 """
34 image_file = io.BytesIO(base64.b64decode(image64))
35 img = Image.open(image_file)
36 img.thumbnail(size, Image.LANCZOS)
37 bio = io.BytesIO()
38 img.save(bio, format='PNG')
39 imgbytes = bio.getvalue()
40 return imgbytes
41
42
43def main():

Callers 1

mainFunction · 0.70

Calls 1

saveMethod · 0.80

Tested by

no test coverage detected