Does anyone know how to compress images of any type (jpg, png, gif, etc.) in c# asp.net core. WebP doesn't work on core. I downloaded the ImageProcessor Core library, but can't figure out how to compress/reduce the quality of the image. Here's what we tried, but it didn't work.
newImage.Quality = old_image.Quality-20;
newImage.HorizontalResolution = 0;
newImage.VerticalResolution = 0;
We use Magic.Net to compress jpeg, gif and png images. It supports .Net Core, available via Nuget.
Example:
var file = new FileInfo(fileName);
Console.WriteLine("Bytes before: " + file.Length);
var optimizer = new ImageOptimizer();
optimizer.Compress(file);
file.Refresh();
Console.WriteLine("Bytes after: " + file.Length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With