Skip to content

Instantly share code, notes, and snippets.

@oelna
Created September 3, 2018 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oelna/2af271c932904625f8908c06130e97c3 to your computer and use it in GitHub Desktop.
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)
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