diff --git a/jarvis/cogs/image.py b/jarvis/cogs/image.py index 7328921..d711b5b 100644 --- a/jarvis/cogs/image.py +++ b/jarvis/cogs/image.py @@ -58,15 +58,19 @@ class ImageCog(commands.Cog): ratio = tgt_size / size - buffer = np.frombuffer(file, dtype=np.uint8) - img = cv2.imdecode(buffer, flags=-1) + # TODO: Optimize to not run multiple times + while len(file) > tgt_size: - width = int(img.shape[1] * ratio) - height = int(img.shape[0] * ratio) + buffer = np.frombuffer(file, dtype=np.uint8) + img = cv2.imdecode(buffer, flags=-1) - new_img = cv2.resize(img, (width, height)) - buffer = cv2.imencode(".png", new_img)[1].tobytes() - bufio = BytesIO(buffer) + width = int(img.shape[1] * ratio) + height = int(img.shape[0] * ratio) + + new_img = cv2.resize(img, (width, height)) + file = cv2.imencode(".png", new_img)[1].tobytes() + + bufio = BytesIO(file) await ctx.send(file=File(bufio, filename="resized.png"))