Reputation: 11
I am using Montage command-line tool to merge the two jpg images. The output jpg contains the common strip present in the input jpgs. Below is the command to merge two jpgs:
montage -geometry 500 input1.jpg input2.jpg output.jpg
How can I avoid the common area in the output file? Is there any other tool available to auto-merge the two images?
Upvotes: 0
Views: 802
Reputation: 4500
Before finding this answer I ended up with a slightly different strategy:
-resize
images if they have different scale (dpi)left+right-overlap
):
-extent
are the final dimensions-gravity
positions each image on the top/bottom left/right-background none
so the empty part aren't white-composite
(ImageMagick 7 code, just replace magick
with convert
for IM6)
sz=1105x1155
magick \
\( \( right.jpg -resize 924x724^ \) \
-background none -gravity northeast -extent $sz \) \
\( left.jpg -background none -gravity southwest -extent $sz \) \
-composite result.jpg
This seems less elegant than the existing answers, for example -mosaic
used by @Mark Setchell is smarter, according to the docs:
Rather than only creating an initial canvas based on just the canvas size of the initial image, the Mosaic Operator creates a canvas that is large enough to hold all the images (in the positive direction only).
... but maybe some use-case will prefer giving the merged canvas size or need -composite
options.
Upvotes: 0
Reputation: 53081
If you want to do what Mark Setchell is suggesting, then using -page is probably the best method, if you have more than one image to merge and the offsets are different. If you only have on pair of image, you can overlap them using +smush in ImageMagick. It is like +append, but allows either overlap or a gap according to the sign of the argument. Unlike -page, it only shifts in one direction according to +/- smush. Using Mark's images,
convert left.jpg right.jpg +smush -400 result.jpg
Upvotes: 1
Reputation: 207465
I suspect you are trying to make a panoramic by stitching two images with an area of common overlap.
So, if we start with left.png
:
and right.png
:
You probably want this:
convert left.png -page +200 right.png -mosaic result.png
Just so you can see what happens if I change the x-offset and also how to add a y-offset:
convert left.png -page +280+30 right.png -mosaic result.png
Upvotes: 1
Reputation: 53081
In ImageMagick, you can simply append the two images side by side or top/bottom.
convert image1.jpg image2.jpg -append result.jpg
will do top/bottom
convert image1.jpg image2.jpg +append result.jpg
will do left/right.
You can append as many images as you want of different sizes. You can use the -gravity setting to align them as desired. If different sizes, then you will have background regions, which you can control the color by using -background somecolor. If desired, you can resize the images by adding -resize 500 after reading the inputs and before the append.
See http://www.imagemagick.org/Usage/layers/#append
Upvotes: 1