mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-07 21:48:16 -08: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
|
||||
|
||||
```
|
||||
import (
|
||||
"io/ioutil"
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/harukasan/go-libwebp/examples/util"
|
||||
"github.com/harukasan/go-libwebp/webp"
|
||||
)
|
||||
|
|
@ -21,10 +21,7 @@ func main() {
|
|||
var err error
|
||||
|
||||
// Read binary data
|
||||
data, err := ioutil.ReadFile("examples/cosmos.webp")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data := util.ReadFile("cosmos.webp")
|
||||
|
||||
// Decode
|
||||
options := &webp.DecoderOptions{}
|
||||
|
|
@ -33,10 +30,7 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
err = util.WritePNG(img, "out/encoded_cosmos.png")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
util.WritePNG(img, "encoded_cosmos.png")
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -56,19 +50,22 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
err := util.ReadPNG("examples/cosmos.png")
|
||||
if err != nil {
|
||||
panic()
|
||||
}
|
||||
img := util.ReadPNG("cosmos.png")
|
||||
|
||||
// Encode to WebP
|
||||
io := ("out.webp")
|
||||
w := bufio.NewWriter(f)
|
||||
// Create file and buffered writer
|
||||
io := util.CreateFile("encoded_cosmos.webp")
|
||||
w := bufio.NewWriter(io)
|
||||
defer func() {
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue