Skip to content

Commit

Permalink
Pass only width to resize image and keep aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Dec 6, 2024
1 parent 27b4f77 commit 6726917
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions scraper/src/mindtouch2zim/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,16 @@ def _get_image_content(
logger.debug("Optimizing")
optimized = BytesIO()
with Image.open(unoptimized) as image:
if image.width * image.height <= CONTEXT.maximum_image_pixels:
if image.width * image.height <= context.maximum_image_pixels:
image.save(optimized, format="WEBP")
else:
resizeimage.resize_cover(
resizeimage.resize_width(
image,
[
int(
math.sqrt(
CONTEXT.maximum_image_pixels
* image.width
/ image.height
)
),
int(
math.sqrt(
CONTEXT.maximum_image_pixels
* image.height
/ image.width
)
),
],
int(
math.sqrt(
context.maximum_image_pixels * image.width / image.height
)
),
).save(optimized, format="WEBP")
del unoptimized

Expand Down

0 comments on commit 6726917

Please sign in to comment.