Hi, I'm stupid

This commit is contained in:
AuroraWright
2024-01-24 17:14:12 +01:00
parent 4e7d714297
commit 2296ac0fee

View File

@@ -5,6 +5,7 @@ from pathlib import Path
import time import time
import sys import sys
import platform import platform
from math import sqrt
import jaconv import jaconv
import numpy as np import numpy as np
@@ -192,14 +193,11 @@ class GoogleLens:
def _preprocess(self, img): def _preprocess(self, img):
w,h = img.size w,h = img.size
ratio = w/h if w * h > 3000000:
while True: aspect_ratio = w/h
if h * w < 3000000: new_w = int(sqrt(3000000 * aspect_ratio))
if (w,h) != img.size: new_h = int(new_w / aspect_ratio)
img = img.resize((w, h), Image.LANCZOS) img = img.resize((new_w, new_h), Image.LANCZOS)
break
h -= 1
w = int(h * ratio)
image_bytes = io.BytesIO() image_bytes = io.BytesIO()
img.save(image_bytes, format='png') img.save(image_bytes, format='png')