Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ImageMagick 'montage': How to append images horizontally and to add space between them?

I need to append two images horizontally, that is, on the left and on the right sides, and to add space between them. Here is what I use currently for this:

magick montage input1.png input2.png -geometry +10+0 output.png

But there is a problem: -geometry +10+0 adds space not only on the inner side, but also on the outer side.

magick -size 100x150 xc:red  image1.png
magick -size 100x150 xc:gree image2.png
magick montage input1.png input2.png -geometry +10+0 output.png

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(The border is added for clarity.)

Whereas what I want it

enter image description here

I can achieve it using -trim, but -trim is not really convenient for some images, e.g. if the images are book pages, and you don’t want to remove their margins. So I wonder whether this can be achieved using -geometry instead. Is it possible?

>Solution :

Use +smush N where N is the width of the gap in pixels:

magick red.png green.png +smush 10 result.png

Use -smush N to stack above/below instead of side-by-side.

Set -background blue before "smushing" to make the gap blue.

Use a negative N to overlap your images.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading