Multiple saves

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dargaud
Posts: 31
Joined: 2006-08-06T01:58:58-07:00

Multiple saves

Post by dargaud »

Hello all,
I'm learning the basics of scripting with IM.
Is there a way to optimize the following into a single convert operation since I always start from the same source file:

Code: Select all

convert Source.jpg ...operations1... Dest1.jpg
convert Source.jpg ...operations2... Dest2.jpg
convert Source.jpg ...operations3... Dest3.jpg
And two side questions:
  • I saw it's possible to do general floating point maths with IM with "%[...]" but where is the complete explanation (syntax, list of functions, etc) about that ?
  • is there a way to get write support for the DNG format ? (something else to install / compile ?) I'm on Ubuntu.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Multiple saves

Post by Bonzo »

Try:

Code: Select all

convert Source.jpg ( +clone -thumbnail x480 -write Dest1.jpg +delete ) ( +clone -thumbnail x250 -write Dest2.jpg +delete ) -thumbnail Dest3.jpg
or

Code: Select all

convert Source.jpg -write mpr:image +delete ( mpr:image -thumbnail x480 Dest1.jpg ) ( mpr:image -thumbnail x250 -write Dest2.jpg )  ( mpr:image -colorspace Gray -write Dest3.jpg  )");
dargaud
Posts: 31
Joined: 2006-08-06T01:58:58-07:00

Re: Multiple saves

Post by dargaud »

Thanks, that would have been hard to figure out. Actually, after some tests I'm not convinced this is much faster than the simpler multiline command.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Multiple saves

Post by anthony »

It is faster as it performs the exact same operations, but only reads the source image once.
It also saves of start up processing (loading commands, libraries etc) needed.

Depending on the operations you may also gain speed by not needing to save and re-read intermediate image files, which not only can take time, and is generally slow due to disk IO, but also can introduce loss of accuracy as image files format usually are 8 bit depth, when default in memory store is a 16 bit depth.

In fact, not saving intermediate files become a crucial part for very advanced fourier transform image processing techniques using HDRI (floating point).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply