ImageMagick montage always includes labels

1.6k views Asked by At

In the ImageMagick documentation, it says that if you use montage without any fancy options, it should just line up your images without any decoration and with some spacing.

That's not happening to me. Here are my two input images:

Image1 enter image description here

These are two separate PNGs, both of size 100x100, with red backgrounds. Now, if I run montage 1.png 2.png out.png, it produces an image file out.png that looks like this:

out.png

You may notice, there are labels there. I've tried everything, and I can't remove these labels. For instance, adding -label "" to the command produces this:

out2.png

It's not obvious because of the white background, but the space for labels is still part of the image, there's just nothing there.

The end result is that i want to tightly pack these images (so these two would produce a 200x100 png), and I would expect the command to be somthing like this: montage -geometry 100x100+0+0 -label "" -background blue 1.png 2.png out3.png Here I've made the background blue to highlight the "label" area, in the final version it shouldn't be necessary. This is what that command produces:

out3.png

The size of the image is 200x118, indicating that it's added 18 pixels for the labels. Removing the label argument to the command does nothing except making the label a number. I think I'm losing my mind a little bit, I've tried dozens of variations of this command, and nothing gets rid of that "label space". Given that they show up by default, and the documentation indicates that it shouldn't, I'm starting susupect that it's a bug in ImageMagick, but again: losing my mind. I think I'm probably just missing something obvious.

I'm on macOS, with ImageMagick installed through Homebrew, though I tried with the version directly from their site, and it didn't work. This is what montage -version reports:

Version: ImageMagick 7.0.5-7 Q16 x86_64 2017-05-20 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
2

There are 2 answers

2
fmw42 On BEST ANSWER

The default geometry is +2+2, so if you want them appended with no space then you must use -geometry +0+0.

Also, your files have meta data labels that are 1 and 2 respectively. So even if I change the file names to a.png and b.png, montage will apply the labels of 1 and 2. Labels will always show either from being in the meta data or if you use -label "XYZ" or -label "%f". If you do not want the labels to show, remove the labels. But even if you use -label "" or -set label "", it still leaves an empty label in the meta data. So it will leave a white space at the bottom.

magick montage 1.png 2.png -background blue -set label "" -geometry +0+0 result1.png

enter image description here

You could do a one sided (protected) -trim afterwards to remove the white. But you would have to pipe from montage to magick(convert) and pad with black on the opposite side.

However, you can just use a pipe with pnm: to remove the label, since pnm does not carry the label property. (If you use miff: or tiff:, even if you do a -strip, it will carry the label property). So this command will work like +append, though it would be easier to just use +append if you do not want any space

magick 1.png 2.png pnm:- | magick montage - -background blue -geometry +0+0 result2.png

enter image description here

2
Mark Setchell On

As a temporary workaround just use this till it gets sorted out:

convert [12].png +append out.png

enter image description here

Or, if you want a larger grid:

convert [123].png +append \( [456].png +append \) -append out.png

enter image description here

Note that +append will append side-by-side, whereas -append will append below.