diff --git a/jarvis/cogs/image.py b/jarvis/cogs/image.py index 54cdad2..ec4a459 100644 --- a/jarvis/cogs/image.py +++ b/jarvis/cogs/image.py @@ -67,8 +67,10 @@ class ImageCog(commands.Cog): ratio = tgt_size / size - 0.02 + accuracy = 0.0 # TODO: Optimize to not run multiple times while len(file) > tgt_size: + old_file = file buffer = np.frombuffer(file, dtype=np.uint8) img = cv2.imdecode(buffer, flags=-1) @@ -78,7 +80,12 @@ class ImageCog(commands.Cog): new_img = cv2.resize(img, (width, height)) file = cv2.imencode(".png", new_img)[1].tobytes() - ratio = tgt_size / len(file) - 0.02 + accuracy = (len(file) / tgt_size) * 100 + if accuracy <= 0.50: + file = old_file + ratio = ratio + 0.1 + else: + ratio = tgt_size / len(file) - 0.02 bufio = BytesIO(file) accuracy = (len(file) / tgt_size) * 100