本文整理汇总了Golang中github.com/chai2010/webp.Decode函数的典型用法代码示例。如果您正苦于以下问题:Golang Decode函数的具体用法?Golang Decode怎么用?Golang Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Decode函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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.Fatal(err)
}
// GetInfo
if width, height, _, err = webp.GetInfo(data); err != nil {
log.Fatal(err)
}
fmt.Printf("width = %d, height = %d\n", width, height)
// Decode webp
m, err := webp.Decode(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
// Encode lossless webp
if err = webp.Encode(&buf, m, &webp.Options{Lossless: true}); err != nil {
log.Fatal(err)
}
if err = ioutil.WriteFile("output.webp", buf.Bytes(), 0666); err != nil {
log.Fatal(err)
}
fmt.Printf("Save output.webp ok\n")
}
示例2: BenchmarkDecode_yellow_rose_lossy_with_alpha_chai2010_webp
func BenchmarkDecode_yellow_rose_lossy_with_alpha_chai2010_webp(b *testing.B) {
data := tbLoadData(b, "yellow_rose.lossy-with-alpha.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := chai2010_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例3: BenchmarkDecode_video_001_chai2010_webp
func BenchmarkDecode_video_001_chai2010_webp(b *testing.B) {
data := tbLoadData(b, "video-001.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := chai2010_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例4: BenchmarkDecode_tux_lossless_chai2010_webp
func BenchmarkDecode_tux_lossless_chai2010_webp(b *testing.B) {
data := tbLoadData(b, "tux.lossless.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := chai2010_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例5: BenchmarkDecode_blue_purple_pink_lossy_chai2010_webp
func BenchmarkDecode_blue_purple_pink_lossy_chai2010_webp(b *testing.B) {
data := tbLoadData(b, "blue-purple-pink.lossy.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := chai2010_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例6: Post
func Post(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.Write(json.Message("ERROR", "Not supported Method"))
return
}
f, _, err := r.FormFile("image")
if err != nil {
w.Write(json.Message("ERROR", "Can't Find Image"))
return
}
defer f.Close()
buf := bufio.NewReader(f)
h := sha1.New()
var result json.Result
var ic iconf
ic.machine = conf.Image.Machine
if conf.InputType == "jpeg" {
ic.image, _, err = image.Decode(io.TeeReader(buf, h))
} else {
ic.image, err = webp.Decode(io.TeeReader(buf, h))
}
ic.hash = fmt.Sprintf("%x", h.Sum(nil))
if err != nil {
w.Write(json.Message("ERROR", "Unable to decode your image! Type="+conf.InputType+" error:"+err.Error()))
return
}
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))
}
示例7: loadImgSpecFormat
func loadImgSpecFormat(file string, ft string) (image.Image, error) {
file_origin, err := os.Open(file)
if err != nil {
return nil, Newcuserr(10000)
}
defer file_origin.Close()
var img0 image.Image
switch ft {
case "gif":
img0, err = gif.Decode(file_origin)
case "png":
img0, err = png.Decode(file_origin)
case "webp":
img0, err = webp.Decode(file_origin)
default:
img0, err = jpeg.Decode(file_origin)
}
if err != nil {
return nil, Newcuserr(10001)
}
return img0, nil
}