WebPWrapper

WebP CLI wrapper


Keywords
webp, wrapper, dotnet, dotnetstandart20, wrapper-library
License
MIT
Install
Install-Package WebPWrapper -Version 1.3.2

Documentation

WebPWrapper

Unit Test NuGet Version NuGet Download Github license

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.

Getting started

Install library

dotnet add package WebPWrapper

Use case

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
}

Suggestions

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