Skip to content

Instantly share code, notes, and snippets.

@kamoljan
Created July 29, 2014 03:45
Show Gist options
  • Save kamoljan/48a71140ac61ed5d98e9 to your computer and use it in GitHub Desktop.
Save kamoljan/48a71140ac61ed5d98e9 to your computer and use it in GitHub Desktop.
package main
import (
"image"
_ "image/jpeg"
_ "image/png"
"log"
"os"
"github.com/chai2010/webp"
)
func main() {
ifile := os.Args[1]
ofile := os.Args[2]
f, err := os.Open(ifile)
defer f.Close()
if err != nil {
log.Fatal("error during open: ", err)
}
img, _, err := image.Decode(f)
if err != nil {
log.Fatal("error decoding file: ", err)
}
out, err := os.Create(ofile)
defer out.Close()
if err != nil {
log.Fatal("Unable to create a file: ", err)
}
webp.Encode(out, img, &webp.Options{true, 90})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment