webp

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 7 Imported by: 1

README

webp-go

A Go package for working with libwebp

Example

import (
	"bytes"
	"image/png"
	"io/ioutil"
	"os"

	"github.com/shotis/webp-go"
)

func main() {
	// open our original PNG file
	file, err := os.Open("original.png")

	if err != nil {
		// end the program if it can't read the file
		log.Fatalln(err)
	}

	// decode the original image using PNG
	img, err := png.Decode(file)

	if err != nil {
		// end the program if it can't decode
		log.Fatalln(err)
	}

	// create a new webp.Config that can be converted 1:1 to a WebPConfig
	config := &webp.Config{
		Lossless: true, // Use lossless compression
		Method:   0,    // use fastest compression. This ranges from 0-6
		Quality:  100,  // try preserving 100% quality
	}

	// create a new webp.Picture. webp.Picture is a wrapper for the libwebp WebPPicture
	picture := webp.NewPicture(img)
	picture.Init()       // initialize and allocate the webp.Picture with the parameters from the passed in Image
	defer picture.Free() // free when the execution is complete

	var buf bytes.Buffer // allocate a new byte buffer where the data wil be written to

	picture.Encode(&buf, config) // Encode the image to the buffer

	ioutil.WriteFile("output.webp", buf.Bytes(), os.ModePerm) // write it to the file
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllocatedPicture

type AllocatedPicture struct {
	Picture
	// contains filtered or unexported fields
}

func NewPicture

func NewPicture(img image.Image) *AllocatedPicture

func (*AllocatedPicture) Encode

func (p *AllocatedPicture) Encode(w io.Writer, config *Config) error

func (*AllocatedPicture) Free

func (p *AllocatedPicture) Free() error

func (*AllocatedPicture) Init

func (p *AllocatedPicture) Init() error

type Config

type Config struct {
	Lossless bool
	Method   int
	Quality  float32
	Hint     Hint
	// contains filtered or unexported fields
}

type Hint

type Hint int
const (
	DefaultHint Hint = iota
	PictureHint
	PhotoHint
	GraphHint
	LastHint
)

func GetHint

func GetHint(s string) Hint

type Picture

type Picture interface {
	Bounds() image.Rectangle
	RGBA() bool
}

type RGBAPicture

type RGBAPicture struct {
	// contains filtered or unexported fields
}

func NewNRGBAImage

func NewNRGBAImage(img *image.NRGBA) *RGBAPicture

func NewRGBAImage

func NewRGBAImage(img *image.RGBA) *RGBAPicture

func (*RGBAPicture) Bounds

func (p *RGBAPicture) Bounds() image.Rectangle

func (*RGBAPicture) Pixels

func (p *RGBAPicture) Pixels() []uint8

func (*RGBAPicture) RGBA

func (p *RGBAPicture) RGBA() bool

func (*RGBAPicture) Stride

func (p *RGBAPicture) Stride() int

type YUVAPicture

type YUVAPicture struct {
	// contains filtered or unexported fields
}

func NewYUVAPicture

func NewYUVAPicture(img *image.YCbCr) *YUVAPicture

func (*YUVAPicture) Bounds

func (p *YUVAPicture) Bounds() image.Rectangle

func (*YUVAPicture) RGBA

func (*YUVAPicture) RGBA() bool

func (*YUVAPicture) UVStride

func (p *YUVAPicture) UVStride() int

func (*YUVAPicture) YStride

func (p *YUVAPicture) YStride() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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