Page 1 of 1

Convert IM command to Magick.NET

Posted: 2019-02-08T08:21:23-07:00
by topnotchKe
I have some legacy application that uses the following IM Commands and I would like to rewrite the code to use the Magick.NET library.

Can anyone provide some guidance?

Code: Select all

 Convert c:\Temp\Source.jpg -units PixelsPerInch -density 96x96 -resize 150x150 -quality 100 -type TrueColor   output.jpg 

Re: Convert IM command to Magick.NET

Posted: 2019-02-08T15:43:20-07:00
by dlemstra
Most options have the same name as the methods/properties of the MagickImage class. Your example would translate to this:

Code: Select all

using (var image = new MagickImage(@"c:\Temp\Source.jpg"))
{
    // -units PixelsPerInch -density 96x96
    image.Density = new Density(96); // PixelsPerInch is the default.

    // -resize 150x150
    image.Resize(150, 150);

    // -quality 100
    image.Quality = 100;

    // -type TrueColor
    image.ColorType = ColorType.TrueColor;

    image.Write("output.jpg");
}

Re: Convert IM command to Magick.NET

Posted: 2019-02-09T03:48:19-07:00
by topnotchKe
Thank you dlemstra, this is exactly what I was looking for.