@@ -132,21 +132,24 @@ for image in "${IMAGES[@]}"; do
132
132
# figure out what type the image is: jpeg, png, gif, and reduce size if necessary/possible.
133
133
mimetype_local=" $( file --mime-type -b " $image " ) "
134
134
imgsize_org=" $( stat -c%s " $image " ) "
135
+ modtime_org=" $( stat -c " %y" " $image " ) "
136
+
135
137
if (( imgsize_org >= 950000 )) ; then
136
- if [[ " $mimetype_local " == " image/jpeg" ]]; then
137
- jpegoptim -q -S950 -s " $image " # if it's JPG and > 1 MB, we can optimize for it
138
- # try again if still too big
139
- if (( $(stat - c% s "$image ") >= 950000 )) ; then
140
- jpegoptim -q -S850 -s " $image "
141
- fi
142
- elif [[ " $mimetype_local " == " image/png" ]]; then
143
- pngquant -f -o " ${image} .tmp" 64 " $image " # if it's PNG and > 1 MB, we can optimize for it
144
- mv -f " ${image} .tmp" " $image "
145
- else
146
- " ${s6wrap[@]} " echo " Omitting image $image as it is too big ($imgsize )"
147
- continue # skip if it's not JPG or PNG
148
- fi
149
- " ${s6wrap[@]} " echo " Image size of $image reduced from $imgsize_org to $( stat -c%s " $image " ) "
138
+ if [[ " $mimetype_local " == " image/jpeg" ]]; then
139
+ jpegoptim -q -S950 -s " $image " # if it's JPG and > 1 MB, we can optimize for it
140
+ # try again if still too big
141
+ if (( $(stat - c% s "$image ") >= 950000 )) ; then
142
+ jpegoptim -q -S850 -s " $image "
143
+ fi
144
+ elif [[ " $mimetype_local " == " image/png" ]]; then
145
+ pngquant -f -o " ${image} .tmp" 64 " $image " # if it's PNG and > 1 MB, we can optimize for it
146
+ mv -f " ${image} .tmp" " $image "
147
+ else
148
+ " ${s6wrap[@]} " echo " Omitting image $image as it is too big ($imgsize )"
149
+ continue # skip if it's not JPG or PNG
150
+ fi
151
+ touch -d " $modtime_org " " $image " # restore original modification date of the image (for cache management purposes)
152
+ " ${s6wrap[@]} " echo " Image size of $image reduced from $imgsize_org to $( stat -c%s " $image " ) "
150
153
fi
151
154
if (( $(stat - c% s "$image ") >= 950000 )) ; then
152
155
" ${s6wrap[@]} " echo " Omitting image $image as the size reduction was insufficient: before: $imgsize_org ; now: $( stat -c%s " $image " ) "
0 commit comments