Initial commit
This commit is contained in:
26
codec/webp.go
Normal file
26
codec/webp.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package codec
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"io"
|
||||
|
||||
"github.com/chai2010/webp"
|
||||
)
|
||||
|
||||
type WebpCoder struct{}
|
||||
|
||||
func (coder WebpCoder) Decode(r io.Reader) (image.Image, error) {
|
||||
i, err := webp.Decode(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (coder WebpCoder) Encode(i image.Image, quality int) (buf bytes.Buffer, err error) {
|
||||
if err = webp.Encode(&buf, i, &webp.Options{Lossless: true, Quality: float32(quality)}); err != nil {
|
||||
return buf, err
|
||||
}
|
||||
return buf, nil
|
||||
}
|
Reference in New Issue
Block a user