@@ -65,7 +65,7 @@ process_images() {
6565 }
6666
6767 # Skip if not an image file
68- if [[ ! " $img " =~ \. (png| jpg| jpeg)$ ]]; then
68+ if [[ ! " $img " =~ \. (png| PNG | jpg| JPG | jpeg| JPEG )$ ]]; then
6969 if [[ " $img " == * .webp ]]; then
7070 echo " Skipping $img (already .webp)"
7171 continue
@@ -79,7 +79,7 @@ process_images() {
7979 width=$( identify -format " %w" " $img " 2> /dev/null || echo 0)
8080
8181 # Get file size in KB (macOS stat is different)
82- filesize=$( stat -f%z " $img " 2> /dev/null || echo 0)
82+ filesize=$( stat -c%s " $img " 2> /dev/null || echo 0)
8383 kbsize=$(( filesize / 1024 ))
8484
8585 # Define new filename
@@ -98,7 +98,7 @@ process_images() {
9898 echo " DRY RUN: Would update markdown references"
9999 else
100100 # Set quality dynamically based on file size
101- if [ " $kbsize " -ge 1500 ]; then # ≥ 150KB
101+ if [ " $kbsize " -ge 1500 ]; then # ≥ 1500KB
102102 quality=80
103103 elif [ " $kbsize " -ge 500 ]; then # 500–1500KB
104104 quality=75
@@ -107,7 +107,7 @@ process_images() {
107107 fi
108108 echo " Optimizing $img (${kbsize} KB, ${width} px), quality=$quality "
109109 # Resize and convert to WebP. If error occurs, capture it and exit.
110- error=$( magick " $img " -resize 1280x \> -quality $quality -define webp:lossless=true " $webp_img " 2>&1 )
110+ error=$( magick " $img " -resize ${target_width} x \> -quality $quality -define webp:lossless=true " $webp_img " 2>&1 )
111111 convert_status=$?
112112 if [ $convert_status -ne 0 ]; then
113113 echo " ⚠️ Error converting $img to WebP format."
0 commit comments