Error with resizing content of folder

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Stepo
Posts: 2
Joined: 2012-10-17T10:51:42-07:00
Authentication code: 67789

Error with resizing content of folder

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Error with resizing content of folder

Post 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
Stepo
Posts: 2
Joined: 2012-10-17T10:51:42-07:00
Authentication code: 67789

Re: Error with resizing content of folder

Post 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
Post Reply