This project has moved and is read-only. For the latest updates, please go here.

Having trouble trying to replicate a ImageMagic montage command

Aug 1, 2014 at 11:44 AM
Hi,

Im trying to move some batch code image generation over to Magick.net to run it on an ASP.NET webpage. All of my image generation code is working but having trouble trying to get the below to work.

Im trying to replicate the following
montage -mode concatenate -tile 1x red.png orange.png yellow.png green.png yellow.png red.png out.jpg
using (MagickImageCollection images = new MagickImageCollection())
            {
                // Add the first image
                MagickImage first = new MagickImage("blue.png");
                images.Add(first);

                // Add the second image
                MagickImage second = new MagickImage("yellow.png");
                images.Add(second);

                images.Add(first);
                images.Add(first);

                MontageSettings montage_settings = new MontageSettings();

                montage_settings.TileGeometry = new MagickGeometry(1, 4);

                // Create a mosaic from both images
                using (MagickImage result = images.Montage(montage_settings))
                {
                    // Save the result
                    result.Write("out.png");
                }
            }
This gets me one column with four images in it, but each of the images are surrounded by a white border. Cant for the life of me work out how to get rid of that.

Any ideas?
Aug 1, 2014 at 12:16 PM
Edited Aug 1, 2014 at 12:17 PM
The -mode concatenate option sets a set of default values that are not set by the MontageSettings constructor. The MontageSettings constructor also sets a set of default options. I will add a constructor in the next version of Magick.NET that will allow you to specify the mode.

I think your problem will be solved if you set montage_settings.Geometry to null.
Aug 1, 2014 at 12:33 PM
Thanks for the quick reply. However I get a crash if I set montage_settings.Geometry to null
Any rough ETA for when the constructor would be there? Just so I can make the call to go ahead and manually fudge the image files for the minute.....
An unhandled exception of type 'ImageMagick.MagickOptionErrorException' occurred in Magick.NET-AnyCPU.dll

Additional information: Magick: InvalidGeometry `(null)' @ error/geometry.c/ParseRegionGeometry/1509
Aug 1, 2014 at 2:47 PM
I was planning to publish a new release tonight but I will delay it a couple of days so I can add the constructor and fix the Geometry bug.

I just realized that for your situation MagickImageCollection.AppendHorizontally should be enough:
using (MagickImageCollection images = new MagickImageCollection())
{
  // Add the first image
  MagickImage first = new MagickImage("blue.png");
  images.Add(first);

  // Add the second image
  MagickImage second = new MagickImage("yellow.png");
  images.Add(second);

  images.Add(first);
  images.Add(first);

  using (MagickImage result = images.AppendHorizontally())
  {
    // Save the result
    result.Write("out.png");
  }
}
Aug 1, 2014 at 4:56 PM
Brilliant!
And yes, images.AppendVertically() does do exactly what I want - you are a star!

Mat
Aug 1, 2014 at 5:47 PM
Edited Aug 1, 2014 at 5:47 PM
It turns out you cannot set the Geometry to null and that is why you are receiving that error message. I will still add the constructors for MontageSettings even though AppendHorizontally works for you.