Created
January 27, 2017 11:05
-
-
Save makadev/2a14196043527bc3cd5c1431fd80439b to your computer and use it in GitHub Desktop.
Bash batch resizing script using lanczos with imagemagicks convert
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 | |
#### setup | |
print_error() { | |
echo "$*" | |
echo "" | |
echo "Usage: $0 <Format> <Target Directory> <Files>" | |
echo "" | |
echo "Format: check out http://www.imagemagick.org/Usage/resize/#resize, f.e. 512x512" | |
echo "Target Directory: directory where resized images will be placed" | |
echo "Files: files to resize" | |
echo "" | |
echo "Example: $0 160x160 ./resized_160x160 *.jpg" | |
exit 1; | |
} | |
CONVERT=`which convert` | |
[[ ! -x "${CONVERT}" ]] && print_error "convert not found, make sure you have imagemagick or compatible installed" | |
SIZE_SPEC=$1 | |
TARGET_DIR=$2 | |
shift | |
shift | |
[[ -z "$*" ]] && print_error "no files given" | |
##### | |
[[ ! -d "${TARGET_DIR}" ]] && mkdir -p ${TARGET_DIR} | |
for f in $*; do | |
echo "Processing file ${f}.."; | |
${CONVERT} ${f} -filter Lanczos -resize ${SIZE_SPEC} -background 'rgba(0,0,0,0)' ${TARGET_DIR}/${f} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment