Last active
August 29, 2015 14:27
-
-
Save smagch/40f2313c84c16d3645ac to your computer and use it in GitHub Desktop.
Imagemagick multiple files
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
#!/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