Page 1 of 1

Error with resizing content of folder

Posted: 2012-10-17T11:00:53-07:00
by Stepo
Hello,
I have a bash script operating with ImageMagick and I can't get resized image.

Code: Select all

#!/bin/bash
FILES=/srv/www/vhosts/detsky-pokoj.biz/httpdocs/components/com_virtuemart/shop_image/product/*
for f in $FILES
do
	if [[ $f == *.jpg ]]; then
		convert -resize 175x175 $f
	fi
done;
When I execute script.sh, an error message for each file suddenly appears!
http://stepolabs.com/lab/img/error-execute.png
But my files are here!
http://stepolabs.com/lab/img/files.png
Please do you know where is problem?

Thank you very much,
Stepo

Re: Error with resizing content of folder

Posted: 2012-10-17T14:58:15-07:00
by fmw42
FILES=/srv/www/vhosts/detsky-pokoj.biz/httpdocs/components/com_virtuemart/shop_image/product/*
I am not a unix expert, but I am not sure this actually gets a list of your files. I think you need to add ls

FILES=`ls /srv/www/vhosts/detsky-pokoj.biz/httpdocs/components/com_virtuemart/shop_image/product/`

I defer to any unix expert on this

if [[ $f == *.jpg ]]; then
convert -resize 175x175 $f
fi

This also seems odd to me. I do not understand your if test. I am not sure you can do such a wildcard test and if you could, you probably would need to put "" around the $f and the *.jpg as they are strings and not integers. Also I don't know about double brackets for tests.

But more importantly your convert command is wrong. YOu have specified no input images

convert input -resize ... output

is the correct format, even if you want to override the input with the output by using the same name.

However, there is an easier way to do this by using mogrify, which processes all images in a folder. See
http://www.imagemagick.org/Usage/basics/#mogrify. I would suggest you use the -path option to specify a new folder to put the output images.

create a new folder, then
cd path2imagefolder
mogify -path path2newimagefolder -format jpg -resize 175x175 *.jpg

Re: Error with resizing content of folder

Posted: 2012-10-18T10:33:11-07:00
by Stepo
Hi man!
I wish I could invite you for a beer! Oh gosh, you live in Valley, I want visit Valley at least once in my life ;) But before my trip to Valley, I must do what Lenin said: "Study, study, study!" :lol:
It works very well, thanks! :)
Stepo