chai2010 / webp

WebP decoder and encoder for Go (Zero Dependencies).
http://godoc.org/github.com/chai2010/webp
BSD 3-Clause "New" or "Revised" License
522 stars 88 forks source link

webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments #4

Closed kamoljan closed 10 years ago

kamoljan commented 10 years ago

@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 asdfasdf=@Photo_20140806_000942.jpg http://obrol.shopafter.com:9090/

Is it bug?

chai2010 commented 10 years ago

You can try dwebp first. If dwebp is ok, and the webp.Decode failed, you need provide the test image.

https://developers.google.com/speed/webp/docs/dwebp

kamoljan commented 10 years ago

dwebp is ok, however, webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments.

I cannot attached the webp file in this comment. Going to email you.

kamoljan commented 10 years ago

it was client side code issue with multipart/form-data... everything is fine with webp :)