mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-16 10:45:59 -07:00
Update and fix README usage code.
This commit is contained in:
parent
5af6d93b3b
commit
f538b94d63
1 changed files with 15 additions and 18 deletions
33
README.md
33
README.md
|
|
@ -10,9 +10,9 @@ The [examples](./examples) directory contains example codes and images.
|
||||||
### Decoding WebP into image.RGBA
|
### Decoding WebP into image.RGBA
|
||||||
|
|
||||||
```
|
```
|
||||||
import (
|
package main
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
|
import (
|
||||||
"github.com/harukasan/go-libwebp/examples/util"
|
"github.com/harukasan/go-libwebp/examples/util"
|
||||||
"github.com/harukasan/go-libwebp/webp"
|
"github.com/harukasan/go-libwebp/webp"
|
||||||
)
|
)
|
||||||
|
|
@ -21,10 +21,7 @@ func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Read binary data
|
// Read binary data
|
||||||
data, err := ioutil.ReadFile("examples/cosmos.webp")
|
data := util.ReadFile("cosmos.webp")
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode
|
// Decode
|
||||||
options := &webp.DecoderOptions{}
|
options := &webp.DecoderOptions{}
|
||||||
|
|
@ -33,10 +30,7 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.WritePNG(img, "out/encoded_cosmos.png")
|
util.WritePNG(img, "encoded_cosmos.png")
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -56,19 +50,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := util.ReadPNG("examples/cosmos.png")
|
img := util.ReadPNG("cosmos.png")
|
||||||
if err != nil {
|
|
||||||
panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode to WebP
|
// Create file and buffered writer
|
||||||
io := ("out.webp")
|
io := util.CreateFile("encoded_cosmos.webp")
|
||||||
w := bufio.NewWriter(f)
|
w := bufio.NewWriter(io)
|
||||||
defer func() {
|
defer func() {
|
||||||
w.Flush()
|
w.Flush()
|
||||||
f.Close()
|
io.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
config := webp.Config{
|
||||||
|
Preset: webp.PresetDefault,
|
||||||
|
Quality: 90,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode into WebP
|
||||||
if err := webp.EncodeRGBA(w, img.(*image.RGBA), config); err != nil {
|
if err := webp.EncodeRGBA(w, img.(*image.RGBA), config); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue