Categorygithub.com/HugoSmits86/nativewebp
repositorypackage
0.9.3
Repository: https://github.com/hugosmits86/nativewebp.git
Documentation: pkg.go.dev

# 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).

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 decoder.

PNG encodernativeWebP encoderreduction

file size121kb105kb13% smaller
encoding time14170403 ns/op5389776 ns/op62% faster

file size48kb38kb21% smaller
encoding time10662832 ns/op3760902 ns/op65% faster

file size23821510% smaller
encoding time30952147 ns/op16371708 ns/op47% faster

file size53kb43kb19% smaller
encoding time4511737 ns/op2181801 ns/op52% faster

file size140kb137kb2% smaller
encoding time11045284 ns/op4850678 ns/op56% 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)
}