Created
September 3, 2018 12:52
-
-
Save oelna/2af271c932904625f8908c06130e97c3 to your computer and use it in GitHub Desktop.
A bash script to batch resize images on macOS, possibly through an Automator Service (uses sips, ImageOptim)
This file contains 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
for f in "$@" | |
do | |
dir=$(dirname "${f}") | |
filename=$(basename -- "$f") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
# array of pixel sizes (widths) to generate | |
sizes=(600 1200) | |
for s in "${sizes[@]}" | |
do | |
newfilename="$dir"/"$filename"_"${s}"."$extension" | |
cp "$f" "$newfilename" # make a copy of the file first | |
sips -Z "${s}" -s formatOptions 60 "$newfilename" # resize the copy | |
/Applications/ImageOptim.app/Contents/MacOS/ImageOptim "$newfilename" # run imageoptim on the resized image | |
done | |
done | |
osascript -e 'display notification "Image resizing complete!"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment