14

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 ?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 1
    I asked this question in 2011, answered it myself in 2012 and accepted another answer in 2015. WebP development isn't going as fast as expected ;) – Denys Séguret Jun 30 '15 at 16:45

5 Answers5

8

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)
    }
}
orcaman
  • 6,263
  • 8
  • 54
  • 69
3

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

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
1

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

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
ABri
  • 610
  • 6
  • 16
1

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.

scaszoo
  • 191
  • 1
  • 4
1

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.

zzzz
  • 87,403
  • 16
  • 175
  • 139
  • 1
    I tried it but it lacks the encoder as you said and it doesn't compile in weekly. I don't get why the Google Go team seems to neglect the image format promoted by Google. – Denys Séguret Dec 01 '11 at 12:49
  • 1
    @dystroy: The outdated code is possibly gofixable and the BSD-3 license allows for an easy fork, i.e. consider to rip the decoder and then code the (probably non trivial) encoder yourself - iff you'll fail to find it somewhere else ready made and you really need it. Also to ask at golang-nuts may be worth a try. – zzzz Dec 01 '11 at 13:14
  • 1
    I don't think I have the time to code the encoder myself and I may even not have the competences to understand the existing encoders in other languages (didn't make C++ in a looong time). I'll probably ask golang-nuts even if half the mailing list probably already saw this question here :) – Denys Séguret Dec 01 '11 at 14:40