Upscaling (/upscale_image)
Enhances details removing common flaws in images and upscales to higher resolution. Need to provide desired size will keep aspect ratio, pass only desired either "width" or "height"
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as image_file:
# Read the image, encode it in base64, and convert to string
return base64.b64encode(image_file.read()).decode('utf-8')
def test_upscale():
url = f"https://gateway.ezml.io/api/v1/functions/upscale_image"
payload = {
"image": image_to_base64("<path to image>"),
"type": "width",
"value": 2046,
}
headers = {
"Authorization": "Bearer <token from /auth>"
}
res = requests.post(url, json=payload, headers=headers)
res = res.json()
with open("test.png", "wb") as f: # write the resulting image to file
f.write(base64.b64decode(res["result"]))
Last updated on October 23, 2023