From 8310f6eb790fc3b89f6c51df61d18d899ba312b7 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 6 Dec 2013 12:06:01 -0800 Subject: [PATCH] properly handle thumbnail requests if both height and width are specified, we assume you want an image at exactly those dimensions, so use imaging.Thumbnail, which will resize and crop the image. if either height or width are left unspecified, then it's just a simple resize request. --- transform/transform.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/transform/transform.go b/transform/transform.go index 4bfac30..ef0e891 100644 --- a/transform/transform.go +++ b/transform/transform.go @@ -39,7 +39,11 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) { if opt.Fit { m = imaging.Fit(m, opt.Width, opt.Height, imaging.Lanczos) } else { - m = imaging.Resize(m, opt.Width, opt.Height, imaging.Lanczos) + if opt.Width == 0 || opt.Height == 0 { + m = imaging.Resize(m, opt.Width, opt.Height, imaging.Lanczos) + } else { + m = imaging.Thumbnail(m, opt.Width, opt.Height, imaging.Lanczos) + } } // encode image