From c8600773b3feb5a14a33454830591a82cd92bac7 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Tue, 23 Sep 2014 23:54:24 +0200 Subject: [PATCH] A script to resize images with convert. TODO: add a verification of the arguments --- resize_img | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 resize_img 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