go-libwebp

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

decode.go (580B)


      1 package webp
      2 
      3 import (
      4 	"fmt"
      5 	"image"
      6 	"io"
      7 
      8 	stdwebp "golang.org/x/image/webp"
      9 )
     10 
     11 // Decode reads a WEBP image from r and returns it as an image.Image.
     12 func Decode(r io.Reader) (image.Image, error) {
     13 	by, err := io.ReadAll(r)
     14 	if err != nil {
     15 		return nil, fmt.Errorf("buffering data: %w", err)
     16 	}
     17 	b, err := active()
     18 	if err != nil {
     19 		return nil, err
     20 	}
     21 	return b.decode(by)
     22 }
     23 
     24 // DecodeConfig returns the color model and dimensions of a WEBP image without
     25 // decoding the entire image.
     26 func DecodeConfig(r io.Reader) (image.Config, error) {
     27 	return stdwebp.DecodeConfig(r)
     28 }