Search code examples
imagemagickimagemagick-convert

Black line between 2 images while using append on imagemagick


I have two files;

  • 1.jpg = 14000x2800 pixels
  • 2.jpg = 2800x128 pixels

I use the following command:

...\convert.exe -auto-orient -quality 100 -append "1.jpg" "2.jpg" "out.jpg"

The goal is to merge the images together on the vertical axis, and it works great but now I need to add a straight horizontal black line between images (line's length should be the biggest file's length, meaning from left to right) while appending.

Is there any way to do that without a second command?

Easier description with MSPaint skills

Easier description with MSPaint skills


Solution

  • Here's a way to do it:

    magick 1.jpg 2.jpg -size "%[fx:u.w>v.w?u.w:v.w]x10" xc:black -swap 2,1 -append result.png
    

    That says... load 1.jpg and 2.jpg. Define the width for the canvas we create next as "whatever is the wider of 1.jpg (referred to as u) and 2.jpg (referred to as v)" by 10 pixels tall. Create a black canvas that size. Now swap the order so that the canvas we just created is between the two images. Append all 3 images and save.

    That gives you one of these, depending which one you load first:

    enter image description here enter image description here

    If you want the unfilled, white background area beside the narrower image to be, say magenta, use:

    magick -background magenta 1.jpg 2.jpg -size "%[fx:u.w>v.w?u.w:v.w]x10" xc:black -swap 2,1 -append result.png
    

    Keywords: ImageMagick, image processing, wider, widest, taller, tallest, match existing image width, match height.