Skip to content

Instantly share code, notes, and snippets.

@smagch
Last active August 29, 2015 14:27
Show Gist options
  • Save smagch/40f2313c84c16d3645ac to your computer and use it in GitHub Desktop.
Save smagch/40f2313c84c16d3645ac to your computer and use it in GitHub Desktop.
Imagemagick multiple files
#!/bin/bash
SIZES=(320 640 960 1280 1920 2560)
target=$1
extension="${target##*.}"
filename="${target%.*}"
echo "ext is $extension"
if [ ! -f $target ]; then
echo "File $target not found"
exit 1
fi
convert "${target}" -set filename:mysize '%wx%h' "${filename}_%[filename:mysize].${extension}"
width=$(identify -format "%[fx:w]" $target)
for w in ${SIZES[@]}; do
echo "$target is $width. then $w"
if [ "$w" -gt "$width" ]; then
echo "end"
exit
fi
convert "${target}" -resize "${w}x" -set filename:mysize '%wx%h' "${filename}_%[filename:mysize].${extension}"
done
echo "resized all"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment