Page 1 of 1

Pass all kind of image file in a single request

Posted: 2011-04-12T09:09:42-07:00
by kheraud
Hello,

I am having problem to figure it out... I think it is more a shell problem than a IM one.
I have a directory with PNG, png, JPEG, JPG, jpg, GIF, gif... images. And I want to thumbnail all theses images in png format.

Today I use :
mogrify -path thumbs2x -thumbnail 50x50 -background transparent -gravity center -extent 50x50 *.png

but it only takes png files... I tried *.[png|jpg|...] but it fails.

Do you have ideas ??

Thansk for your help

K.

Re: Pass all kind of image file in a single request

Posted: 2011-04-12T09:41:58-07:00
by Bonzo
Lateral thinking is probably required!

I use php and would read the whole directory using glob and the image names would then be in an array. I would then loop through the array feeding the image name to the comand via a variable.

Re: Pass all kind of image file in a single request

Posted: 2011-04-12T09:57:55-07:00
by markmarques
I suppose the idea is to "create" new thumbnails for each image ...

so an aproach would be:

convert * -thumbnail 50x50 -background transparent -gravity center -extent 50x50 *_thumb.png

If and only if all the files present in the dir are images ( or at least if convert can read them as images) ...

Greetings

Re: Pass all kind of image file in a single request

Posted: 2011-04-12T10:06:39-07:00
by fmw42
One way is (don't forget to tell mogrify the desired output format using -format png). Note you cannot change the output name. I think you are mistaking the input and output parts of mogrify. Read this in more detail http://www.imagemagick.org/Usage/basics/#mogrify

mogrify -path thumbs2x -format png -thumbnail 50x50 -background transparent -gravity center -extent 50x50 *

another is to write a script that just changes the input format

mogrify -path thumbs2x -format png -thumbnail 50x50 -background transparent -gravity center -extent 50x50 *.png
mogrify -path thumbs2x -format png -thumbnail 50x50 -background transparent -gravity center -extent 50x50 *.jpg
etc for each input format


Just on a whim, I tried this simple test and it worked:

mogrify -path /Users/fred/test2 -format png *.png *.gif *.jpg *.GIF



Again on a whim, I tried to change the output name as follows, but it has limitations of adding a period:

mogrify -path /Users/fred/test2 -format thumb.png *.png *.gif *.jpg *.GIF

results in names like
tree.jpg ---> tree.thumb.png

Re: Pass all kind of image file in a single request

Posted: 2011-04-12T10:17:45-07:00
by kheraud
Solved !
I don't do it with the correct approach (learn, fail, learn, fail, ask, learn, succeed). But I am in a hurry for this part of my project.
Thanks a lot for your help !

The result is :
$format_img_double = 50x50
mogrify -path thumbs2x -thumbnail $format_img_double -format png -background transparent -gravity center -extent $format_img_double toCompute/*.*

The *.* permit to avoid errors on directories
The toCompute/ only contains img
I purge thumbs2x with rm+mkdir at start of script
I use mogrify because I want to keep the same filenames !

Thanks

Re: Pass all kind of image file in a single request

Posted: 2011-04-12T23:41:33-07:00
by anthony
kheraud wrote:but it only takes png files... I tried *.[png|jpg|...] but it fails.
that is a shell problem. If you are using BASH shell you can specify files in many ways.
One method is {xxx,yyy,zzz}

so try... *.{png,jpg,gif}

NOTE this will expand without sorting to *.png *.jpg *.gif so it will do all PNG images first.

an alturnative is to generate a list of filename...

ls *.{png,jpg,gif} | mogrify ..... @-

Ls will sort all the files alphabetically itself. The @- reads a list of filenames from '-' or standard input. See the last part of the section...
http://www.imagemagick.org/Usage/files/#read

if you are trying to avoid directories...
find * -prune -type f | ....

See http://www.imagemagick.org/Usage/basics/#mogrify-not

You will also probably be interested in the section before that
which uses a technique of using convert instead of mogrify
http://www.imagemagick.org/Usage/basics ... fy_convert
Its very useful is combined with the "xargs" or "parellel" comamnds.