Reputation: 150
I've been trying to understand ImageMagick's image stack. Here's my understanding:
Whenever you reference an image on the command line, you add an image to the stack. Certain operators can pop multiple images off the stack and push a result image, such as +append
or -composite
. For example:
convert a.png b.png -composite output.png
This composites b on top of a, as expected.
But when I run this (I know it doesn't make sense, but I'm trying to understand the behavior):
convert a.png -composite b.png output.png
I get a picture consisting of just b.png
. Why is that? Where did the first image go? Wouldn't you expect this to error since composite doesn't have two images to work with?
In addition, if I run this,
convert -composite a.png b.png output.png
I get the same result as if I ran a.png b.png -composite
. Why is this? Wouldn't you expect this to also error?
This confuses me because I expect malformed inputs to throw errors rather than producing unexpected output. How do I avoid issues like these when working with ImageMagick?
Upvotes: 0
Views: 102
Reputation: 207540
I think it is related to the desire of the ImageMagick team to simplify and rationalise the parameter order but still accommodate folks who use the original, old parameter order.
Your first example is, IMHO, the new and preferred way of doing things, load first image, then second image, then do something with the two.
convert a.png b.png -composite output.png
Your second and third example work because of ImageMagick trying to accommodate an illogical, or maybe old-fashioned way of using it. If operators (such as -composite
) are used when there are insufficient images, it kind of remembers that and then applies it when it has enough images.
I wrote another answer here that is very related and may help clarify a bit more.
There is a good explanation here.
Upvotes: 1