16

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

Mark Bell
  • 28,985
  • 26
  • 118
  • 145
Ryan Fisch
  • 2,614
  • 5
  • 36
  • 57

1 Answers1

18

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

Mark Bell
  • 28,985
  • 26
  • 118
  • 145
dlemstra
  • 7,813
  • 2
  • 27
  • 43
  • 2
    what does it mean 10? 10%? – Maxim Kitsenko Jan 16 '17 at 15:07
  • 1
    @burzhuy hope it helps. For the JPEG and MPEG image formats, quality is 1 (lowest image quality and highest compression) to 100 (best quality but least effective compression). The default is to use the estimated quality of your input image if it can be determined, otherwise 92. When the quality is greater than 90, then the chroma channels are not downsampled. You can also set quality scaling for luminance and chrominance separately (e.g. -quality 90,70). Sources: https://www.imagemagick.org/script/command-line-options.php#quality and https://www.imagemagick.org/script/formats.php – tedi Jul 11 '18 at 10:18
  • Searching and trying more than 4 hours , finally found that `.Quality ` is an option to reduce the image quality in MagickNet :(. Thanks – ehsan_kabiri_33 Apr 13 '21 at 20:40