chai2010 / webp

WebP decoder and encoder for Go (Zero Dependencies).
http://godoc.org/github.com/chai2010/webp
BSD 3-Clause "New" or "Revised" License
512 stars 89 forks source link

Support Resize #34

Open yuhang2 opened 3 years ago

yuhang2 commented 3 years ago

Does this library support resize images?

grokify commented 3 years ago

DecodeRGBA will return an *image.RGBA which can be resized using the standard draw package golang.org/x/image/draw.

The following should work:

m, err := webp.DecodeRGBA((data)
if err != nil {
    log.Fatal(err)
}

width := 100
height := 200
scale := draw.BiLinear

rect := image.Rect(0, 0, width, height)
dst := image.NewRGBA(rect)
scale.Scale(dst, rect, m, src.Bounds(), draw.Over, nil)