Page 1 of 1

Convert 10 Images with 3 clones for each

Posted: 2013-07-22T07:01:16-07:00
by class3f
Hello,

This is my first contact with imagemagick. I have folder with 10 diffrent images. In one query I am trying to create four thumbnail sizes:

1024x768 - normall
360x270 - cut to fit
104x78 - cut to fit
68x51 - cut to fit

created by me questions almost works:

Code: Select all

convert path/folder/*.* 
( +clone -strip -thumbnail "68x51^>" -background white -gravity center -extent 68x51 -quality 80 +adjoin -scene 1 -write path/folder/%d_68x51.jpg +delete ) 
( +clone -strip -thumbnail "104x78^>" -background white -gravity center -extent 104x78 -quality 80 +adjoin -scene 1 -write path/folder/%d_104x78.jpg +delete ) 
( +clone -strip -thumbnail "360x270^>" -background white -gravity center -extent 360x270 -quality 80 +adjoin -scene 1 -write path/folder/%d_360x270.jpg +delete ) 
-strip -thumbnail "1024x768>" -quality 80 +adjoin -scene 1 path/folder/%d_1024x768.jpg
All thumbnails are created with dimensions 1024x768. Unfortunately, the clones are created only for the last image. It seems to me that the clones are overwritten and therefore remains only the last. Unfortunately, I can not help myself with the names. I'm trying to get the names of the files:

1_1024x768, 1_360x270, 1_104x78, 1_68x51
2_1024x768, 2_360x270, 2_104x78, 2_68x51
3_1024x768, 3_360x270, 3_104x78, 3_68x51
...

Thanks for any help.

Re: Convert 10 Images with 3 clones for each

Posted: 2013-07-22T07:22:36-07:00
by GreenKoopa
+clone makes a copy of the last image
-clone 0 makes a copy of the first image
-clone -1 makes a copy of the last image
-clone 0--1 makes a copy of the first through last images
http://www.imagemagick.org/Usage/basics/#clone

convert path/folder/*.* reads all images into memory at once. If you have a large number of large images, consider writing a script that calls convert for each image.

Settings such as -background, -gravity, and -quality remain set until changed. They are, by default, unaffected by parentheses. The need not be repeated, but may be if you like.

Filename escapes
http://www.imagemagick.org/Usage/files/#save_escapes

Re: Convert 10 Images with 3 clones for each

Posted: 2013-07-22T09:11:51-07:00
by class3f
By creating a query I have in mind only the speed of execution. I have about 50 folders, each from 0 to 20 files. Each file must have four thumbnails. I thought that I will perform one query for a single folder. In total, these questions will be about 50. Each of them doing with exec in php.

Is this the best solution? Do you recommend something else? faster? more optimal for this task?

Re: Convert 10 Images with 3 clones for each

Posted: 2013-07-22T09:43:21-07:00
by GreenKoopa
I have no idea which way is best. It's just an alternative for you to consider, which I offered because it may also simplify your clone and filename needs. Personally I would make one call to convert per image, and use php to create the loop. Many people have success loading all of the images at once, which is why IM supports it. I'm not in a position to guess how large your images are or how much memory you have. I don't know if there might be more images per folder in the future. Note that 16-bit IM uses 8 bytes per pixel, and that -clone sometimes causes a copy to be created.

Re: Convert 10 Images with 3 clones for each

Posted: 2013-07-22T10:43:26-07:00
by fmw42
I would loop over each image in the directory and process that for the 3 outputs. If you load too many images with convert, you will run out of memory and things can get slow thrashing to disk.

Re: Convert 10 Images with 3 clones for each

Posted: 2013-07-22T11:49:41-07:00
by class3f
The number of folders will be changed depending on the time of the query. The folder will never be more than 20 images and no larger than 5MB. On the server I have 16GB of memory and I do not know whether a lot or a little for ImageMagick. Tests carried out later and see what is better or 100 requests for folders or 1,000 requests for files.

I converted the code from the earlier instructions and was able to create all the necessary files:

Code: Select all

convert path/folder/*.* 
( -clone 0--1 -strip -thumbnail "68x51^>" -background white -gravity center -extent 68x51 -quality 80 +adjoin -scene 1 -write path/folder/%d_68x51.jpg +delete ) 
( -clone 0--1 -strip -thumbnail "104x78^>" -background white -gravity center -extent 104x78 -quality 80 +adjoin -scene 1 -write path/folder/%d_104x78.jpg +delete ) 
( -clone 0--1 -strip -thumbnail "360x270^>" -background white -gravity center -extent 360x270 -quality 80 +adjoin -scene 1 -write path/folder/%d_360x270.jpg +delete ) 
-strip -thumbnail "1024x768>" -quality 80 +adjoin -scene 1 path/folder/%d_1024x768.jpg
Unfortunately, I now have in each folder 99 files too much :) Query creating the correct files also creates thumbnails of various names and sizes mixed. Do you have any suggestions why this is happening? clone probably doing new versions of previously self-created files. How do I prevent this?

Re: Convert 10 Images with 3 clones for each

Posted: 2013-07-22T12:30:29-07:00
by GreenKoopa
Since you changed +clone to -clone 0--1, you should change the matching +delete to -delete 0--1

http://www.imagemagick.org/Usage/basics/#image_list