Replace PNGEncode with WriteTo for Image.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:48:58 +0200
3 files changed,
9 insertions(+),
5 deletions(-)
M
captcha.go
→
captcha.go
@@ -54,7 +54,8 @@ ns := globalStore.getNumbers(id)
if ns == nil { return os.NewError("captcha id not found") } - return NewImage(ns, width, height).PNGEncode(w) + _, err := NewImage(ns, width, height).WriteTo(w) + return err } // WriteAudio writes WAV-encoded audio captcha with the given captcha id into
M
cmd/image/main.go
→
cmd/image/main.go
@@ -7,5 +7,5 @@ )
func main() { img, _ := captcha.NewRandomImage(captcha.StdLength, captcha.StdWidth, captcha.StdHeight) - img.PNGEncode(os.Stdout) + img.WriteTo(os.Stdout) }
M
image.go
→
image.go
@@ -68,9 +68,12 @@ img = NewImage(numbers, width, height)
return } -// PNGEncode writes captcha image in PNG format into the given writer. -func (img *Image) PNGEncode(w io.Writer) os.Error { - return png.Encode(w, img) +// WriteTo writes captcha image in PNG format into the given writer. +// +// Bug: while Image conforms to io.WriterTo interface, this function returns 0 +// instead of the actual bytes written because png.Encode doesn't report this. +func (img *Image) WriteTo(w io.Writer) (int64, os.Error) { + return 0, png.Encode(w, img) } func (img *Image) calculateSizes(width, height, ncount int) {