diff --git a/resize_img b/resize_img new file mode 100755 index 0000000..9bcfc8c --- /dev/null +++ b/resize_img @@ -0,0 +1,25 @@ +#!/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