Created
June 19, 2020 14:19
-
-
Save tomayac/556d99891f0638909a7ac7718a93224e to your computer and use it in GitHub Desktop.
Resize script for web.dev images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
maxwidth="1600" # in pixels, the widest image you want to allow. | |
#find all .png in current dir and subdirectories | |
FILES="$(find . -iname '*.png')" | |
for imagefile in $FILES | |
do | |
if [ -f "$imagefile" ]; then | |
imgwidth=`sips --getProperty pixelWidth "$imagefile" | awk '/pixelWidth/ {print $2}'` | |
else | |
echo "Oops, "$imagefile" does not exist." | |
exit | |
fi | |
if [ $imgwidth -gt $maxwidth ]; then | |
echo " - Image too big. Resizing..." | |
sips --resampleWidth $maxwidth "$imagefile" > /dev/null 2>&1 # to hide sips' ugly output | |
imgwidth=`sips --getProperty pixelWidth "$imagefile" | awk '/pixelWidth/ {print $2}'` | |
imgheight=`sips --getProperty pixelHeight "$imagefile" | awk '/pixelHeight/ {print $2}'` | |
echo " - Resized "$imagefile" to $imgwidth""px wide by $imgheight""px tall"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment