Darnelix.Webp 1.2.0

dotnet add package Darnelix.Webp --version 1.2.0
                    
NuGet\Install-Package Darnelix.Webp -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Darnelix.Webp" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Darnelix.Webp" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Darnelix.Webp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Darnelix.Webp --version 1.2.0
                    
#r "nuget: Darnelix.Webp, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Darnelix.Webp@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Darnelix.Webp&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Darnelix.Webp&version=1.2.0
                    
Install as a Cake Tool

Darnelix.Webp

A WebP codec written entirely in C#. It decodes and encodes WebP — lossy, lossless, near-lossless, with alpha, still and animated — implemented from the published WebP container, VP8 and VP8L specifications. One managed assembly, no native code, zero runtime dependencies. This package targets .NET 8, .NET 9, .NET 10 and .NET 11.

What ships

  • Decode. Still images (lossy VP8 and lossless VP8L, with alpha) into RGBA32, BGRA32, ARGB32, RGB24 or BGR24; cropped and scaled decode; incremental decode from bytes as they arrive; header-only feature reads; animated WebP played frame by frame onto a composited canvas.
  • Encode. Still images, lossy (quality, effort, target size or PSNR, alpha quality and compression, sharp YUV, loop-filter settings) or lossless (effort, near-lossless preprocessing; the RGB under transparent pixels is always preserved); animated WebP assembled from full-canvas frames with per-frame durations, a loop count and a background colour.
  • Deterministic. The same input and options produce the same bytes — with or without the optional worker threads (UseThreads on the decode and encode options, off by default).
  • Defined failure. A truncated, corrupt or unsupported file raises a WebpException subtype (WebpFormatException, WebpDecodeException, WebpUnsupportedFeatureException); a bad argument raises an ArgumentException.
  • SIMD-accelerated DSP kernels on every framework this package carries, each proven bit-identical to the scalar reference implementation they replace.

Two API styles cover the same functionality. The idiomatic API — WebpDecoder, WebpEncoder, WebpAnimDecoder, WebpAnimEncoder, each with an options type — exposes everything; the static Webp class mirrors the shape of the reference C API's classic entry points for the common cases (Decode, EncodeLossy, EncodeLossless, GetFeatures). Container metadata (ICC, EXIF, XMP) and animation parameters are edited with the companion command-line tool (below).

Quick start

using System;
using System.IO;
using Darnelix.Webp;
using Darnelix.Webp.Animation;
using Darnelix.Webp.Decoding;
using Darnelix.Webp.Encoding;

byte[] file = File.ReadAllBytes("input.webp");

// Header only — no pixels decoded; false (never an exception) when the bytes are not a WebP header.
if (WebpDecoder.TryGetInfo(file, out WebpImageInfo info))
{
    Console.WriteLine($"{info.Width}x{info.Height} {info.Format} alpha={info.HasAlpha} animated={info.HasAnimation}");
}

// Decode. The image owns a pooled pixel buffer: dispose it when you are done with the pixels.
using (WebpImage image = WebpDecoder.Decode(file))
{
    Span<byte> rgba = image.Pixels;   // RGBA32, top-down, 4 bytes per pixel, no row padding
    Console.WriteLine($"{image.Width}x{image.Height} {image.Format}, {rgba.Length} bytes");
}

// Encode RGBA32 pixels. The Webp facade applies the recommended defaults (effort 4, loop-filter
// strength 60, lossless alpha at effort 100); EncodeLossy takes the quality.
int width = 64, height = 64;
byte[] pixels = new byte[width * height * 4];   // RGBA32, top-down
byte[] lossless = Webp.EncodeLossless(pixels, width, height);
byte[] lossy = Webp.EncodeLossy(pixels, width, height, 85f);
File.WriteAllBytes("output.webp", lossy);

// For anything else, build the options yourself and set every field you rely on: a new
// WebpEncodeOptions starts at zero throughout, and zero means "off" for the loop filter and the
// alpha effort. Nothing is filled in for you.
var options = new WebpEncodeOptions { Quality = 85, Method = 4, FilterStrength = 60, AlphaQuality = 100, SharpYuv = true };
byte[] tuned = WebpEncoder.Encode(pixels, width, height, PixelFormat.Rgba32, options);

Animated WebP, frame by frame:

using (var animation = new WebpAnimDecoder(file))
{
    Console.WriteLine($"{animation.Info.CanvasWidth}x{animation.Info.CanvasHeight}, {animation.Info.FrameCount} frames");
    while (animation.TryGetNextFrame(out WebpFrame frame))
    {
        // frame.Pixels is the full composited canvas (RGBA32); frame.DurationMs is its display time.
    }
}

Command-line tool

The same codec drives webpx, packaged separately as Darnelix.Webp.Cli: encode, decode, inspect, edit container metadata and animation parameters, and build or extract animations from the shell.

dotnet tool install --global Darnelix.Webp.Cli
webpx encode photo.ppm photo.webp -q 90

License

Free of charge under a proprietary licence (not open source); the full terms are in LICENSE, packed with this package.

Project site: https://www.darnelix.com/products/webp-dotnet/

Support: support@darnelix.com

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 0 11/15/2026
1.1.0 212 9/29/2026

1.2.0 — adds a .NET 11 build: the package now targets .NET 8, .NET 9, .NET 10 and .NET 11, with SIMD-accelerated DSP kernels on all four. The public API is unchanged from 1.1.0, and the decode and encode paths on .NET 8, 9 and 10 are the ones 1.1.0 shipped. What the package contains: Darnelix.Webp, a WebP codec written entirely in C#: one managed assembly, no native code, zero runtime dependencies. Decode: lossy and lossless still images, with alpha, into RGBA32, BGRA32, ARGB32, RGB24 or BGR24; cropped and scaled decode; incremental decode from bytes as they arrive; header-only feature reads; animated WebP frame by frame onto a composited canvas. Encode: lossy or lossless still images, with alpha, a target size or PSNR, sharp YUV and near-lossless preprocessing; animated WebP from full-canvas frames with per-frame durations, a loop count and a background colour. The same input and options produce the same bytes, with or without the optional worker threads. A truncated, corrupt or unsupported file raises a WebpException subtype. Container metadata and animation parameters are edited with the companion tool, Darnelix.Webp.Cli.