(image_path, screen_scale_ratio=0.5)
| 12 | import json |
| 13 | |
| 14 | def resize_encode_image(image_path, screen_scale_ratio=0.5): |
| 15 | with Image.open(image_path) as img: |
| 16 | new_width = int(img.width * screen_scale_ratio) |
| 17 | new_height = int(img.height * screen_scale_ratio) |
| 18 | resized_img = img.resize((new_width, new_height), Image.LANCZOS) |
| 19 | |
| 20 | buffered = io.BytesIO() |
| 21 | resized_img.save(buffered, format="PNG") |
| 22 | |
| 23 | img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8') |
| 24 | return img_base64 |
| 25 | # with open(image_path, "rb") as image_file: |
| 26 | # return base64.b64encode(image_file.read()).decode('utf-8') |
| 27 | |
| 28 | |
| 29 |
no test coverage detected