Last active
September 6, 2017 04:25
-
-
Save ravinggenius/180ac910c805bec0cdae0a071a3baf9e to your computer and use it in GitHub Desktop.
Batch resize images with ImageMagick
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
# place this script in whatever directory you have your albums in | |
# each album is expected to have an `original` sub-directory where the full-size images actually are | |
# resized images will be placed in a sibling directory next to `original` | |
# USAGE | |
# $ ./resize.sh "2017-09-04 Some Album Name" 1600 | |
# rename arguments | |
ALBUM=$1 # the name of the directory containing the album (may contain spaces, which is why everything is quoted below) | |
SIZE=$2 # used to size a bounding box into which images will be resized (aspect ratio will be preserved) | |
# set globbing to return empty list for empty directories instead of the literal glob pattern | |
shopt -s nullglob | |
# create destination directory | |
mkdir -p "$ALBUM/$SIZE" | |
# loop over original images, which are expected to be in a sub-directory called `original` | |
for SOURCE in "$ALBUM/original/"*".JPG" | |
do | |
BASE=`basename "$SOURCE" | sed -e 's/.JPG//'` | |
DESTINATION="$ALBUM/$SIZE/${BASE}_$SIZE.JPG" | |
# progress report | |
echo $DESTINATION | |
# actually do the resize | |
magick convert "$SOURCE" -resize $SIZEx$SIZE "$DESTINATION" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment