How to adjust jpeg quality with Magick.Net

Ryan Fisch picture Ryan Fisch · Nov 10, 2013 · Viewed 10.3k times · Source

I am trying to set the image quality of two images appended to one another to 10% and resize the images to 40x40.

using (var images = new MagickImageCollection {designFile, swatchFile})
{
    MagickImage sprite = images.AppendHorizontally();
    sprite.Format = MagickFormat.Jpeg;
    sprite.SetOption(MagickFormat.Jpeg, "quality", "10%");
    sprite.SetOption(MagickFormat.Jpeg, "size", "40x40"); ;

    sprite.Write(spriteFile);
}

Unfortunately the SetOption and Format calls don't seem to be affecting the file that is written to sprite.Write()?

Answer

dlemstra picture dlemstra · Nov 10, 2013

The method SetOption is the same as -define in ImageMagick. And this method will be renamed to SetDefine in the next release. The following resizes your image to 40x40 and uses a quality of 10%.

using (MagickImage sprite = images.AppendHorizontally())
{
    sprite.Format = MagickFormat.Jpeg;
    sprite.Quality = 10;
    sprite.Resize(40, 40);
    sprite.Write(spriteFile);
}

If you need more help feel free to post another question here: https://magick.codeplex.com/discussions