imagemagickimagemagick-convertimagemagick-montage

Overlap multiple images at some pixel level using Imagemagick


For example, I have 4 images with a size of 1000x800. I want to merge all these images into one image. I know there is a command of

convert +append image[1-4].jpg output.jpg

But I want to merge the second image into the first image by overlapping 250 pixels.

i.e., In my final image, image1 has 750 pixels as well as image2 & 3 and the last image has 1000 pixels.

By using above convert command, we will get an image size of 4000x800, but here I want it to be ((750*3)+1000*1)x800. i.e., 3250x800.

Also, how can I do this by appending vertically?


Solution

  • You do not say how you want to overlap them. If you do not need to blend, then in ImageMagick, you can use smush rather than append. Smush allows offsets (gaps) or overlaps. The former with positive values and the latter with negative values to overlap succeeding images. -smush appends vertically and +smush appends horizontally. The background color controls the spacing for gaps when using positive values for the argument.

    So try

    convert image[1-4].jpg +smush -256x0 output.jpg
    

    or

    convert image1.jpg image2.jpg image3.jpg image4.jpg +smush -256x0 output.jpg
    

    or if those are the only images with that syntax, then

    convert image*.jpg +smush -256x0  output.jpg