Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust jpeg quality with Magick.Net

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()?

like image 987
Ryan Fisch Avatar asked Nov 09 '13 23:11

Ryan Fisch


1 Answers

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

like image 87
dlemstra Avatar answered Sep 18 '22 20:09

dlemstra