Why do some ImageMagick flags have plus sign (+) and others minus (-)?

Viewed 150

I don't see any rhyme or reason to the use of + vs -, and I've never seen a Unix command other than ImageMagick's suite (convert, etc.) which expects some flags to have a +. Win32 commands (and ports of them to Linux) sometimes use /, but never +.

1 Answers

I don't know the background behind this but personally find it quite rational. In general, the normal form is like other Linux commands preceded with a dash, or hyphen:

magick INPUT -something OUTPUT

The + form is used when there is a sense of:

  • negation, or
  • opposite direction, or
  • of resetting, disabling or clearing or
  • as a shorthand form.

There may be some overlap in these concepts, and maybe other additional ones exist.


So, in terms of "negation":

magick INPUT -fill red -opaque blue RESULT

will turn all blue pixels into red, whereas this command:

magick INPUT -fill red +opaque blue RESULT

will turn all non-blue pixels into red.

Similarly, -adjoin will clump multiple images together into a single output file if possible, whereas +adjoin will force multiple, separate output files even when it may have been possible to make, say, a multipage TIFF or animated GIF.

Another example is -level 10%,90% which will increase contrast so that the top and bottom 10% of the brightness range are discarded and the remaining 80% are stretched across the full, permissible brightness range. On the other hand, +level 10%,90% will decrease contrast by compressing the entire possible brightness range into the central 80% of the possible brightness range.


In terms of "opposite direction", this command will append images vertically below the first:

magick INPUT INPUT INPUT -append TALL_RESULT

whereas the following positive form will append images horizontally to the right:

magick INPUT INPUT INPUT +append WIDE_RESULT

In terms of "resetting, disabling or clearing", this command will use Riemer dithering:

magick INPUT -dither RiemerSMA ... RESULT

whereas the following positive form will disable dithering:

magick INPUT +dither ... RESULT

If you select a couple of channels to apply a filter or threshold to, you can reset back to the default channels afterwards:

magick INPUT -channel alpha -threshold 50% +channel RESULT

If you set a fuzz for some operation, you can reset it back to zero afterwards:

magick INPUT -fill red -fuzz 10% -opaque blue +fuzz -opaque yellow RESULT

which will set the fill-colour to red, then turn all pixels within 10% of blue into that red and also all perfectly yellow pixels into that fill-colour of red.


In terms of "shorthand", -swap 0,2 will swap the first and third image in a sequence, whereas +swap will swap the last two in the sequence regardless of how many there are. This is a common operation and the plus form is succinct compared to the conventional alternative -swap -1,-2

Likewise, -clone 2 will clone the third image in a sequence, whereas +clone will clone the last... again, a very common operation. Compare +clone with the more conventional-looking, but IMHO uglier alternative -clone -1

Likewise, +delete will delete the last image in a sequence.

Related