I am using ImageMagick on the CLI like this:
gm convert input.png -crop 512x512 +repage +adjoin "tiles/tile%02d.png"
to create a tiled version of my input image. But i want to do it with GraphicsMagick.NET or Magick.NET instead of using the command line. The problem that occurred to me is that neither GM.NET or IM.NET seem to support "+repage" and "+adjoin" properly. Instead both generate only a single output image.
I tried the following code in C# but without success.
GraphicsMagick.NET Test
MagickImage image = new MagickImage("test.png");
MagickGeometry geo = new MagickGeometry(512,512);
image.Crop(geo);
image.RePage();
image.Adjoin = true; // i tried false too!
image.Write("testout_%d.png");
ImageMagick.NET Test
// ImageMagick.NET Test
using (MagickImage image = new MagickImage("test.png"))
{
image.Crop(512, 512,Gravity.Northwest);
image.RePage();
image.Adjoin = true;
image.Write("testout_%d.png");
}
I also tried out MSL to generate a tiled version of my image, but MSL does not seem to support this either, both adjoin and repage are missing in MSL completely.
The crop option is calling different code then what you are expecting. Cropping an image into tiles is currently only supported by Magick.NET. Below is an example of how you could do that.
using (MagickImage image = new MagickImage("test.png"))
{
int i = 0;
foreach (MagickImage tile in image.CropToTiles(512, 512))
{
tile.Write("testout_" + (i++) + ".png");
}
}
P.s. Both adjoin and rePage are supported by MagickScript (MSL)