本文整理匯總了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
}