Page 1 of 1
Combine multiple commands into one
Posted: 2012-05-17T19:01:28-07:00
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.
Re: Combine multiple commands into one
Posted: 2012-05-17T19:24:53-07:00
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
Re: Combine multiple commands into one
Posted: 2012-05-21T09:43:44-07:00
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!
Re: Combine multiple commands into one
Posted: 2012-05-21T10:04:42-07:00
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.
Re: Combine multiple commands into one
Posted: 2012-05-21T23:48:11-07:00
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
Re: Combine multiple commands into one
Posted: 2016-02-22T17:43:38-07:00
by weblife
@anthony Thank you very much for the references.