Combine multiple commands into one

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
kocheez75
Posts: 2
Joined: 2012-05-17T18:53:40-07:00
Authentication code: 13

Combine multiple commands into one

Post by kocheez75 »

Hello, I am very new to using imageMagick and I'm still learning a lot, so I greatly appreciate any help someone may have to offer.

I currently have the following commands performed on a single image (this is inside a shell script):

Code: Select all

   `convert $file \( -clone 0 -fill '#222b6d' -colorize 100% \) \( -clone 0 -colorspace gray -negate \) -compose blend -define compose:args=100,0 -composite $file`
   `convert $file \( -clone 0 -fill '#f7daae' -colorize 100% \) \( -clone 0 -colorspace gray \) -compose blend -define compose:args=100,0 -composite $file`
   `convert $file -contrast -modulate 100,150,100 -auto-gamma $file`
And this gives me the results I want. However, I would like to combine this just one 'convert' command. I have been reading up on using the stacks, but still not sure about the syntax and underlying details. If someone posts a solution, and explanation of why it works (or what it's doing) would be very insightful for me. For my particular implementation, I don't need to preserve the original image, although if that's also a possibility it might be useful as well.

Again, I have been pounding on this for several hours now so any help would be greatly appreciated :)

Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine multiple commands into one

Post by fmw42 »

If I have not misread your command you are doing a masked blending, then doing another masked blending on the result of the first, then some final processing on the result of the second masked blending. The convert ... -composite operation can stack successive commands upon the result (as the original and temps are thrown away), so long as your only composite 3 images including the mask. So this should do what you want.


convert $file \( -clone 0 -fill '#222b6d' -colorize 100% \) \( -clone 0 -colorspace gray -negate \) \
-compose blend -define compose:args=100,0 -composite \
\( -clone 0 -fill '#f7daae' -colorize 100% \) \( -clone 0 -colorspace gray \) \
-compose blend -define compose:args=100,0 -composite \
-contrast -modulate 100,150,100 -auto-gamma $newfile

Generally best to write to a new file at least while testing.

See
http://www.imagemagick.org/Usage/layers/#convert
kocheez75
Posts: 2
Joined: 2012-05-17T18:53:40-07:00
Authentication code: 13

Re: Combine multiple commands into one

Post by kocheez75 »

Thank you, this does indeed complete what I was trying to achieve!

I guess I'm still not sure about why the clone statements need to be in parentheses vs the composite. Is it possible to just perform the colorize on the original image rather than creating the clone (and wouldn't this eliminate the need for a composite?)

Thanks again for all your help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine multiple commands into one

Post by fmw42 »

kocheez75 wrote:Thank you, this does indeed complete what I was trying to achieve!

I guess I'm still not sure about why the clone statements need to be in parentheses vs the composite. Is it possible to just perform the colorize on the original image rather than creating the clone (and wouldn't this eliminate the need for a composite?)

Thanks again for all your help!
Clones must be in parens. They are used for processing that is separate from the main command. If you left them out, all the commands would compound on the previous result and not be separate. The clones are there because you need to do different things on the same input image. So rather than read the input image multiple times, the clones save this extra reading as they just reference the image already read.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Combine multiple commands into one

Post by anthony »

See Parenthesis, Processing images on the side
http://www.imagemagick.org/Usage/basics/#parenthesis

You may also like to look at
Complex Image Processing and Debugging
http://www.imagemagick.org/Usage/basics/#complex
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
weblife
Posts: 21
Joined: 2016-01-06T22:23:33-07:00
Authentication code: 1151

Re: Combine multiple commands into one

Post by weblife »

@anthony Thank you very much for the references.
Post Reply