Search code examples
imagemagickimagemagick-convert

How to merge two half images horizontally using ImageMagick convert tool, creating a splited view?


I have two images and would like to merge them horizontally: the first half of the first image, with the second half of the second image, so that the output size is the same as the input images.

I need to run it in a command line tool, so I guess ImageMagick's convert would be ideal, but I'm struggling when I try to do that using a single command (for performance reasons). I know how to do it first cropping and appending, but it is probably much slower.

Something like this, but without the blending: enter image description here


Solution

  • There are several ways to crop and append using ImageMagick. If the two input images are the same dimensions, a very simple method like this should accomplish your task...

    convert in1.png in2.png -crop 2x1@ -delete 1,2 +append out.png
    

    That reads in both images, crops them both into two equal pieces, deletes the right half of the left image and the left half of the right image, then appends the two outer halves to create the output image.