From 13ef72dc0350ae98961e2e721c7fb0b8167a04b6 Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Tue, 3 Nov 2015 07:54:40 +0000 Subject: [PATCH] refactor(resize): clone options by value --- resize.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resize.go b/resize.go index d6dce26..f0ba8e3 100644 --- a/resize.go +++ b/resize.go @@ -23,8 +23,8 @@ func Resize(buf []byte, o Options) ([]byte, error) { return nil, err } - // Define default options - applyDefaults(&o, imageType) + // Clone and define default options + o = applyDefaults(o, imageType) if IsTypeSupported(o.Type) == false { return nil, errors.New("Unsupported image output type") @@ -121,7 +121,7 @@ func Resize(buf []byte, o Options) ([]byte, error) { return vipsSave(image, saveOptions) } -func applyDefaults(o *Options, imageType ImageType) { +func applyDefaults(o Options, imageType ImageType) Options { if o.Quality == 0 { o.Quality = QUALITY } @@ -134,6 +134,7 @@ func applyDefaults(o *Options, imageType ImageType) { if o.Interpretation == 0 { o.Interpretation = INTERPRETATION_sRGB } + return o } func normalizeOperation(o *Options, inWidth, inHeight int) {