Set default resize image quality #138
-
Beta Was this translation helpful? Give feedback.
Answered by
JimBobSquarePants
Feb 13, 2021
Replies: 1 comment 2 replies
-
Hi @sophisma Thanks! It's really great to hear you like it! Yep you can do this at startup when registering the services. First create the following method. That will build you a custom configuration instance using a default quality of 91. internal static Configuration CreateCustomConfiguration()
{
var configuration = new Configuration(
new PngConfigurationModule(),
new GifConfigurationModule(),
new BmpConfigurationModule(),
new TgaConfigurationModule());
// 91 is the minimum quality required to force the encoder to not use
// 4:2:0 subsampling.
var jpegEncoder = new JpegEncoder { Quality = 91 };
configuration.ImageFormatsManager.SetEncoder(JpegFormat.Instance, jpegEncoder);
configuration.ImageFormatsManager.SetDecoder(JpegFormat.Instance, new JpegDecoder());
configuration.ImageFormatsManager.AddImageFormatDetector(new JpegImageFormatDetector());
return configuration;
} Then when registering the middleware services you can call it like this. services.AddImageSharp(options => options.Configuration = CreateCustomConfiguration()); You'll need the following namepspace declarations for the code to compile. using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Tga; |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sophisma
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @sophisma
Thanks! It's really great to hear you like it!
Yep you can do this at startup when registering the services.
First create the following method. That will build you a custom configuration instance using a default quality of 91.