Search code examples
c#imageresizer

Image Resizer: No image encoder was found for the request (WebP)


I have a problem with the encoding of images in WebP format using the Imageresizer .NET library.

This is the fragment of code that raise the exception:

ImageResizer.ImageJob i1920Webp = new ImageResizer.ImageJob(filePath, filePath.Replace(name, name + "-1920").Replace(ext, ".webp"),new ImageResizer.Instructions("width=1920;format=webp;quality=65"));
i1920Webp.Build();

This is the relative stack trace:

[ImageProcessingException (0x80004005): No image encoder was found for this request.]
ImageResizer.ImageBuilder.buildToStream(Bitmap source, Stream dest, ResizeSettings settings) +270
ImageResizer.ImageBuilder.BuildJob(ImageJob job) +1237
ImageResizer.ImageBuilder.Build(ImageJob job) +268

The Build() method call raises the exception. The destination file was created on filesystem but it's empty (0 byte); it's correctly named: image-1920.webp

I've installed the WebP plugin via NuGet; I've added the <add name="WebPEncoder" /> in the plugins subsection of the resizer section of the web.config.

I don't understand what's the problem.


Solution

  • Nathanael, I've followed the hints in your latest comment and now it works. This is what I've done:

    var config = new ImageResizer.Configuration.Config();
    new WebPEncoderPlugin().Install(config);
    config.BuildImage(
        filePath, 
        filePath.Replace(name, name + "-1920").Replace(ext, ".webp"),
        "width=1920;format=webp;quality=65"
    );
    

    Thank you for your support!