WebP编码器/解码器在Go语言中

huangapple go评论81阅读模式
英文:

WebP encoder/decoder in go

问题

有没有一个完整的WebP编码器和解码器与当前的每周版本(或可分叉版本)兼容?

它的速度与标准的png相比如何?

英文:

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 ?

答案1

得分: 8

有一个GitHub上的包,由这个人提供,包括WebP的编码器和解码器:
https://github.com/chai2010/webp

从readme文件中:

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

    // 加载文件数据
    if data, err = ioutil.ReadFile("./testdata/1_webp_ll.webp"); err != nil {
        log.Println(err)
    }

    // 获取信息
    if width, height, _, err = webp.GetInfo(data); err != nil {
        log.Println(err)
    }
    fmt.Printf("width = %d, height = %d\n", width, height)

    // 获取元数据
    if metadata, err := webp.GetMetadata(data, "ICCP"); err != nil {
        fmt.Printf("Metadata: err = %v\n", err)
    } else {
        fmt.Printf("Metadata: %s\n", string(metadata))
    }

    // 解码webp
    m, err := webp.Decode(bytes.NewReader(data))
    if err != nil {
        log.Println(err)
    }

    // 编码无损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)
    }
}
英文:

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\n", width, height)

    // GetMetadata
    if metadata, err := webp.GetMetadata(data, "ICCP"); err != nil {
        fmt.Printf("Metadata: err = %v\n", err)
    } else {
        fmt.Printf("Metadata: %s\n", 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)
    }
}

答案2

得分: 3

好的。经过长时间的搜索,我可以说,即使已经有一个解码器(https://github.com/golang/image/blob/master/webp/decode.go),但仍然没有公开可用的编码器。

英文:

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 ).

答案3

得分: 1

找到了这个,虽然我不确定它是否是你想要的。此外,它似乎缺少一个编码器,并且可能已经过时了,与当前的Go发布/每周版本不一致。

英文:

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.

答案4

得分: 1

Go的作者实际上在2014年11月将webp添加到了他们的额外的go "image"仓库(bmp/tiff/webP)中:

https://github.com/golang/image

编辑:显然该仓库不包含任何webp编码器/似乎只有阅读器。

(还没有测试过webp代码。在生产中使用之前可能需要留出更多时间进行测试。)

英文:

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.)

答案5

得分: 1

对于那些正在寻找具有webp解码器/编码器的更多软件包的人来说。

除了@orcaman提到的软件包之外,还有:

https://godoc.org/github.com/harukasan/go-libwebp/webp

https://github.com/harukasan/go-libwebp

这个软件包已经有一段时间没有更新了,但它使用了本地安装的libwebp。

英文:

For those who are looking for more packages with webp decoder/encoder.

Beside the package @orcaman mentioned, there is also:

https://godoc.org/github.com/harukasan/go-libwebp/webp

https://github.com/harukasan/go-libwebp

Which hasn't been updated for a while but uses the local install of libwebp.

huangapple
  • 本文由 发表于 2011年12月1日 19:38:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/8340751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定