From a71584a63cd265c9c6263d27e099eb21b70e2bd9 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 2 May 2016 19:23:00 -0700 Subject: [PATCH] skip transform if options don't request it Fixes #64 --- data.go | 9 +++++++-- data_test.go | 2 ++ transform.go | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/data.go b/data.go index 382be17..c5c5e2f 100644 --- a/data.go +++ b/data.go @@ -72,8 +72,6 @@ type Options struct { ScaleUp bool } -var emptyOptions = Options{} - func (o Options) String() string { buf := new(bytes.Buffer) fmt.Fprintf(buf, "%v%s%v", o.Width, optSizeDelimiter, o.Height) @@ -101,6 +99,13 @@ func (o Options) String() string { return buf.String() } +// transform returns whether o includes transformation options. Some fields +// are not transform related at all (like Signature), and others only apply in +// the presence of other fields (like Fit and Quality). +func (o Options) transform() bool { + return o.Width != 0 || o.Height != 0 || o.Rotate != 0 || o.FlipHorizontal || o.FlipVertical +} + // ParseOptions parses str as a list of comma separated transformation options. // The following options can be specified in any order: // diff --git a/data_test.go b/data_test.go index 5d63d35..735448f 100644 --- a/data_test.go +++ b/data_test.go @@ -19,6 +19,8 @@ import ( "testing" ) +var emptyOptions = Options{} + func TestOptions_String(t *testing.T) { tests := []struct { Options Options diff --git a/transform.go b/transform.go index b37d0ca..4536c61 100644 --- a/transform.go +++ b/transform.go @@ -35,7 +35,7 @@ var resampleFilter = imaging.Lanczos // encoded image in one of the supported formats (gif, jpeg, or png). The // bytes of a similarly encoded image is returned. func Transform(img []byte, opt Options) ([]byte, error) { - if opt == emptyOptions { + if !opt.transform() { // bail if no transformation was requested return img, nil }