mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-07 21:48:16 -08:00
initial commit
This commit is contained in:
commit
5af6d93b3b
26 changed files with 1165 additions and 0 deletions
88
README.md
Normal file
88
README.md
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
go-libwebp
|
||||
==========
|
||||
|
||||
A implementation of Go binding for [libwebp](https://developers.google.com/speed/webp/docs/api) written with cgo.
|
||||
|
||||
## Usage
|
||||
|
||||
The [examples](./examples) directory contains example codes and images.
|
||||
|
||||
### Decoding WebP into image.RGBA
|
||||
|
||||
```
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/harukasan/go-libwebp/examples/util"
|
||||
"github.com/harukasan/go-libwebp/webp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
|
||||
// Read binary data
|
||||
data, err := ioutil.ReadFile("examples/cosmos.webp")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Decode
|
||||
options := &webp.DecoderOptions{}
|
||||
img, err := webp.DecodeRGBA(data, options)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = util.WritePNG(img, "out/encoded_cosmos.png")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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/examples/util"
|
||||
"github.com/harukasan/go-libwebp/webp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := util.ReadPNG("examples/cosmos.png")
|
||||
if err != nil {
|
||||
panic()
|
||||
}
|
||||
|
||||
// Encode to WebP
|
||||
io := ("out.webp")
|
||||
w := bufio.NewWriter(f)
|
||||
defer func() {
|
||||
w.Flush()
|
||||
f.Close()
|
||||
}()
|
||||
|
||||
if err := webp.EncodeRGBA(w, img.(*image.RGBA), config); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- Incremental decoding API
|
||||
- Container API (Animation)
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2014 MICHII Shunsuke. All rights reserved.
|
||||
|
||||
This library is released under The BSD 2-Clause License.
|
||||
See [LICENSE](./LICENSE).
|
||||
Loading…
Add table
Add a link
Reference in a new issue