Convert IM command to Magick.NET

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
topnotchKe
Posts: 2
Joined: 2019-02-08T08:04:08-07:00
Authentication code: 1152

Convert IM command to Magick.NET

Post 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 
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Convert IM command to Magick.NET

Post 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");
}
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
topnotchKe
Posts: 2
Joined: 2019-02-08T08:04:08-07:00
Authentication code: 1152

Re: Convert IM command to Magick.NET

Post by topnotchKe »

Thank you dlemstra, this is exactly what I was looking for.
Post Reply