Skip to content

Instantly share code, notes, and snippets.

@hgwr
Created August 4, 2019 07:50
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 hgwr/478960389523a47d984573bea31944d9 to your computer and use it in GitHub Desktop.
Save hgwr/478960389523a47d984573bea31944d9 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
trap 'echo "Ctrl-C captured and exit."; exit 1' INT
trap 'echo "some error occured at $(pwd) and exit."; exit 8' SIGHUP
mkdir -p outdir || exit 1
find . -type f \( -iname '*.jpg' -or -iname '*.png' -or -iname '*.jpeg' -or -iname '*.gif' \) -print0 | \
while read -d $'\0' i; do
echo convert "$i" -geometry 1200x -compress jpeg -quality 85 "outdir/${i%.*}.jpg"
convert "$i" -geometry 1200x -compress jpeg -quality 85 "outdir/${i%.*}.jpg" || kill -hup $$
done
rm -f *.jpg *.png *.JPG *.PNG *.JPEG && \
mv outdir/* . && \
rm -rf outdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment