log resize dimensions

This commit is contained in:
bakatrouble 2023-08-13 22:28:55 +03:00
parent 6a5d68351c
commit e83c970717

View File

@ -86,11 +86,13 @@ async def send_post(post: E621Post, tag_list: List[str]):
if post.file.size > 10000000: if post.file.size > 10000000:
logging.warning('compressing') logging.warning('compressing')
dl_im = Image.open(file).convert('RGBA') dl_im = Image.open(file).convert('RGBA')
if dl_im.size[0] > 2000 or dl_im.size[1] > 2000: size = dl_im.size
larger_dimension = max(dl_im.size) if size[0] > 2000 or size[1] > 2000:
larger_dimension = max(size)
ratio = 2000 / larger_dimension ratio = 2000 / larger_dimension
dl_im = dl_im.resize((int(dl_im.size[0] * ratio), int(dl_im.size[1] * ratio)), dl_im = dl_im.resize((int(size[0] * ratio), int(size[1] * ratio)),
Image.LANCZOS) Image.LANCZOS)
print(f'Resizing from {size[0]}x{size[1]} to {dl_im.size[0]}x{dl_im.size[1]}')
im = Image.new('RGBA', dl_im.size, (255, 255, 255)) im = Image.new('RGBA', dl_im.size, (255, 255, 255))
composite = Image.alpha_composite(im, dl_im).convert('RGB') composite = Image.alpha_composite(im, dl_im).convert('RGB')
file = BytesIO() file = BytesIO()