go-libwebp

module
v0.0.0-...-61eedf9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2022 License: BSD-2-Clause

README

go-libwebp

Build Status GoDoc

A implementation of Go binding for libwebp.

Dependencies

  • libwebp 0.4, 0.5

Usage

The examples directory contains example codes and images.

Decoding WebP into image.RGBA
package main

import (
	"github.com/harukasan/go-libwebp/test/util"
	"github.com/harukasan/go-libwebp/webp"
)

func main() {
	var err error

	// Read binary data
	data := util.ReadFile("cosmos.webp")

	// Decode
	options := &webp.DecoderOptions{}
	img, err := webp.DecodeRGBA(data, options)
	if err != nil {
		panic(err)
	}

	util.WritePNG(img, "encoded_cosmos.png")
}

You can set more decoding options such as cropping, flipping and scaling.

Encoding WebP from image.RGBA
package main

import (
	"bufio"
	"image"

	"github.com/harukasan/go-libwebp/test/util"
	"github.com/harukasan/go-libwebp/webp"
)

func main() {
	img := util.ReadPNG("cosmos.png")

	// Create file and buffered writer
	io := util.CreateFile("encoded_cosmos.webp")
	w := bufio.NewWriter(io)
	defer func() {
		w.Flush()
		io.Close()
	}()

	config := webp.ConfigPreset(webp.PresetDefault, 90)

	// Encode into WebP
	if err := webp.EncodeRGBA(w, img.(*image.RGBA), config); err != nil {
		panic(err)
	}
}

TODO

  • Incremental decoding API
  • Container API (Animation)

License

Copyright (c) 2016 MICHII Shunsuke. All rights reserved.

This library is released under The BSD 2-Clause License. See LICENSE.

Directories

Path Synopsis
examples
decode
Package main is an example implementation of WebP decoder.
Package main is an example implementation of WebP decoder.
encode
Package main is an example implementation of WebP encoder.
Package main is an example implementation of WebP encoder.
test
util
Package util contains utility code for demosntration of go-libwebp.
Package util contains utility code for demosntration of go-libwebp.
Package webp provides an interface to libwebp library to decoding/encoding WebP image.
Package webp provides an interface to libwebp library to decoding/encoding WebP image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL