scripts/resize_img

26 lines
821 B
Bash
Executable File

#!/bin/sh
# Description: Resize images with avec lower width
#
# $1: a directory with images to convert or a image file path
# $2: the new width size (the height will be proportional)
TO_RESIZE="${1}"
NEW_SIZE="${2}"
## If the first parameter is a directory
if [ -d ${TO_RESIZE} ]; then
printf 'Convert all images in %s to %spx width\n' "${TO_RESIZE}" "${NEW_SIZE}"
## For all images files with the old format in the album directory
find "${TO_RESIZE}" -iname "*.png" -o -iname "*.jpg" -exec convert -resize "${NEW_SIZE}" {} {} \;
else
if [ -f ${TO_RESIZE} ]; then
printf 'Convert %s to %spx width\n' "${TO_RESIZE}" "${NEW_SIZE}"
# Run a find command to ensure it's a png or jpg file
find "${TO_RESIZE}" -iname "*.png" -o -iname "*.jpg" -exec convert -resize "${NEW_SIZE}" {} {} \;
fi
fi