From 068da56c91a783eff8d030568368a58e93b93888 Mon Sep 17 00:00:00 2001 From: xeoncross Date: Mon, 26 Aug 2019 14:04:06 -0500 Subject: [PATCH] Added support for JPEG encoding --- context.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/context.go b/context.go index 5e4e476..1ddb09f 100644 --- a/context.go +++ b/context.go @@ -5,6 +5,7 @@ import ( "errors" "image" "image/color" + "image/jpeg" "image/png" "io" "math" @@ -150,6 +151,13 @@ func (dc *Context) EncodePNG(w io.Writer) error { return png.Encode(w, dc.im) } +// EncodeJPG encodes the image as a JPG and writes it to the provided io.Writer +// in JPEG 4:2:0 baseline format with the given options. +// Default parameters are used if a nil *jpeg.Options is passed. +func (dc *Context) EncodeJPG(w io.Writer, o *jpeg.Options) error { + return jpeg.Encode(w, dc.im, o) +} + // 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.