,,,,,,
Assuming that the directory /websites/www.abc.com/ROOT/uploads/inventory/100024/34510/110x85
already exists, what ImageMagick command would you use to resize /websites/www.abc.com/ROOT/uploads/inventory/100024/34510/400x300/34510-20140319-131033.jpeg
into /websites/www.abc.com/ROOT/uploads/inventory/100024/34510/110x85/34510-20140319-131033.jpeg
?
Are all of the jpeg and jpg files that you want to process located in directories matched by the pattern /websites/www.abc.com/ROOT/uploads/inventory/*/*/400x300
? If not, how do you find the files you want to convert?
,,,,,,,,
This should give you a template you can use to get the variables you want. I use the Korn shell, but this will work with any shell that recognizes the shell variable expansions required by the POSIX standards (including bash
and ksh
):
#!/bin/ksh
IMAGES_HOME="/websites/www.abc.com/ROOT/uploads/inventory/"
find "$IMAGES_HOME" -type f \
\( -name '*.[Jj][Pp][Gg]' -o -name '*.[Jj][Pp][Ee][Gg]' \) |
grep -F /400x300/ | while read -r f
do printf 'Processing: %s\n' "$f"
# If f=/prefix/x/y/400x300/z.jpg
file=${f##*/} # x.jpg
p3=${f%/*} # /prefix/x/y/400x300
d3=${p3##*/} # 400x300
p2=${p3%/*} # /prefix/x/y
d2=${p2##*/} # y
p1=${p2%/*} # /prefix/x
d1=${p1##*/} # x
printf 'file: %s\n' "$file"
printf 'd1: %s\n' "$d1"
printf 'd2: %s\n' "$d2"
printf 'd3: %s\n' "$d3"
printf 'p1: %s\n' "$p1"
printf 'p2: %s\n' "$p2"
printf 'p3: %s\n' "$p3"
pd="$p2/110x85" # /prefix/x/y/110x85
printf 'pd: %s\n' "$pd"
if [ ! -d "$pd" ]
then printf 'Creating directory: %s\n' "$pd"
mkdir "$pd"
fi
dest="$pd/$file" # /prefix/x/y/110x85/z.jpg
printf 'dest: %s\n' "$dest"
done
Thanks a lot Mr.Don Cragun. Your solution has helped me.
Regards
Praveen