WebP decoder and encoder for Go (Zero Dependencies).

Overview

webp

██╗    ██╗███████╗██████╗ ██████╗
██║    ██║██╔════╝██╔══██╗██╔══██╗
██║ █╗ ██║█████╗  ██████╔╝██████╔╝
██║███╗██║██╔══╝  ██╔══██╗██╔═══╝
╚███╔███╔╝███████╗██████╔╝██║
 ╚══╝╚══╝ ╚══════╝╚═════╝ ╚═╝

Build Status GoDoc

Benchmark

Install

Install GCC or MinGW (download here) at first, and then run these commands:

  1. go get github.com/chai2010/webp
  2. go run hello.go

Example

This is a simple example:

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)
	}
    
    fmt.Println("Save output.webp ok")
}

Decode and Encode as RGB format:

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

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

Notes

Change the libwebp to fast method:

internal/libwebp/src/enc/config.c
WebPConfigInitInternal
config->method = 0; // 4;

BUGS

Report bugs to [email protected].

Thanks!

Comments
  • Upgrade libwebp to 1.0.2

    Upgrade libwebp to 1.0.2

    We are using this library to convert images into WebP format, thanks for your awesome job. Here is our options:

    • lossless: false
    • quality: 70

    After all images has converted, we found some images's compress rate is higher than 100. Then we try to use cwebp-1.0.2 to convert those images, and almost images's compress rate is lower than 100.

    So I made this PR to upgrade libwebp's version to 1.0.2, and I also made some tests:

    Compress Rate Report Between 1.0.2 and 0.5.0(`+` made by 1.0.2 and `-` made by `0.5.0`
    - images/10.jpeg - raw_size: 268675 - webp_size: 294154 - compress_rate: 109.48
    + images/10.jpeg - raw_size: 268675 - webp_size: 260364 - compress_rate: 96.91
    - images/100.jpeg - raw_size: 150187 - webp_size: 150786 - compress_rate: 100.40
    + images/100.jpeg - raw_size: 150187 - webp_size: 109580 - compress_rate: 72.96
    - images/101.jpeg - raw_size: 147819 - webp_size: 147982 - compress_rate: 100.11
    + images/101.jpeg - raw_size: 147819 - webp_size: 117970 - compress_rate: 79.81
    - images/102.jpeg - raw_size: 142298 - webp_size: 146328 - compress_rate: 102.83
    + images/102.jpeg - raw_size: 142298 - webp_size: 104992 - compress_rate: 73.78
    - images/103.jpeg - raw_size: 140774 - webp_size: 141184 - compress_rate: 100.29
    + images/103.jpeg - raw_size: 140774 - webp_size: 110424 - compress_rate: 78.44
    - images/104.jpeg - raw_size: 138640 - webp_size: 147868 - compress_rate: 106.66
    + images/104.jpeg - raw_size: 138640 - webp_size: 113796 - compress_rate: 82.08
    - images/105.jpg - raw_size: 137696 - webp_size: 145858 - compress_rate: 105.93
    + images/105.jpg - raw_size: 137696 - webp_size: 78132 - compress_rate: 56.74
    - images/106.jpeg - raw_size: 137832 - webp_size: 141070 - compress_rate: 102.35
    + images/106.jpeg - raw_size: 137832 - webp_size: 100304 - compress_rate: 72.77
    - images/107.jpg - raw_size: 135415 - webp_size: 170110 - compress_rate: 125.62
    + images/107.jpg - raw_size: 135415 - webp_size: 107752 - compress_rate: 79.57
    - images/108.jpeg - raw_size: 134618 - webp_size: 140256 - compress_rate: 104.19
    + images/108.jpeg - raw_size: 134618 - webp_size: 110316 - compress_rate: 81.95
    - images/109.jpeg - raw_size: 132110 - webp_size: 144796 - compress_rate: 109.60
    + images/109.jpeg - raw_size: 132110 - webp_size: 86544 - compress_rate: 65.51
    - images/11.jpeg - raw_size: 266425 - webp_size: 296350 - compress_rate: 111.23
    + images/11.jpeg - raw_size: 266425 - webp_size: 233448 - compress_rate: 87.62
    - images/110.jpeg - raw_size: 132710 - webp_size: 134124 - compress_rate: 101.07
    + images/110.jpeg - raw_size: 132710 - webp_size: 108030 - compress_rate: 81.40
    - images/111.jpeg - raw_size: 120794 - webp_size: 128138 - compress_rate: 106.08
    + images/111.jpeg - raw_size: 120794 - webp_size: 88776 - compress_rate: 73.49
    - images/112.jpg - raw_size: 119664 - webp_size: 130408 - compress_rate: 108.98
    + images/112.jpg - raw_size: 119664 - webp_size: 114760 - compress_rate: 95.90
    - images/113.jpeg - raw_size: 118361 - webp_size: 118642 - compress_rate: 100.24
    + images/113.jpeg - raw_size: 118361 - webp_size: 91092 - compress_rate: 76.96
    - images/114.jpg - raw_size: 115883 - webp_size: 125030 - compress_rate: 107.89
    + images/114.jpg - raw_size: 115883 - webp_size: 100722 - compress_rate: 86.92
    - images/115.jpeg - raw_size: 115251 - webp_size: 115494 - compress_rate: 100.21
    + images/115.jpeg - raw_size: 115251 - webp_size: 88940 - compress_rate: 77.17
    - images/116.jpeg - raw_size: 113461 - webp_size: 114482 - compress_rate: 100.90
    + images/116.jpeg - raw_size: 113461 - webp_size: 85830 - compress_rate: 75.65
    - images/117.jpeg - raw_size: 108900 - webp_size: 117792 - compress_rate: 108.17
    + images/117.jpeg - raw_size: 108900 - webp_size: 59276 - compress_rate: 54.43
    - images/118.jpeg - raw_size: 107464 - webp_size: 128738 - compress_rate: 119.80
    + images/118.jpeg - raw_size: 107464 - webp_size: 69992 - compress_rate: 65.13
    - images/119.jpeg - raw_size: 107259 - webp_size: 113886 - compress_rate: 106.18
    + images/119.jpeg - raw_size: 107259 - webp_size: 81064 - compress_rate: 75.58
    - images/12.jpeg - raw_size: 266707 - webp_size: 293088 - compress_rate: 109.89
    + images/12.jpeg - raw_size: 266707 - webp_size: 242818 - compress_rate: 91.04
    - images/120.jpeg - raw_size: 102135 - webp_size: 106296 - compress_rate: 104.07
    + images/120.jpeg - raw_size: 102135 - webp_size: 75838 - compress_rate: 74.25
    - images/121.jpg - raw_size: 98568 - webp_size: 132962 - compress_rate: 134.89
    + images/121.jpg - raw_size: 98568 - webp_size: 92814 - compress_rate: 94.16
    - images/122.jpg - raw_size: 96874 - webp_size: 103910 - compress_rate: 107.26
    + images/122.jpg - raw_size: 96874 - webp_size: 83260 - compress_rate: 85.95
    - images/123.jpeg - raw_size: 93606 - webp_size: 98412 - compress_rate: 105.13
    + images/123.jpeg - raw_size: 93606 - webp_size: 53170 - compress_rate: 56.80
    - images/124.jpeg - raw_size: 87842 - webp_size: 94278 - compress_rate: 107.33
    + images/124.jpeg - raw_size: 87842 - webp_size: 67102 - compress_rate: 76.39
    - images/125.jpeg - raw_size: 87546 - webp_size: 92634 - compress_rate: 105.81
    + images/125.jpeg - raw_size: 87546 - webp_size: 67094 - compress_rate: 76.64
    - images/126.jpeg - raw_size: 81315 - webp_size: 87164 - compress_rate: 107.19
    + images/126.jpeg - raw_size: 81315 - webp_size: 68368 - compress_rate: 84.08
    - images/127.jpeg - raw_size: 81725 - webp_size: 86390 - compress_rate: 105.71
    + images/127.jpeg - raw_size: 81725 - webp_size: 70340 - compress_rate: 86.07
    - images/128.jpeg - raw_size: 75239 - webp_size: 77416 - compress_rate: 102.89
    + images/128.jpeg - raw_size: 75239 - webp_size: 58368 - compress_rate: 77.58
    - images/129.jpeg - raw_size: 68574 - webp_size: 74582 - compress_rate: 108.76
    + images/129.jpeg - raw_size: 68574 - webp_size: 56140 - compress_rate: 81.87
    - images/13.jpeg - raw_size: 266605 - webp_size: 290308 - compress_rate: 108.89
    + images/13.jpeg - raw_size: 266605 - webp_size: 254940 - compress_rate: 95.62
    - images/130.jpg - raw_size: 67296 - webp_size: 73986 - compress_rate: 109.94
    + images/130.jpg - raw_size: 67296 - webp_size: 52508 - compress_rate: 78.03
    - images/131.jpg - raw_size: 62297 - webp_size: 65358 - compress_rate: 104.91
    + images/131.jpg - raw_size: 62297 - webp_size: 47760 - compress_rate: 76.67
    - images/132.jpeg - raw_size: 61121 - webp_size: 65518 - compress_rate: 107.19
    + images/132.jpeg - raw_size: 61121 - webp_size: 46230 - compress_rate: 75.64
    - images/133.jpg - raw_size: 57112 - webp_size: 56408 - compress_rate: 98.77
    + images/133.jpg - raw_size: 57112 - webp_size: 43288 - compress_rate: 75.79
    - images/134.jpeg - raw_size: 54623 - webp_size: 55002 - compress_rate: 100.69
    + images/134.jpeg - raw_size: 54623 - webp_size: 39918 - compress_rate: 73.08
    - images/135.jpg - raw_size: 52984 - webp_size: 54956 - compress_rate: 103.72
    + images/135.jpg - raw_size: 52984 - webp_size: 39924 - compress_rate: 75.35
    - images/136.png - raw_size: 46794 - webp_size: 46672 - compress_rate: 99.74
    + images/136.png - raw_size: 46794 - webp_size: 29760 - compress_rate: 63.60
    - images/137.png - raw_size: 44731 - webp_size: 45452 - compress_rate: 101.61
    + images/137.png - raw_size: 44731 - webp_size: 27816 - compress_rate: 62.19
    - images/138.jpg - raw_size: 40653 - webp_size: 41590 - compress_rate: 102.30
    + images/138.jpg - raw_size: 40653 - webp_size: 26658 - compress_rate: 65.57
    - images/139.jpeg - raw_size: 39760 - webp_size: 40498 - compress_rate: 101.86
    + images/139.jpeg - raw_size: 39760 - webp_size: 27462 - compress_rate: 69.07
    - images/14.jpeg - raw_size: 265914 - webp_size: 290680 - compress_rate: 109.31
    + images/14.jpeg - raw_size: 265914 - webp_size: 248808 - compress_rate: 93.57
    - images/140.png - raw_size: 39903 - webp_size: 39334 - compress_rate: 98.57
    + images/140.png - raw_size: 39903 - webp_size: 23664 - compress_rate: 59.30
    - images/141.png - raw_size: 38234 - webp_size: 39438 - compress_rate: 103.15
    + images/141.png - raw_size: 38234 - webp_size: 24634 - compress_rate: 64.43
    - images/142.png - raw_size: 38907 - webp_size: 38740 - compress_rate: 99.57
    + images/142.png - raw_size: 38907 - webp_size: 22752 - compress_rate: 58.48
    - images/143.jpeg - raw_size: 36159 - webp_size: 36220 - compress_rate: 100.17
    + images/143.jpeg - raw_size: 36159 - webp_size: 24106 - compress_rate: 66.67
    - images/144.jpg - raw_size: 34821 - webp_size: 36366 - compress_rate: 104.44
    + images/144.jpg - raw_size: 34821 - webp_size: 22698 - compress_rate: 65.18
    - images/145 - raw_size: 35274 - webp_size: 35492 - compress_rate: 100.62
    + images/145 - raw_size: 35274 - webp_size: 18044 - compress_rate: 51.15
    - images/146.png - raw_size: 33084 - webp_size: 33000 - compress_rate: 99.75
    + images/146.png - raw_size: 33084 - webp_size: 28312 - compress_rate: 85.58
    - images/147.jpg - raw_size: 31877 - webp_size: 36022 - compress_rate: 113.00
    + images/147.jpg - raw_size: 31877 - webp_size: 32812 - compress_rate: 102.93
    - images/148 - raw_size: 32122 - webp_size: 32388 - compress_rate: 100.83
    + images/148 - raw_size: 32122 - webp_size: 28552 - compress_rate: 88.89
    - images/149.png - raw_size: 31779 - webp_size: 32188 - compress_rate: 101.29
    + images/149.png - raw_size: 31779 - webp_size: 26962 - compress_rate: 84.84
    - images/15.jpg - raw_size: 265061 - webp_size: 307310 - compress_rate: 115.94
    + images/15.jpg - raw_size: 265061 - webp_size: 157294 - compress_rate: 59.34
    - images/150.png - raw_size: 30638 - webp_size: 30720 - compress_rate: 100.27
    + images/150.png - raw_size: 30638 - webp_size: 25536 - compress_rate: 83.35
    - images/151.png - raw_size: 29983 - webp_size: 29988 - compress_rate: 100.02
    + images/151.png - raw_size: 29983 - webp_size: 24526 - compress_rate: 81.80
    - images/152 - raw_size: 29430 - webp_size: 30276 - compress_rate: 102.87
    + images/152 - raw_size: 29430 - webp_size: 26464 - compress_rate: 89.92
    - images/153.png - raw_size: 28601 - webp_size: 28368 - compress_rate: 99.19
    + images/153.png - raw_size: 28601 - webp_size: 22918 - compress_rate: 80.13
    - images/154.png - raw_size: 27591 - webp_size: 27302 - compress_rate: 98.95
    + images/154.png - raw_size: 27591 - webp_size: 21758 - compress_rate: 78.86
    - images/155.png - raw_size: 27623 - webp_size: 27342 - compress_rate: 98.98
    + images/155.png - raw_size: 27623 - webp_size: 22202 - compress_rate: 80.38
    - images/156.jpg - raw_size: 25453 - webp_size: 24740 - compress_rate: 97.20
    + images/156.jpg - raw_size: 25453 - webp_size: 16354 - compress_rate: 64.25
    - images/157.jpg - raw_size: 23502 - webp_size: 22862 - compress_rate: 97.28
    + images/157.jpg - raw_size: 23502 - webp_size: 16308 - compress_rate: 69.39
    - images/158.jpeg - raw_size: 21820 - webp_size: 22652 - compress_rate: 103.81
    + images/158.jpeg - raw_size: 21820 - webp_size: 17102 - compress_rate: 78.38
    - images/159.jpg - raw_size: 21918 - webp_size: 22346 - compress_rate: 101.95
    + images/159.jpg - raw_size: 21918 - webp_size: 14932 - compress_rate: 68.13
    - images/16.jpeg - raw_size: 263801 - webp_size: 294002 - compress_rate: 111.45
    + images/16.jpeg - raw_size: 263801 - webp_size: 230988 - compress_rate: 87.56
    - images/160.png - raw_size: 21952 - webp_size: 21572 - compress_rate: 98.27
    + images/160.png - raw_size: 21952 - webp_size: 15426 - compress_rate: 70.27
    - images/161.jpg - raw_size: 21809 - webp_size: 21522 - compress_rate: 98.68
    + images/161.jpg - raw_size: 21809 - webp_size: 16670 - compress_rate: 76.44
    - images/162.jpg - raw_size: 22254 - webp_size: 21596 - compress_rate: 97.04
    + images/162.jpg - raw_size: 22254 - webp_size: 15560 - compress_rate: 69.92
    - images/163.jpeg - raw_size: 21020 - webp_size: 23048 - compress_rate: 109.65
    + images/163.jpeg - raw_size: 21020 - webp_size: 18044 - compress_rate: 85.84
    - images/164.jpg - raw_size: 21347 - webp_size: 20804 - compress_rate: 97.46
    + images/164.jpg - raw_size: 21347 - webp_size: 13754 - compress_rate: 64.43
    - images/165.jpg - raw_size: 20987 - webp_size: 20596 - compress_rate: 98.14
    + images/165.jpg - raw_size: 20987 - webp_size: 13240 - compress_rate: 63.09
    - images/166.jpg - raw_size: 21255 - webp_size: 20534 - compress_rate: 96.61
    + images/166.jpg - raw_size: 21255 - webp_size: 15136 - compress_rate: 71.21
    - images/167.jpg - raw_size: 19915 - webp_size: 20022 - compress_rate: 100.54
    + images/167.jpg - raw_size: 19915 - webp_size: 14018 - compress_rate: 70.39
    - images/168.jpg - raw_size: 20453 - webp_size: 19768 - compress_rate: 96.65
    + images/168.jpg - raw_size: 20453 - webp_size: 13206 - compress_rate: 64.57
    - images/169.jpeg - raw_size: 19398 - webp_size: 20102 - compress_rate: 103.63
    + images/169.jpeg - raw_size: 19398 - webp_size: 15294 - compress_rate: 78.84
    - images/17.jpeg - raw_size: 261667 - webp_size: 300256 - compress_rate: 114.75
    + images/17.jpeg - raw_size: 261667 - webp_size: 263928 - compress_rate: 100.86
    - images/170.jpg - raw_size: 19328 - webp_size: 18496 - compress_rate: 95.70
    + images/170.jpg - raw_size: 19328 - webp_size: 11256 - compress_rate: 58.24
    - images/171.jpg - raw_size: 17796 - webp_size: 26916 - compress_rate: 151.25
    + images/171.jpg - raw_size: 17796 - webp_size: 23052 - compress_rate: 129.53
    - images/172.jpeg - raw_size: 17929 - webp_size: 18584 - compress_rate: 103.65
    + images/172.jpeg - raw_size: 17929 - webp_size: 12550 - compress_rate: 70.00
    - images/173.jpg - raw_size: 18093 - webp_size: 17968 - compress_rate: 99.31
    + images/173.jpg - raw_size: 18093 - webp_size: 11560 - compress_rate: 63.89
    - images/174.jpeg - raw_size: 18016 - webp_size: 18104 - compress_rate: 100.49
    + images/174.jpeg - raw_size: 18016 - webp_size: 12818 - compress_rate: 71.15
    - images/175.jpeg - raw_size: 17155 - webp_size: 18866 - compress_rate: 109.97
    + images/175.jpeg - raw_size: 17155 - webp_size: 13208 - compress_rate: 76.99
    - images/176.jpeg - raw_size: 17291 - webp_size: 19230 - compress_rate: 111.21
    + images/176.jpeg - raw_size: 17291 - webp_size: 13998 - compress_rate: 80.96
    - images/177.jpg - raw_size: 17183 - webp_size: 16748 - compress_rate: 97.47
    + images/177.jpg - raw_size: 17183 - webp_size: 9864 - compress_rate: 57.41
    - images/178.jpg - raw_size: 17361 - webp_size: 17302 - compress_rate: 99.66
    + images/178.jpg - raw_size: 17361 - webp_size: 11196 - compress_rate: 64.49
    - images/179.jpg - raw_size: 15369 - webp_size: 21102 - compress_rate: 137.30
    + images/179.jpg - raw_size: 15369 - webp_size: 18306 - compress_rate: 119.11
    - images/18.jpeg - raw_size: 259472 - webp_size: 281560 - compress_rate: 108.51
    + images/18.jpeg - raw_size: 259472 - webp_size: 248996 - compress_rate: 95.96
    - images/180.jpg - raw_size: 16107 - webp_size: 15728 - compress_rate: 97.65
    + images/180.jpg - raw_size: 16107 - webp_size: 9546 - compress_rate: 59.27
    - images/181.jpg - raw_size: 16233 - webp_size: 15704 - compress_rate: 96.74
    + images/181.jpg - raw_size: 16233 - webp_size: 10674 - compress_rate: 65.75
    - images/182.jpeg - raw_size: 15905 - webp_size: 16358 - compress_rate: 102.85
    + images/182.jpeg - raw_size: 15905 - webp_size: 12076 - compress_rate: 75.93
    - images/183.jpeg - raw_size: 15321 - webp_size: 15508 - compress_rate: 101.22
    + images/183.jpeg - raw_size: 15321 - webp_size: 11016 - compress_rate: 71.90
    - images/184.jpg - raw_size: 15230 - webp_size: 14858 - compress_rate: 97.56
    + images/184.jpg - raw_size: 15230 - webp_size: 10016 - compress_rate: 65.76
    - images/185.jpg - raw_size: 13828 - webp_size: 20552 - compress_rate: 148.63
    + images/185.jpg - raw_size: 13828 - webp_size: 15650 - compress_rate: 113.18
    - images/186.jpg - raw_size: 13862 - webp_size: 18856 - compress_rate: 136.03
    + images/186.jpg - raw_size: 13862 - webp_size: 14418 - compress_rate: 104.01
    - images/187.jpg - raw_size: 13466 - webp_size: 17938 - compress_rate: 133.21
    + images/187.jpg - raw_size: 13466 - webp_size: 12698 - compress_rate: 94.30
    - images/188.jpg - raw_size: 13464 - webp_size: 17910 - compress_rate: 133.02
    + images/188.jpg - raw_size: 13464 - webp_size: 14676 - compress_rate: 109.00
    - images/189.jpeg - raw_size: 14019 - webp_size: 16402 - compress_rate: 117.00
    + images/189.jpeg - raw_size: 14019 - webp_size: 14388 - compress_rate: 102.63
    - images/19.jpeg - raw_size: 258612 - webp_size: 290086 - compress_rate: 112.17
    + images/19.jpeg - raw_size: 258612 - webp_size: 247868 - compress_rate: 95.85
    - images/190.jpeg - raw_size: 13678 - webp_size: 14200 - compress_rate: 103.82
    + images/190.jpeg - raw_size: 13678 - webp_size: 9846 - compress_rate: 71.98
    - images/191.jpg - raw_size: 12737 - webp_size: 16864 - compress_rate: 132.40
    + images/191.jpg - raw_size: 12737 - webp_size: 13258 - compress_rate: 104.09
    - images/192.jpeg - raw_size: 12620 - webp_size: 12302 - compress_rate: 97.48
    + images/192.jpeg - raw_size: 12620 - webp_size: 8084 - compress_rate: 64.06
    - images/193.jpg - raw_size: 12091 - webp_size: 17442 - compress_rate: 144.26
    + images/193.jpg - raw_size: 12091 - webp_size: 12832 - compress_rate: 106.13
    - images/194.jpg - raw_size: 12263 - webp_size: 17118 - compress_rate: 139.59
    + images/194.jpg - raw_size: 12263 - webp_size: 13284 - compress_rate: 108.33
    - images/195.jpg - raw_size: 11585 - webp_size: 15614 - compress_rate: 134.78
    + images/195.jpg - raw_size: 11585 - webp_size: 12072 - compress_rate: 104.20
    - images/196.jpg - raw_size: 11386 - webp_size: 15862 - compress_rate: 139.31
    + images/196.jpg - raw_size: 11386 - webp_size: 12724 - compress_rate: 111.75
    - images/197.jpeg - raw_size: 12021 - webp_size: 13160 - compress_rate: 109.48
    + images/197.jpeg - raw_size: 12021 - webp_size: 8722 - compress_rate: 72.56
    - images/198.jpeg - raw_size: 11714 - webp_size: 11560 - compress_rate: 98.69
    + images/198.jpeg - raw_size: 11714 - webp_size: 7922 - compress_rate: 67.63
    - images/199.jpg - raw_size: 10954 - webp_size: 15794 - compress_rate: 144.18
    + images/199.jpg - raw_size: 10954 - webp_size: 10966 - compress_rate: 100.11
    - images/2.jpeg - raw_size: 297847 - webp_size: 335008 - compress_rate: 112.48
    + images/2.jpeg - raw_size: 297847 - webp_size: 304540 - compress_rate: 102.25
    - images/20.jpeg - raw_size: 256709 - webp_size: 290424 - compress_rate: 113.13
    + images/20.jpeg - raw_size: 256709 - webp_size: 253928 - compress_rate: 98.92
    - images/200.jpg - raw_size: 10854 - webp_size: 13884 - compress_rate: 127.92
    + images/200.jpg - raw_size: 10854 - webp_size: 11034 - compress_rate: 101.66
    - images/201.jpg - raw_size: 10679 - webp_size: 10752 - compress_rate: 100.68
    + images/201.jpg - raw_size: 10679 - webp_size: 7760 - compress_rate: 72.67
    - images/202.png - raw_size: 9987 - webp_size: 9522 - compress_rate: 95.34
    + images/202.png - raw_size: 9987 - webp_size: 7480 - compress_rate: 74.90
    - images/203.jpg - raw_size: 10057 - webp_size: 9746 - compress_rate: 96.91
    + images/203.jpg - raw_size: 10057 - webp_size: 7320 - compress_rate: 72.79
    - images/204.jpg - raw_size: 9702 - webp_size: 9326 - compress_rate: 96.12
    + images/204.jpg - raw_size: 9702 - webp_size: 5858 - compress_rate: 60.38
    - images/205.jpg - raw_size: 8702 - webp_size: 11486 - compress_rate: 131.99
    + images/205.jpg - raw_size: 8702 - webp_size: 7996 - compress_rate: 91.89
    - images/206.jpg - raw_size: 8727 - webp_size: 8350 - compress_rate: 95.68
    + images/206.jpg - raw_size: 8727 - webp_size: 6530 - compress_rate: 74.83
    - images/207.jpg - raw_size: 8179 - webp_size: 7692 - compress_rate: 94.05
    + images/207.jpg - raw_size: 8179 - webp_size: 4940 - compress_rate: 60.40
    - images/208.jpg - raw_size: 8125 - webp_size: 7486 - compress_rate: 92.14
    + images/208.jpg - raw_size: 8125 - webp_size: 5062 - compress_rate: 62.30
    - images/209.jpg - raw_size: 7844 - webp_size: 7176 - compress_rate: 91.48
    + images/209.jpg - raw_size: 7844 - webp_size: 4324 - compress_rate: 55.12
    - images/21.jpeg - raw_size: 254974 - webp_size: 284724 - compress_rate: 111.67
    + images/21.jpeg - raw_size: 254974 - webp_size: 235264 - compress_rate: 92.27
    - images/210.jpg - raw_size: 6507 - webp_size: 8778 - compress_rate: 134.90
    + images/210.jpg - raw_size: 6507 - webp_size: 5436 - compress_rate: 83.54
    - images/211.jpg - raw_size: 7114 - webp_size: 7364 - compress_rate: 103.51
    + images/211.jpg - raw_size: 7114 - webp_size: 5170 - compress_rate: 72.67
    - images/212.jpeg - raw_size: 6738 - webp_size: 7188 - compress_rate: 106.68
    + images/212.jpeg - raw_size: 6738 - webp_size: 3860 - compress_rate: 57.29
    - images/213.jpg - raw_size: 6136 - webp_size: 5922 - compress_rate: 96.51
    + images/213.jpg - raw_size: 6136 - webp_size: 4094 - compress_rate: 66.72
    - images/214.jpeg - raw_size: 2559 - webp_size: 2062 - compress_rate: 80.58
    + images/214.jpeg - raw_size: 2559 - webp_size: 1404 - compress_rate: 54.87
    - images/215.jpeg - raw_size: 2574 - webp_size: 2072 - compress_rate: 80.50
    + images/215.jpeg - raw_size: 2574 - webp_size: 1418 - compress_rate: 55.09
    - images/216.jpeg - raw_size: 2553 - webp_size: 2070 - compress_rate: 81.08
    + images/216.jpeg - raw_size: 2553 - webp_size: 1420 - compress_rate: 55.62
    - images/22.jpeg - raw_size: 254648 - webp_size: 274190 - compress_rate: 107.67
    + images/22.jpeg - raw_size: 254648 - webp_size: 237702 - compress_rate: 93.35
    - images/23.jpeg - raw_size: 253784 - webp_size: 278218 - compress_rate: 109.63
    + images/23.jpeg - raw_size: 253784 - webp_size: 234534 - compress_rate: 92.41
    - images/24.jpeg - raw_size: 249819 - webp_size: 257566 - compress_rate: 103.10
    + images/24.jpeg - raw_size: 249819 - webp_size: 202330 - compress_rate: 80.99
    - images/25.jpeg - raw_size: 248033 - webp_size: 266978 - compress_rate: 107.64
    + images/25.jpeg - raw_size: 248033 - webp_size: 229882 - compress_rate: 92.68
    - images/26.jpeg - raw_size: 247258 - webp_size: 294728 - compress_rate: 119.20
    + images/26.jpeg - raw_size: 247258 - webp_size: 231762 - compress_rate: 93.73
    - images/27.jpeg - raw_size: 242369 - webp_size: 271172 - compress_rate: 111.88
    + images/27.jpeg - raw_size: 242369 - webp_size: 217866 - compress_rate: 89.89
    - images/28.jpeg - raw_size: 242484 - webp_size: 260596 - compress_rate: 107.47
    + images/28.jpeg - raw_size: 242484 - webp_size: 228068 - compress_rate: 94.05
    - images/29.jpeg - raw_size: 240954 - webp_size: 259644 - compress_rate: 107.76
    + images/29.jpeg - raw_size: 240954 - webp_size: 231572 - compress_rate: 96.11
    - images/3.jpeg - raw_size: 294620 - webp_size: 318750 - compress_rate: 108.19
    + images/3.jpeg - raw_size: 294620 - webp_size: 266384 - compress_rate: 90.42
    - images/30.jpeg - raw_size: 239823 - webp_size: 258152 - compress_rate: 107.64
    + images/30.jpeg - raw_size: 239823 - webp_size: 230648 - compress_rate: 96.17
    - images/31.jpeg - raw_size: 239565 - webp_size: 273384 - compress_rate: 114.12
    + images/31.jpeg - raw_size: 239565 - webp_size: 214176 - compress_rate: 89.40
    - images/32.jpeg - raw_size: 234712 - webp_size: 254944 - compress_rate: 108.62
    + images/32.jpeg - raw_size: 234712 - webp_size: 231400 - compress_rate: 98.59
    - images/33.jpeg - raw_size: 234619 - webp_size: 248282 - compress_rate: 105.82
    + images/33.jpeg - raw_size: 234619 - webp_size: 205726 - compress_rate: 87.69
    - images/34.jpeg - raw_size: 227425 - webp_size: 257194 - compress_rate: 113.09
    + images/34.jpeg - raw_size: 227425 - webp_size: 220766 - compress_rate: 97.07
    - images/35.jpeg - raw_size: 228345 - webp_size: 235988 - compress_rate: 103.35
    + images/35.jpeg - raw_size: 228345 - webp_size: 195180 - compress_rate: 85.48
    - images/36.jpeg - raw_size: 226289 - webp_size: 253980 - compress_rate: 112.24
    + images/36.jpeg - raw_size: 226289 - webp_size: 201792 - compress_rate: 89.17
    - images/37.jpeg - raw_size: 225245 - webp_size: 257676 - compress_rate: 114.40
    + images/37.jpeg - raw_size: 225245 - webp_size: 214656 - compress_rate: 95.30
    - images/38.jpeg - raw_size: 224754 - webp_size: 243142 - compress_rate: 108.18
    + images/38.jpeg - raw_size: 224754 - webp_size: 209540 - compress_rate: 93.23
    - images/39.jpeg - raw_size: 224726 - webp_size: 228860 - compress_rate: 101.84
    + images/39.jpeg - raw_size: 224726 - webp_size: 203356 - compress_rate: 90.49
    - images/4.jpeg - raw_size: 292338 - webp_size: 298872 - compress_rate: 102.24
    + images/4.jpeg - raw_size: 292338 - webp_size: 252224 - compress_rate: 86.28
    - images/40.jpeg - raw_size: 223644 - webp_size: 293454 - compress_rate: 131.21
    + images/40.jpeg - raw_size: 223644 - webp_size: 252726 - compress_rate: 113.00
    - images/41.jpeg - raw_size: 223487 - webp_size: 238058 - compress_rate: 106.52
    + images/41.jpeg - raw_size: 223487 - webp_size: 198102 - compress_rate: 88.64
    - images/42.jpeg - raw_size: 223518 - webp_size: 230722 - compress_rate: 103.22
    + images/42.jpeg - raw_size: 223518 - webp_size: 191290 - compress_rate: 85.58
    - images/43.jpeg - raw_size: 222852 - webp_size: 241302 - compress_rate: 108.28
    + images/43.jpeg - raw_size: 222852 - webp_size: 206892 - compress_rate: 92.84
    - images/44.jpeg - raw_size: 222158 - webp_size: 231476 - compress_rate: 104.19
    + images/44.jpeg - raw_size: 222158 - webp_size: 187736 - compress_rate: 84.51
    - images/45.jpeg - raw_size: 215550 - webp_size: 221094 - compress_rate: 102.57
    + images/45.jpeg - raw_size: 215550 - webp_size: 173758 - compress_rate: 80.61
    - images/46.jpeg - raw_size: 214415 - webp_size: 225810 - compress_rate: 105.31
    + images/46.jpeg - raw_size: 214415 - webp_size: 177994 - compress_rate: 83.01
    - images/47.jpeg - raw_size: 213485 - webp_size: 230808 - compress_rate: 108.11
    + images/47.jpeg - raw_size: 213485 - webp_size: 191098 - compress_rate: 89.51
    - images/48.jpeg - raw_size: 212034 - webp_size: 226948 - compress_rate: 107.03
    + images/48.jpeg - raw_size: 212034 - webp_size: 177432 - compress_rate: 83.68
    - images/49.jpeg - raw_size: 211980 - webp_size: 224086 - compress_rate: 105.71
    + images/49.jpeg - raw_size: 211980 - webp_size: 180502 - compress_rate: 85.15
    - images/5.jpeg - raw_size: 288430 - webp_size: 322682 - compress_rate: 111.88
    + images/5.jpeg - raw_size: 288430 - webp_size: 265382 - compress_rate: 92.01
    - images/50.jpeg - raw_size: 211470 - webp_size: 218950 - compress_rate: 103.54
    + images/50.jpeg - raw_size: 211470 - webp_size: 182730 - compress_rate: 86.41
    - images/51.jpeg - raw_size: 210617 - webp_size: 225478 - compress_rate: 107.06
    + images/51.jpeg - raw_size: 210617 - webp_size: 192932 - compress_rate: 91.60
    - images/52.jpeg - raw_size: 210154 - webp_size: 218372 - compress_rate: 103.91
    + images/52.jpeg - raw_size: 210154 - webp_size: 183374 - compress_rate: 87.26
    - images/53.jpeg - raw_size: 209173 - webp_size: 222414 - compress_rate: 106.33
    + images/53.jpeg - raw_size: 209173 - webp_size: 190856 - compress_rate: 91.24
    - images/54.jpeg - raw_size: 209348 - webp_size: 221528 - compress_rate: 105.82
    + images/54.jpeg - raw_size: 209348 - webp_size: 189738 - compress_rate: 90.63
    - images/55.jpeg - raw_size: 208979 - webp_size: 220700 - compress_rate: 105.61
    + images/55.jpeg - raw_size: 208979 - webp_size: 172928 - compress_rate: 82.75
    - images/56.jpeg - raw_size: 209681 - webp_size: 216882 - compress_rate: 103.43
    + images/56.jpeg - raw_size: 209681 - webp_size: 180822 - compress_rate: 86.24
    - images/57.jpeg - raw_size: 209878 - webp_size: 216056 - compress_rate: 102.94
    + images/57.jpeg - raw_size: 209878 - webp_size: 180918 - compress_rate: 86.20
    - images/58.jpeg - raw_size: 207900 - webp_size: 222142 - compress_rate: 106.85
    + images/58.jpeg - raw_size: 207900 - webp_size: 190976 - compress_rate: 91.86
    - images/59.jpeg - raw_size: 208616 - webp_size: 219928 - compress_rate: 105.42
    + images/59.jpeg - raw_size: 208616 - webp_size: 173732 - compress_rate: 83.28
    - images/6.jpeg - raw_size: 284054 - webp_size: 336464 - compress_rate: 118.45
    + images/6.jpeg - raw_size: 284054 - webp_size: 305356 - compress_rate: 107.50
    - images/60.jpeg - raw_size: 208085 - webp_size: 215398 - compress_rate: 103.51
    + images/60.jpeg - raw_size: 208085 - webp_size: 180840 - compress_rate: 86.91
    - images/61.jpeg - raw_size: 207741 - webp_size: 218142 - compress_rate: 105.01
    + images/61.jpeg - raw_size: 207741 - webp_size: 187324 - compress_rate: 90.17
    - images/62.jpeg - raw_size: 207207 - webp_size: 213988 - compress_rate: 103.27
    + images/62.jpeg - raw_size: 207207 - webp_size: 176580 - compress_rate: 85.22
    - images/63.jpeg - raw_size: 207378 - webp_size: 211710 - compress_rate: 102.09
    + images/63.jpeg - raw_size: 207378 - webp_size: 175580 - compress_rate: 84.67
    - images/64.jpeg - raw_size: 206363 - webp_size: 211314 - compress_rate: 102.40
    + images/64.jpeg - raw_size: 206363 - webp_size: 172626 - compress_rate: 83.65
    - images/65.jpeg - raw_size: 205403 - webp_size: 248340 - compress_rate: 120.90
    + images/65.jpeg - raw_size: 205403 - webp_size: 189980 - compress_rate: 92.49
    - images/66.jpeg - raw_size: 205596 - webp_size: 221860 - compress_rate: 107.91
    + images/66.jpeg - raw_size: 205596 - webp_size: 177868 - compress_rate: 86.51
    - images/67.jpeg - raw_size: 204866 - webp_size: 219906 - compress_rate: 107.34
    + images/67.jpeg - raw_size: 204866 - webp_size: 187930 - compress_rate: 91.73
    - images/68.jpeg - raw_size: 204206 - webp_size: 212960 - compress_rate: 104.29
    + images/68.jpeg - raw_size: 204206 - webp_size: 183464 - compress_rate: 89.84
    - images/69.jpeg - raw_size: 204454 - webp_size: 209738 - compress_rate: 102.58
    + images/69.jpeg - raw_size: 204454 - webp_size: 174394 - compress_rate: 85.30
    - images/7.jpeg - raw_size: 280407 - webp_size: 330456 - compress_rate: 117.85
    + images/7.jpeg - raw_size: 280407 - webp_size: 301778 - compress_rate: 107.62
    - images/70.jpeg - raw_size: 202759 - webp_size: 207740 - compress_rate: 102.46
    + images/70.jpeg - raw_size: 202759 - webp_size: 158040 - compress_rate: 77.94
    - images/71.jpeg - raw_size: 203697 - webp_size: 205270 - compress_rate: 100.77
    + images/71.jpeg - raw_size: 203697 - webp_size: 156382 - compress_rate: 76.77
    - images/72.jpeg - raw_size: 201752 - webp_size: 216440 - compress_rate: 107.28
    + images/72.jpeg - raw_size: 201752 - webp_size: 184310 - compress_rate: 91.35
    - images/73.jpeg - raw_size: 200511 - webp_size: 233932 - compress_rate: 116.67
    + images/73.jpeg - raw_size: 200511 - webp_size: 207566 - compress_rate: 103.52
    - images/74.jpeg - raw_size: 198903 - webp_size: 200178 - compress_rate: 100.64
    + images/74.jpeg - raw_size: 198903 - webp_size: 144950 - compress_rate: 72.87
    - images/75.jpeg - raw_size: 197543 - webp_size: 216126 - compress_rate: 109.41
    + images/75.jpeg - raw_size: 197543 - webp_size: 179638 - compress_rate: 90.94
    - images/76.jpeg - raw_size: 195824 - webp_size: 214124 - compress_rate: 109.35
    + images/76.jpeg - raw_size: 195824 - webp_size: 177840 - compress_rate: 90.82
    - images/77.jpeg - raw_size: 194642 - webp_size: 208228 - compress_rate: 106.98
    + images/77.jpeg - raw_size: 194642 - webp_size: 173914 - compress_rate: 89.35
    - images/78.jpeg - raw_size: 194654 - webp_size: 207240 - compress_rate: 106.47
    + images/78.jpeg - raw_size: 194654 - webp_size: 174136 - compress_rate: 89.46
    - images/79.jpeg - raw_size: 195052 - webp_size: 205572 - compress_rate: 105.39
    + images/79.jpeg - raw_size: 195052 - webp_size: 169606 - compress_rate: 86.95
    - images/8.jpeg - raw_size: 280346 - webp_size: 310288 - compress_rate: 110.68
    + images/8.jpeg - raw_size: 280346 - webp_size: 255720 - compress_rate: 91.22
    - images/80.jpeg - raw_size: 193529 - webp_size: 204854 - compress_rate: 105.85
    + images/80.jpeg - raw_size: 193529 - webp_size: 171488 - compress_rate: 88.61
    - images/81.jpeg - raw_size: 193159 - webp_size: 203406 - compress_rate: 105.30
    + images/81.jpeg - raw_size: 193159 - webp_size: 165834 - compress_rate: 85.85
    - images/82.jpeg - raw_size: 191890 - webp_size: 193732 - compress_rate: 100.96
    + images/82.jpeg - raw_size: 191890 - webp_size: 146352 - compress_rate: 76.27
    - images/83.jpeg - raw_size: 190356 - webp_size: 198330 - compress_rate: 104.19
    + images/83.jpeg - raw_size: 190356 - webp_size: 162992 - compress_rate: 85.62
    - images/84.jpeg - raw_size: 190275 - webp_size: 197508 - compress_rate: 103.80
    + images/84.jpeg - raw_size: 190275 - webp_size: 156704 - compress_rate: 82.36
    - images/85.jpeg - raw_size: 189938 - webp_size: 195238 - compress_rate: 102.79
    + images/85.jpeg - raw_size: 189938 - webp_size: 159116 - compress_rate: 83.77
    - images/86.jpeg - raw_size: 189224 - webp_size: 191130 - compress_rate: 101.01
    + images/86.jpeg - raw_size: 189224 - webp_size: 145054 - compress_rate: 76.66
    - images/87.jpeg - raw_size: 187442 - webp_size: 193812 - compress_rate: 103.40
    + images/87.jpeg - raw_size: 187442 - webp_size: 154704 - compress_rate: 82.53
    - images/88.jpeg - raw_size: 188188 - webp_size: 191800 - compress_rate: 101.92
    + images/88.jpeg - raw_size: 188188 - webp_size: 156000 - compress_rate: 82.90
    - images/89.jpeg - raw_size: 187437 - webp_size: 189678 - compress_rate: 101.20
    + images/89.jpeg - raw_size: 187437 - webp_size: 148784 - compress_rate: 79.38
    - images/9.jpeg - raw_size: 278229 - webp_size: 325528 - compress_rate: 117.00
    + images/9.jpeg - raw_size: 278229 - webp_size: 290478 - compress_rate: 104.40
    - images/90.jpeg - raw_size: 186994 - webp_size: 189156 - compress_rate: 101.16
    + images/90.jpeg - raw_size: 186994 - webp_size: 148326 - compress_rate: 79.32
    - images/91.jpeg - raw_size: 184742 - webp_size: 207948 - compress_rate: 112.56
    + images/91.jpeg - raw_size: 184742 - webp_size: 142618 - compress_rate: 77.20
    - images/92.jpeg - raw_size: 183611 - webp_size: 186604 - compress_rate: 101.63
    + images/92.jpeg - raw_size: 183611 - webp_size: 149606 - compress_rate: 81.48
    - images/93.jpeg - raw_size: 172830 - webp_size: 175424 - compress_rate: 101.50
    + images/93.jpeg - raw_size: 172830 - webp_size: 127234 - compress_rate: 73.62
    - images/94.jpeg - raw_size: 171496 - webp_size: 189784 - compress_rate: 110.66
    + images/94.jpeg - raw_size: 171496 - webp_size: 145270 - compress_rate: 84.71
    - images/95.jpeg - raw_size: 171554 - webp_size: 176094 - compress_rate: 102.65
    + images/95.jpeg - raw_size: 171554 - webp_size: 127382 - compress_rate: 74.25
    - images/96.jpeg - raw_size: 168665 - webp_size: 169518 - compress_rate: 100.51
    + images/96.jpeg - raw_size: 168665 - webp_size: 124184 - compress_rate: 73.63
    - images/97.jpg - raw_size: 162928 - webp_size: 163242 - compress_rate: 100.19
    + images/97.jpg - raw_size: 162928 - webp_size: 92658 - compress_rate: 56.87
    - images/98.jpg - raw_size: 162068 - webp_size: 162920 - compress_rate: 100.53
    + images/98.jpg - raw_size: 162068 - webp_size: 91270 - compress_rate: 56.32
    - images/99.jpeg - raw_size: 161352 - webp_size: 162626 - compress_rate: 100.79
    + images/99.jpeg - raw_size: 161352 - webp_size: 118972 - compress_rate: 73.73
    

    Here is the test code

    main.go
    package main
    
    import (
    	"bytes"
    	"fmt"
    	"image"
    	_ "image/png"
    	_ "image/jpeg"
    	"log"
    	"os"
    	"path/filepath"
    
    	"gopkg.in/chai2010/webp.v1"
    	// "github.com/coldnight/webp"
    )
    
    func main() {
    	files, err := filepath.Glob("images/*")
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	for _, fn := range files {
    		img0, size := loadImage(fn)
    		webpSize := encodeWebP(img0)
    		rate := float64(webpSize) / float64(size)
    
    		fmt.Printf("%s - raw_size: %d - webp_size: %d - compress_rate: %.2f\n", fn, size, webpSize, rate * 100)
    	}
    }
    
    func loadImage(path string) (image.Image, int64) {
    	f, err := os.Open(path)
    	if err != nil {
    		log.Fatal(err)
    	}
    	defer f.Close()
    	m, _, err := image.Decode(f)
    	if err != nil {
    		log.Fatal(err)
    	}
    	stat, err := f.Stat()
    	if err != nil {
    		log.Fatal(err)
    	}
    	return m, stat.Size()
    }
    
    func encodeWebP(img image.Image) int {
    	options := &webp.Options{
    		Lossless: false,
    		Quality:  70,
    	}
    
    	buf := new(bytes.Buffer)
    	err := webp.Encode(buf, img, options)
    	if err != nil {
    		log.Fatal(err)
    	}
    	return buf.Len()
    }
    
    opened by coldnight 7
  • Error compiling: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET'

    Error compiling: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET'

    Hi there,

    Thanks for the great package. When installing/building I am receiving an error:

    ../../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)? [-Wxor-used-as-pow]
    ../../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: note: replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning
    

    Not sure how to go about this?

    Many thanks.

    opened by ainsleyclark 5
  • Adding DecodeScaled method.

    Adding DecodeScaled method.

    Uses the advanced decoding API to scale an image while decoding. Saves a lot of memory and CPU time compared to decoding and then resizing.

    Our use case: load original size WEBP -> resize -> encode to JPEG

    Old method: webp.Decode -> nfnt/resize -> jpeg.Encode
    New method: webp.DecodeScaled -> jpeg.Encode

    Benchmarks, with source file 3264x2448px, output file 256x192px:

    BenchmarkMediumOld-8           5     236803936 ns/op
    BenchmarkMediumNew-8          30      48662007 ns/op
    
    opened by jamesbikes 5
  • Works on MacOS, but doesn't work on CoreOS

    Works on MacOS, but doesn't work on CoreOS

    Error when run go build:

     # github.com/chai2010/webp/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc.o: In function `GetPSNR':
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/./enc/picture_psnr.c:60: undefined reference to `log'
     /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc.o: In function `WebPPictureDistortion':
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/./enc/picture_psnr.c:137: undefined reference to `log10'
    /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_dsp_lossless.o: In function `FastSLog2Slow':
     /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/dsp/lossless.c:358: undefined reference to `log'
    /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_dsp_lossless.o: In function `FastLog2Slow':
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/dsp/lossless.c:383: undefined reference to `log'
    /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_frame.o: In function `GetPSNR':
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/frame.c:521: undefined reference to `log10'
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/frame.c:521: undefined reference to `log10'
    /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_picture_csp.o: In function `InitGammaTables':
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/picture_csp.c:110: undefined reference to `pow'
    /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/picture_csp.c:114: undefined reference to `pow'
    /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_quant.o: In function `QualityToCompression':
     /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/quant.c:297: undefined reference to `pow'
     /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_quant.o: In function `VP8SetSegmentParams':
     /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/quant.c:373: undefined reference to `pow'
     /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_webpenc.o: In function `GetPSNR':
     /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/webpenc.c:254: undefined reference to `log10'
    

    OS(CoreOS) Version

     $ cat /etc/issue
     Fedora release 20 (Heisenbug)
    

    Go Version

     $ go version
     go version devel +6acc2dd545b2 Thu Jul 31 12:55:40 2014 +0400 linux/amd64
    

    Libwebp Version 0.4.0

    opened by kamoljan 5
  • hello.go doesn't work

    hello.go doesn't work

    hi @chai2010

    hello.go does not work any longer:

     ➜  src  cd github.com/chai2010/webp
     ➜  webp git:(master) go run hello.go
     width = 400, height = 301
     Metadata: err = webpGetMetadata: not found
    

    Before it was generating output.webp? But it works in my fork

    opened by kamoljan 4
  • Strange compiler errors when CGO_ENABLED=0

    Strange compiler errors when CGO_ENABLED=0

    I'm trying to compile my Go project to one static binary file, without linking to external libraries.

    I am doing so by using this command:

    CGO_ENABLED=0 go get -a -u -ldflags '-s'
    

    This however produces the following errors:

    # github.com/chai2010/webp
    ../github.com/chai2010/webp/reader.go:17: undefined: maxWebpHeaderSize
    ../github.com/chai2010/webp/webp.go:13: undefined: webpGetInfo
    ../github.com/chai2010/webp/webp.go:17: undefined: webpDecodeGray
    ../github.com/chai2010/webp/webp.go:30: undefined: webpDecodeRGB
    ../github.com/chai2010/webp/webp.go:39: undefined: webpDecodeRGBA
    ../github.com/chai2010/webp/webp.go:52: undefined: webpEncodeGray
    ../github.com/chai2010/webp/webp.go:57: undefined: webpEncodeRGB
    ../github.com/chai2010/webp/webp.go:61: undefined: webpEncodeRGBA
    ../github.com/chai2010/webp/webp.go:65: undefined: webpEncodeLosslessGray
    ../github.com/chai2010/webp/webp.go:70: undefined: webpEncodeLosslessRGB
    ../github.com/chai2010/webp/webp.go:70: too many errors
    

    Which is strange, because (for instance) maxWebpHeaderSize is declared in capi.go

    Extra info:

    OS: Debian Jessie
    Kernel 3.2.0-4-amd64
    go version go1.3.2 linux/amd64
    

    Any thoughts?

    Thanks in advance.

    opened by EtienneBruines 3
  • webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments

    webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments

    @chai2010 I am having a strange issue. the webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments

    Here is the code, where I use the webp:

    func Put(w http.ResponseWriter, r *http.Request) {
        if r.Method != "PUT" {
        w.Write(json.Message("ERROR", "Not supported Method"))
        return
    }
    reader, err := r.MultipartReader()
    if err != nil {
        w.Write(json.Message("ERROR", "Client should support multipart/form-data"))
        return
    }
    buf := bytes.NewBufferString("")
    for {
        part, err := reader.NextPart()
        if err == io.EOF {
            break
        }
        if part.FileName() == "" { // if empty skip this iteration
            continue
        }
        _, err = io.Copy(buf, part)
        if err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
            return
        }
    }
    defer r.Body.Close()
    var result json.Result
    var ic iconf
    ic.machine = conf.Image.Machine
    if ic.image, err = webp.Decode(buf); err != nil { // FIXME imagewebpDecodeRGBA: bad arguments
        w.Write(json.Message("ERROR", "Unable to decode your image"+err))
        return
    }
    ic.hash = fmt.Sprintf("%x", sha1.Sum(buf.Bytes()))
    setColor(&ic)
    for _, format := range conf.Image.Format { // jpeg, webp, ...
        for _, screen := range conf.Image.Screen {
            ic.format = format
            ic.ui = screen.Ui
            ic.density = screen.Density
            ic.width = screen.Width
            if ic.fid, err = imgToFile(&ic); err != nil {
                w.Write(json.Message("ERROR", "Unable to create a file"))
                return
            }
            fid := json.Fid{fmt.Sprintf("%s_%s", screen.Density, screen.Ui), ic.fid}
            result.Image = append(result.Image, fid)
        }
    }
    w.Write(json.Message("OK", &result))
    }
    

    I might be messed up with Multipart/form-data. However the same code above works if I send by curl:

    curl -v -XPOST -include --form [email protected]_20140806_000942.jpg http://obrol.shopafter.com:9090/
    

    Is it bug?

    opened by kamoljan 3
  • Add a license

    Add a license

    Hi,

    I'm considering using your package for a project but I can't even consider it due to the lack of a license. Could you add one? Maybe Apache 2.0?

    Thanks

    opened by campoy 2
  • Resize function?

    Resize function?

    is there going to be plan to add resizing function? like the one from the cwebp cwebp -resize <width> <height> apparently resizing using cwebp give a clearer image compared to Lanczos3

    opened by badoet 1
  • Getting compilation issues on linux

    Getting compilation issues on linux

    Installing my package github.paytm.com/paytm/resizer via go get is causing this issue, and then it fails to build.

    github.com/chai2010/webp

    src/github.com/chai2010/webp/writer.go:91: unknown _RGB field 'Pix' in struct literal src/github.com/chai2010/webp/writer.go:92: unknown _RGB field 'Stride' in struct literal src/github.com/chai2010/webp/writer.go:93: unknown _RGB field 'Rect' in struct literal

    opened by qzaidi 1
  • Error for Linux Build

    Error for Linux Build

    Hi! My params for Linux release.

    set GOARCH=amd64 set GOOS=linux go build -ldflags "-s -w"

    Output:

    C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:22:9: undefined: webpGetInfo C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:26:20: undefined: webpDecodeGray C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:39:20: undefined: webpDecodeRGB C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:52:20: undefined: webpDecodeRGBA C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:68:14: undefined: webpDecodeGrayToSize C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:82:14: undefined: webpDecodeRGBToSize C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:96:14: undefined: webpDecodeRGBAToSize C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:109:7: undefined: toGrayImage C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:110:14: undefined: webpEncodeGray C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:119:14: undefined: webpEncodeRGB C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:119:14: too many errors

    Installed TDM-GCC OS Windows 10. Golang version 1.18.4

    How can I compile for Linux? When building for Windows, there are no errors. Thanks!

    question 
    opened by smalloff 3
  • macos 编译出错

    macos 编译出错

    macos 12.4 go 1.18.1 提示如下 github.com/sizeofint/webp-animation

    github.com/sizeofint/webp-animation In file included from ../../repository/go/pkg/mod/github.com/sizeofint/[email protected]/gifdec.go:6: ./webp.hpp:4:10: fatal error: 'webp/encode.h' file not found #include <webp/encode.h> ^~~~~~~~~~~~~~~

    使用make 或者手动命令build 提示均如上所示

    bug 
    opened by libra1010 0
  • Proposal: Support check if Webp is animated

    Proposal: Support check if Webp is animated

    please consider adding an API or put into GetInfo function.

    reference: https://stackoverflow.com/questions/45190469/how-to-identify-whether-webp-image-is-static-or-animated

    opened by huntrist 0
  • Exif Metadata getting set incorrectly

    Exif Metadata getting set incorrectly

    I have a service where I am able to convert jpeg images into webp and render them. The jpeg image that I get has exif information which I extract using goexif library.

    In order to preserve the metadata in the webp image as well, I encode my image with webp encoder and try to set the EXIF data that I extracted earlier, in the encoded image data using the method SetMetadata. This executes successfully and if I try to call GetMetadata after the previous step, I get the correct response i.e all the EXIF tags that were supposed to be set.

    The issue that I face here is, when I try to extract the metadata of the returned webp image using any other online tool, like exif viewer extension on chrome, it errors out with failure to decode exif metadata

    Can someone help here?

    opened by aayush2610 0
  • I want to optimize my website's speed

    I want to optimize my website's speed

    my website address: https://infozone24.com/ I optimized the sites's speed. but My another site called https://bangla.infozone24.com/ is not optimized using the previous formula. I am using wp rocket, Cloudflare,web-p image converter. please help me with some good suggestions.

    opened by rubelpsg 1
Owner
chai2010
《Go语言高级编程》《Go语法树入门》《WebAssembly标准入门》作者
chai2010
BPG decoder for Go (Zero Dependencies).

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa BPG for Go BPG is defined at: http://bellard.o

chai2010 20 Sep 7, 2020
asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

asciigrid asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID. Install go

Ahmet Artu Yildirim 1 Jul 3, 2022
Pbm - Package ppm implements a Portable Bit Map (PBM) image decoder and encoder written in Go

Package pbm import "github.com/slashformotion/pbm" Package pbm implements a Portable Bit Map (PBM) image decoder and encoder. The supported image col

slashformotion 0 Jan 5, 2022
Pure Go encoder/decoder of the QOI image format

QOI - The “Quite OK Image” format for fast, lossless image compression package and small utilities in native Go, quite OK implementation See qoi.h for

Xavier-Frédéric Moulet 58 Nov 12, 2022
Image size analyzer for jpg/png/gif/webp

imgsz Image size analyzer for jpg/png/gif/webp Usage // DecodeSize decodes the dimensions of an image that has // been encoded in a registered format.

源文雨 0 Jan 8, 2022
Go bindings for OpenCV1.1 (Dev/Zero Dependencies).

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa Go bindings for OpenCV1.1 PkgDoc: http://godoc

chai2010 116 Aug 24, 2022
Package qrcode implements a QR Code encoder

A matrix barcode, Arbitrary content may be encoded, with URLs being a popular choice

Rishabh Jain 0 Nov 1, 2021
JPEG-MPO Decoder / Converter Library and CLI Tool

MPO Decoder Library Simple Go JPEG MPO (Multi Picture Object) Decoder - Library and CLI Tool The library and CLI tool contain the ability to convert M

Jesse Donat 10 Sep 26, 2022
Golang implementation of the covid certificate QRCode decoder

Golang implementation of the covid certificates. At the moment it only includes DCC signed data decoding but I've planned to add a lot more of features related to certificates processing.

AlexPresso 5 Sep 22, 2021
Super fast static photo and video gallery generator (written in Go and HTML/CSS/native JS)

fastgallery Fast static photo and video gallery generator Super fast (written in Go and C, concurrent, uses fastest image/video libraries, 4-8 times f

Toni Melisma 26 Oct 20, 2022
Go bindings for audio capture and playback with ALSA and libasound

Go ALSA bindings These bindings allow capture and playback of audio via ALSA using the alsa-lib library. Installation go get github.com/cocoonlife/goa

null 37 Jul 7, 2022
This is old and unmaintained code, ignore it. starfish is a simple, SDL based, 2D graphics and user input library for Go. If you intend to work on it, please fork from the 'devel' branch, not 'master'. Current release: 0.12.0

What is starfish? What starfish is: starfish is a simple 2D graphics and user input library for Go built on SDL. What starfish is not: While it is bui

Gary Talent 12 Jun 4, 2019
darkroom - An image proxy with changeable storage backends and image processing engines with focus on speed and resiliency.

Darkroom - Yet Another Image Proxy Introduction Darkroom combines the storage backend and the image processor and acts as an Image Proxy on your image

Gojek 202 Nov 27, 2022
Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dmitry Chestnykh 1.7k Nov 26, 2022
Fast and secure standalone server for resizing and converting remote images

imgproxy imgproxy is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, sp

imgproxy 6.6k Nov 19, 2022
Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

GISManager Publish Your GIS Data(Vector Data) to PostGIS and Geoserver How to install: go get -v github.com/hishamkaram/gismanager Usage: testdata fol

Hisham waleed karam 48 Sep 26, 2022
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Paul Mach 241 Nov 25, 2022
Real-time Geospatial and Geofencing

Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types

Josh Baker 8.4k Nov 23, 2022
Image processing library and rendering toolkit for Go.

blend Image processing library and rendering toolkit for Go. (WIP) Installation: This library is compatible with Go1. go get github.com/phrozen/blend

Guillermo Estrada 61 Nov 11, 2022