You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
599 B
33 lines
599 B
// Package main is an example implementation of WebP encoder.
|
|
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, err := webp.ConfigPreset(webp.PresetDefault, 90)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Encode into WebP
|
|
if err := webp.EncodeRGBA(w, img.(*image.RGBA), config); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|