nativewebp
Go native WebP encoder with zero external dependencies
About nativewebp
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 applied the png.BestCompression setting to achieve the most competitive compression outcomes.
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)
}
Frequently Asked Questions
What is nativewebp?
nativewebp is a Images library for the Go programming language. Go native WebP encoder with zero external dependencies
How do I install nativewebp?
Install nativewebp with the Go module system using `go get HugoSmits86/nativewebp`. Check the repository for the current installation instructions.
What category does nativewebp belong to?
nativewebp is listed under Images, specifically Images.