Resize image to fit within Lens API limits

This commit is contained in:
AuroraWright
2024-01-24 14:26:59 +01:00
parent a8790e106f
commit 4e7d714297

View File

@@ -191,6 +191,16 @@ class GoogleLens:
return x
def _preprocess(self, img):
w,h = img.size
ratio = w/h
while True:
if h * w < 3000000:
if (w,h) != img.size:
img = img.resize((w, h), Image.LANCZOS)
break
h -= 1
w = int(h * ratio)
image_bytes = io.BytesIO()
img.save(image_bytes, format='png')
return image_bytes.getvalue()