imagemagickappendjpegmontage

ImageMagick: How to combine 200 images in pairs of 2 side-by-side (book layout)


I have 200 jpgs that are the same size. I need to combine them in pairs, putting them side-by-side.

So

1.jpg
2.jpg
3.jpg
4.jpg

Should make 2 new jpgs, one containing 1 and 2, and the other containing 3 and 4. Side by side.

Think of each image as a page of a book.

Is there anyway to automate this using imageMagick montage?


Solution

  • I ended up using ImageMagick NuGet package in a .NET console application and did the following:

    using (MagickImageCollection images = new MagickImageCollection())
                {                   
                    for (var i = 2; i <= 210; i=i+2)
                    {
                        var first =
                            new MagickImage(string.Format("PATH-TO-IMAGE-FOLDER_{0}.jpg", i.ToString().PadLeft(3, '0')));
    
                        var second =
                            new MagickImage(string.Format("PATH-TO-IMAGE-FOLDER_{0}.jpg", (i+1).ToString().PadLeft(3, '0')));
    
                        images.Add(first);
                        images.Add(second);
    
    
                        using (MagickImage result = images.SmushHorizontal(0))
                        {
                            result.Write(string.Format("{0}.png", i));
                        }
    
                        images.Clear();
                    }  
                }