Update ratio during resizing to avoid over-resizing

This commit is contained in:
Zeva Rose 2021-06-26 22:50:02 -06:00
parent 8442ed57d4
commit 7b64578689

View file

@ -56,7 +56,7 @@ class ImageCog(commands.Cog):
await ctx.send("Image already meets target.") await ctx.send("Image already meets target.")
return return
ratio = tgt_size / size ratio = tgt_size / size - 0.05
# TODO: Optimize to not run multiple times # TODO: Optimize to not run multiple times
while len(file) > tgt_size: while len(file) > tgt_size:
@ -69,6 +69,7 @@ class ImageCog(commands.Cog):
new_img = cv2.resize(img, (width, height)) new_img = cv2.resize(img, (width, height))
file = cv2.imencode(".png", new_img)[1].tobytes() file = cv2.imencode(".png", new_img)[1].tobytes()
ratio = tgt_size / len(file) - 0.05
bufio = BytesIO(file) bufio = BytesIO(file)
await ctx.send( await ctx.send(