go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

commit b9bc1b74b5bb6254beace6ad9b27414eb8f14bd6
parent 656734b171d252f78a17f215075cf95fdd694456
Author: Chris Waldon <christopher.waldon.dev@gmail.com>
Date:   Tue, 25 Jan 2022 13:21:41 -0500

webp: improve docs and handle invalid quality settings

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>

Diffstat:
Mwebp/webp.go | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/webp/webp.go b/webp/webp.go @@ -13,7 +13,7 @@ import ( ) func init() { - image.RegisterFormat("webp", "RIFF", Decode, DecodeConfig) + image.RegisterFormat("webp", "RIFF????WEBP", Decode, DecodeConfig) } // Encode an image into webp with default settings. @@ -33,7 +33,11 @@ func DecodeConfig(r io.Reader) (image.Config, error) { // Encoder implements webp encoding of an image. type Encoder struct { - Quality float32 + // Quality is in the range (0,1]. Values outside of this + // range will be treated as 1. + Quality float32 + // Lossless indicates whether to use the lossless compression + // strategy. If true, the Quality field is ignored. Lossless bool } @@ -41,7 +45,7 @@ type Encoder struct { func (enc *Encoder) Encode(w io.Writer, m image.Image) error { runtime.LockOSThread() defer runtime.UnlockOSThread() - if enc.Quality == 0.0 { + if enc.Quality <= 0.0 || enc.Quality > 1 { enc.Quality = 1.0 } rgbaImage := image.NewRGBA(m.Bounds())