From 93f92929f2e9ef4d996b4c94244bcadfe5373393 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Wed, 24 Feb 2016 12:24:57 -0800 Subject: [PATCH] encodePNG implemented Fixes #2. Allows passing in an io.Writer to save a PNG. --- context.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/context.go b/context.go index b2cc402..c2e917e 100644 --- a/context.go +++ b/context.go @@ -5,6 +5,8 @@ import ( "image" "image/color" "image/draw" + "image/png" + "io" "math" "github.com/golang/freetype/raster" @@ -103,6 +105,11 @@ func (dc *Context) SavePNG(path string) error { return SavePNG(path, dc.im) } +// EncodePNG encodes the image as a PNG and writes it to the provided io.Writer. +func (dc *Context) EncodePNG(w io.Writer) error { + return png.Encode(w, dc.im) +} + // SetDash sets the current dash pattern to use. Call with zero arguments to // disable dashes. The values specify the lengths of each dash, with // alternating on and off lengths.