MCPcopy Create free account
hub / github.com/X-PLUG/MobileAgent / resize_encode_image

Function resize_encode_image

PC-Agent/PCAgent/api.py:14–26  ·  view source on GitHub ↗
(image_path, screen_scale_ratio=0.5)

Source from the content-addressed store, hash-verified

12import json
13
14def 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

Callers 3

add_response_oldFunction · 0.90
add_responseFunction · 0.90
add_response_two_imageFunction · 0.90

Calls 3

decodeMethod · 0.80
openMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected