douyan1453
douyan1453
2011-12-01 11:38
浏览 69
已采纳

WebP编码器/解码器

Is there somewhere a complete WebP encoder and decoder compatible with current weekly (or forkable)?

Is it comparable in speed to the standard png one ?

图片转代码服务由CSDN问答提供 功能建议

是否有完整的WebP编码器和解码器与当前每周(或可插拔)兼容?

它的速度是否可以与标准png one相提并论?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongwei1895
    dongwei1895 2015-06-30 16:01
    已采纳

    There is a package by this guy on GitHub that includes both an encoder and a decoder for WebP: https://github.com/chai2010/webp

    From the readme file:

    package main
    
    import (
        "bytes"
        "fmt"
        "io/ioutil"
        "log"
    
        "github.com/chai2010/webp"
    )
    
    func main() {
        var buf bytes.Buffer
        var width, height int
        var data []byte
        var err error
    
        // Load file data
        if data, err = ioutil.ReadFile("./testdata/1_webp_ll.webp"); err != nil {
            log.Println(err)
        }
    
        // GetInfo
        if width, height, _, err = webp.GetInfo(data); err != nil {
            log.Println(err)
        }
        fmt.Printf("width = %d, height = %d
    ", width, height)
    
        // GetMetadata
        if metadata, err := webp.GetMetadata(data, "ICCP"); err != nil {
            fmt.Printf("Metadata: err = %v
    ", err)
        } else {
            fmt.Printf("Metadata: %s
    ", string(metadata))
        }
    
        // Decode webp
        m, err := webp.Decode(bytes.NewReader(data))
        if err != nil {
            log.Println(err)
        }
    
        // Encode lossless webp
        if err = webp.Encode(&buf, m, &webp.Options{Lossless: true}); err != nil {
            log.Println(err)
        }
        if err = ioutil.WriteFile("output.webp", buf.Bytes(), 0666); err != nil {
            log.Println(err)
        }
    }
    
    点赞 评论
  • dongsu4345
    dongsu4345 2011-12-01 12:47

    Found this, although I'm not sure if it's what you want. Additionally it seems to lack an encoder + it may be outdated wrt current Go release/weekly versions.

    点赞 评论
  • dongma7796
    dongma7796 2012-04-27 13:34

    OK. After long searches, I can say that there still is no publicly available encoder even if a decoder was made ( https://github.com/golang/image/blob/master/webp/decode.go ).

    点赞 评论
  • doujiekeyan0622
    doujiekeyan0622 2014-11-27 08:00

    The Go Authors actually (2014/11) added webp to their additional go "image" repo (bmp/tiff/webP) here:

    https://github.com/golang/image

    EDIT: Obviously the repo does not contain any webp encoder / seems to be the reader - only.

    (Haven't tested the webp code so far. Maybe leave some more time 4 testing before using in production.)

    点赞 评论