Created
March 11, 2016 11:50
-
-
Save TaurusOlson/e2477ac2f1d4ead77758 to your computer and use it in GitHub Desktop.
Create one or many new resized image 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 | |
function usage() { | |
cat<<EOF | |
$(basename $0) - Create one or many new resized image files | |
Usage: | |
$(basename $0) <size> <imgfile1> [imgfile2 imgfile3 ...] | |
EOF | |
} | |
function get_filename() { | |
filename=$(basename "$1") | |
echo "${filename%.*}" | |
} | |
function get_extension() { | |
filename=$(basename "$1") | |
echo "${filename##*.}" | |
} | |
function resize_image() { | |
local size=$1 | |
local imgfile=$2 | |
filename=$(get_filename $imgfile) | |
extension=$(get_extension $imgfile) | |
imgfile_resized=$(dirname $imgfile)/${filename}"_${size}."${extension} | |
convert ${imgfile} -resize ${size} ${imgfile_resized} &&\ | |
echo "$imgfile -> $imgfile_resized" | |
} | |
[ $# -lt 2 ] && usage && exit 1 | |
[ -e $1 ] && echo "$1 must be a valid size. Example (1280, 1280x720 or x720)" && exit 1 | |
size=$1 | |
shift | |
for arg in "$@" | |
do | |
! [ -e $arg ] && echo "$arg must be an existing image file" && exit 1 | |
resize_image ${size} $arg | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires ImageMagick.