Page 1 of 1
Is it possible to produce 2 different sized images in one go
Posted: 2010-08-23T06:41:23-07:00
by NeilF
Currently I'm producing two images via two commands. One for optimised TV viewing, and another as a small thumbnail.
Is it possible to do this in one command, hopefully speeding the process up?
Here's examples of my two commands:-
tiny thumbnail: convert <filename> -auto-orient -resize 200x150 -background black -gravity center -extent 200x150 -quality 60 -strip <thumb_filename>
resized photo: convert <fileName> -auto-orient -resize 1920x1080> -quality 60 <thumb_filename>
Notice on the thumbnail making the image 200x150, complete with black background, and stripping out the metatags to reduce filesize.
Now the source file could be X meg big so I suspect if these two conversions could be done by one command instead of two, there might be some speed savings to be had!?
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-23T07:14:35-07:00
by Bonzo
Try:
Code: Select all
convert <filename> -auto-orient ( +clone -resize 200x150 -background black -gravity center -extent 200x150 -quality 60 -strip -write <thumb_filename> ) -resize 1920x1080> -quality 60 <thumb_filename>
You may need to use a \ in front of the ( and )
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-23T19:44:46-07:00
by anthony
See IM examples, Image File handling, Writing an Image Multiple Times
http://www.imagemagick.org/Usage/files/#write
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-24T05:36:31-07:00
by NeilF
Bonzo wrote:Try:
Code: Select all
convert <filename> -auto-orient ( +clone -resize 200x150 -background black -gravity center -extent 200x150 -quality 60 -strip -write <thumb_filename> ) -resize 1920x1080> -quality 60 <thumb_filename>
You may need to use a \ in front of the ( and )
Thanks... Combining them like below almost halved the time for large photos to generate two images... Guess because when the 200x150 is generated it's already working with a far smaller image!
Just seemed to need a -write statement in there, and also a +delete else you'd get some oddly name files popping out too? Huh?
eg:-
convert 001_2.JPeG -resize "1920x1080>" -auto-orient ( +clone -strip -resize 200x150 -background black -gravity center -extent 200x150 -quality 60 -write 001_2_THUMB3.jpg +delete ) -quality 60 001_2_RESIZE3.jpg
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-24T05:58:07-07:00
by Bonzo
To save time on jpg images you can add a "hint" but it may not work very well in this case.
Code: Select all
convert -define jpeg:size=1920x1080 001_2.JPeG -resize "1920x1080>" -auto-orient ( +clone -strip -resize 200x150 -background black -gravity center -extent 200x150 -quality 60 -write 001_2_THUMB3.jpg +delete ) -quality 60 001_2_RESIZE3.jpg
I belive the speed increase is that the image is only read in once.
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-24T06:05:56-07:00
by NeilF
Bonzo wrote:To save time on jpg images you can add a "hint" but it may not work very well in this case.
Code: Select all
convert -define jpeg:size=1920x1080 001_2.JPeG -resize "1920x1080>" -auto-orient ( +clone -strip -resize 200x150 -background black -gravity center -extent 200x150 -quality 60 -write 001_2_THUMB3.jpg +delete ) -quality 60 001_2_RESIZE3.jpg
I belive the speed increase is that the image is only read in once.
The big speed increase only manifests itself when I move the 1920x1080> upfront. With it done after the clone, its only a little faster than the two individual commands. Issuing the resize before the thumb creation though makes a big difference
What does your example show sorry? ie: What does the "-define jpeg:size=1920x1080" do?
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-24T10:19:35-07:00
by fmw42
It only reads as much as needed (only works for jpg). see
http://www.imagemagick.org/Usage/formats/#jpg_read
Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-24T10:33:08-07:00
by NeilF
Cheers! I had a quick test but didn't notice my 3 seconds reduce down... I'll give it some more tests...
But to be honest my 5-6 seconds for producing the two images, has now reduced down to about 3 with the single command doing it, which is a great increase already

Re: Is it possible to produce 2 different sized images in on
Posted: 2010-08-24T16:17:33-07:00
by anthony
A couple of final points to think about. And ones that are repeated many times
use
-thumbnail rather than
-resize... This strips the meta-data and profiles from the jpeg making the later images much much smaller. It also removes details such as GPS location focus, time stamps etc, which is generally not wanted or needed on smaller images (typically used for web work).
using -define jpeg:size=??? is equivalent to doing a
-sample (see
Resize sample) better to use it at twice the resize that will be involved.
However in your case it may not see much improvement simply because your first resize is quite large, as such it probably ends up reading in the whole image in any case. The
Jpeg size hint is more for generating very much smaller (thumbnail) images. Such as in your original second (very small) image command. As you are doing the two steps together, it would not have as big an advantage.
Finally the reason the original example has the resize AFTER the parenthesis, is so each of the two images are generated directly from the original. Processing one image, then re-processing the image again, while faster (at least in this case), may not produce the best quality. Though considering you are doing resizing, with large resize differences, it should not be a problem, at least not in this case.
See the top section of
Thumbnailing Images for more info.