Skip to content

Commit 7db21ed

Browse files
committed
Scale quality depending on image size
1 parent 96357b8 commit 7db21ed

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/resize_images.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,17 @@ process_images() {
9797
echo "DRY RUN: Would remove $img"
9898
echo "DRY RUN: Would update markdown references"
9999
else
100-
echo "Optimizing $img (${kbsize}KB, ${width}px)"
101-
100+
# Set quality dynamically based on file size
101+
if [ "$kbsize" -ge 15000 ]; then # ≥ 15MB
102+
quality=30
103+
elif [ "$kbsize" -ge 5000 ]; then # 5–15MB
104+
quality=50
105+
else # < 5MB
106+
quality=75
107+
fi
108+
echo "Optimizing $img (${kbsize}KB, ${width}px), quality=$quality"
102109
# Resize and convert to WebP. If error occurs, capture it and exit.
103-
error=$(magick "$img" -resize 1280x\> -quality 85 "$webp_img" 2>&1)
110+
error=$(magick "$img" -resize 1280x\> -quality $quality "$webp_img" 2>&1)
104111
convert_status=$?
105112
if [ $convert_status -ne 0 ]; then
106113
echo "⚠️ Error converting $img to WebP format."

0 commit comments

Comments
 (0)