MCPcopy Index your code
hub / github.com/HugoSmits86/nativewebp

github.com/HugoSmits86/nativewebp @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
91 symbols 268 edges 10 files 9 documented · 10% 1 cross-repo links updated 2mo agov1.3.0 · 2026-05-10★ 4501 open issues

Browse by type

Functions 83 Types & classes 8
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Codecov Coverage Go Reference License: MIT

Native WebP for Go

This is a native WebP encoder written entirely in Go, with no dependencies on libwebp or other external libraries. Designed for performance and efficiency, this encoder generates smaller files than the standard Go PNG encoder and is approximately 50% faster in execution.

Currently, the encoder supports only WebP lossless images (VP8L).

Decoding Support

We provide WebP decoding through a wrapper around golang.org/x/image/webp, with an additional DecodeIgnoreAlphaFlag function to handle VP8X images where the alpha flag causes decoding issues.

Benchmark

We conducted a quick benchmark to showcase file size reduction and encoding performance. Using an image from Google’s WebP Lossless and Alpha Gallery, we compared the results of our nativewebp encoder with the standard PNG encoder.

For the PNG encoder, we used png.BestCompression. Likewise, nativewebp was configured with nativewebp.BestCompression so both encoders were benchmarked using their maximum compression settings.

PNG encoder nativeWebP encoder reduction
file size 120 kb 95 kb 21% smaller
encoding time 42945049 ns/op 35413726 ns/op 17% faster
file size 46 kb 35 kb 24% smaller
encoding time 98509399 ns/op 42626779 ns/op 57% faster
file size 236 kb 190 kb 19% smaller
encoding time 178205535 ns/op 96800750 ns/op 46% faster
file size 53 kb 39 kb 26% smaller
encoding time 29088555 ns/op 19877708 ns/op 32% faster
file size 139 kb 119 kb 14% smaller
encoding time 63423995 ns/op 27813126 ns/op 56% faster

image source: https://developers.google.com/speed/webp/gallery2

Installation

To install the nativewebp package, use the following command:

go get github.com/HugoSmits86/nativewebp

Usage

Here’s a simple example of how to encode an image:

file, err := os.Create(name)
if err != nil {
  log.Fatalf("Error creating file %s: %v", name, err)
}
defer file.Close()

err = nativewebp.Encode(file, img, nil)
if err != nil {
  log.Fatalf("Error encoding image to WebP: %v", err)
}

Here’s a simple example of how to encode an animation:

file, err := os.Create(name)
if err != nil {
  log.Fatalf("Error creating file %s: %v", name, err)
}
defer file.Close()

ani := nativewebp.Animation{
  Images: []image.Image{
    frame1,
    frame2,
  },
  Durations: []uint {
    100,
    100,
  },
  Disposals: []uint {
    0,
    0,
  },
  LoopCount: 0,
  BackgroundColor: 0xffffffff,
}

err = nativewebp.EncodeAll(file, &ani, nil)
if err != nil {
  log.Fatalf("Error encoding WebP animation: %v", err)
}

Core symbols most depended-on inside this repo

Shape

Function 73
Method 10
Struct 5
TypeAlias 3

Languages

Go100%

Modules by API surface

writer_test.go23 symbols
writer.go20 symbols
huffman.go13 symbols
transform.go6 symbols
bitwriter.go6 symbols
transform_test.go5 symbols
reader_test.go5 symbols
bitwriter_test.go5 symbols
reader.go4 symbols
huffman_test.go4 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add nativewebp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page