I have an ASP.NET Core based WebAPI. I am trying to convert uploaded .jpeg images to .webp. I tried using ImageProcessor library along with the ImageProcessor.Plugins.WebP to generate the .webp compressed file. Here is the code I used
public async Task<IActionResult> Store(IFormFile file)
{
if(!ModelState.IsValid)
{
return Problem("Invalid model!");
}
string absoluteFilename = Path.Combine("d:/uploaded_images", Path.GetRandomFileName() + ".webp");
using var stream = new FileStream(absoluteFilename, FileMode.Create);
using ImageFactory imageFactory = new ImageFactory(preserveExifData: false);
imageFactory.Load(file.OpenReadStream())
.Format(new WebPFormat())
.Quality(100)
.Save(stream);
return Ok(absoluteFilename);
}
But the above code takes an 83.9KB JPEG file and created a 379KB WEBP file. I tried to convert my JPEG file to WEBP using an online converter and the outcome was 73KB.
How can I correctly convert the .jpeg file to .webp?
I checked source code of this package and I think a lot of compression benefits gets lost during convertion source image to
Bitmap. I tried using Google's tool for converting files to webp and it reduced image file for from 100 KB to 74 KB. You can embed it into your project.Starting an exe in Web environment can be tricky, but you can check some articles on this topic http://www.codedigest.com/articles/aspnet/334_working_with_exe_in_aspnet-calling_killingaborting_an_exe.aspx
More about
cwebpcan be found here https://developers.google.com/speed/webp/docs/cwebpDownload link https://developers.google.com/speed/webp/download