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?
The size of the .webp file is much larger than initial .jpeg file
ImageProcessor version: latest
Other ImageProcessor packages and versions:
WebP can both be lossy and lossless: in this case you're setting the quality to 100% and using lossless. JPEG is lossy, so this the same as saving it as PNG (a lossless format), which would also increase the file size.
@ronaldbarendse thanks for the feedback. I don't want to lose image quality, I just want to reduce the size of the file which is why I am trying to convert my JPEG images to WebP. How should my code change so that the new files are smaller than my JPEG without losing image quality?
@ronaldbarendse I removed the .Quality(100) and the file which was 83.9 KB is now 100KB. So the size went up not down.
We currently only support a limited subset of the WebP functionality and our encoding methods encode all 4 BGRA components. We'd have to create a wrapper around the native method for supporting BGR.
However....
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
ImageProcessor is not supported and will never support .NET Core. It contains targets for .NET Framework only and I'm surprised you have not had many other issues.
Hey @magic-john I've just added 24bit WebP encoding to the v3 branch. Theoretically I could add it to the v2 build.
Could you supply the input jpeg you were getting the larger result with so I can do some testing. Thanks!
I removed the .Quality(100) and the file which was 83.9 KB is now 100KB. So the size went up not down.
PS. This makes no sense to me. You were asked to compare lossy vs lossless WebP output. The file sizes given look like the jpeg output.
@JimBobSquarePants Here is the raw image.

Thank you.
I did some investigating this evening.
I had a look at the input jpeg using JpegSnoop and it is encoded with a quality of 75. ImageFactory defaults to a quality of 90. (Hence why you still peaked at 100KB)
If you set ImageFactory to encode the image using a quality 75 then the WebP output size is 52KB. Jpeg is encoded with the same filesize as the input at 83.9KB.
I've attached the two files for comparison.
issue-789.zip
I'm going to go ahead and close this as given identical parameters the WebP output is clearly smaller.