Initial commit

This commit is contained in:
2024-08-29 11:32:55 +02:00
commit b168c688cd
9 changed files with 226 additions and 0 deletions

26
codec/webp.go Normal file
View 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
}