Last active
December 13, 2015 16:39
-
-
Save joshuaconner/4941992 to your computer and use it in GitHub Desktop.
Copy this into your .bash_profile! Bash function to batch-resize images according to the geometry specified in resize-arg. If no destination directory is specified, the converted images' filenames have "-resized" appended so as to not overwrite the original images.
This file contains hidden or 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
resize () { | |
SUFFIX="-resized" | |
if [ -n "$1" ] ; then | |
if [ ! -f "${@: -1}" ] ; then | |
SUFFIX="" | |
DEST="${@: -1}" | |
mkdir -p "$DEST" | |
fi | |
geom="$1" | |
shift | |
while [ -n "$1" ] | |
do | |
if [ -f "$1" ]; then | |
FILENAME=$(basename "$1") | |
EXTENSION="${FILENAME##*.}" | |
FILENAME="${FILENAME%.*}" | |
convert -filter Lanczos2 -resize "$geom" "$1" "${DEST}/${FILENAME}${SUFFIX}.${EXTENSION}" | |
fi | |
shift | |
done | |
else | |
echo "Usage: resize resize-arg [file1, file2, ...] destinationDirectory" | |
echo "For possible resize-arg formats, see:" | |
echo "http://www.imagemagick.org/script/command-line-processing.php#geometry" | |
echo "" | |
echo 'If a destination directory is no specified, each filename will be appended with' | |
echo '"-resized" so as to not overwrite the original files.' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit where credit is due: http://superuser.com/questions/282688/batch-resizing-images-in-os-x-to-a-certain-height/282909#282909