This library is a wrapper for WebP CLI. Provides a simple CLI parameter builder, making it easier to use WebP in development
For more information about WebP and WebP CLI, please refer to this website.
dotnet add package WebPWrapper
using WebPWrapper;
using WebPWrapper.Encoder;
WebPExecuteDownloader.Download();
var builder = new WebPEncoderBuilder();
var encoder = builder
.Resize(100, 0) // Resize image to 100px (length)
.AlphaConfig(x => x // set alpha config
.TransparentProcess(
TransparentProcesses.Blend, // Change transparent color to blend with yellow color
Color.Yellow
)
)
.CompressionConfig(x => x // set compression config
.Lossless(y => y.Quality(75)) // set lossless config
)
.Build(); // build encoder
using (var outputFile = File.Open("output.webp", FileMode.Create))
using (var inputFile = File.Open("input.png", FileMode.Open)) {
encoder.Encode(inputFile, outputFile); // encode image
}
For containerized services, I do not recommend downloading CLI in Runtime.
I recommend installing the CLI when building the docker image. Then set executeFilePath
in builder class's constructs