all repos — captcha @ 797447596cf268e3bf3a1f4459c3977ba6415605

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Replace PNGEncode with WriteTo for Image.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:48:58 +0200
commit

797447596cf268e3bf3a1f4459c3977ba6415605

parent

e3eb22480f6e652f321e379501124c5c62318fc2

3 files changed, 9 insertions(+), 5 deletions(-)

jump to
M captcha.gocaptcha.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.gocmd/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.goimage.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) {