From 3c72d0b5ca3bf1789d0b63a55043e592dd0a760c Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 26 Dec 2013 19:32:23 -0800 Subject: [PATCH] never resize larger than the original image --- proxy/transform.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/proxy/transform.go b/proxy/transform.go index a3857b4..baa609a 100644 --- a/proxy/transform.go +++ b/proxy/transform.go @@ -40,18 +40,28 @@ func Transform(img []byte, opt *Options) ([]byte, error) { } // convert percentage width and height values to absolute values + imgW := m.Bounds().Max.X - m.Bounds().Min.X + imgH := m.Bounds().Max.Y - m.Bounds().Min.Y var h, w int if opt.Width > 0 && opt.Width < 1 { - w = int(float64(m.Bounds().Max.X-m.Bounds().Min.X) * opt.Width) + w = int(float64(imgW) * opt.Width) } else { w = int(opt.Width) } if opt.Height > 0 && opt.Height < 1 { - h = int(float64(m.Bounds().Max.Y-m.Bounds().Min.Y) * opt.Height) + h = int(float64(imgH) * opt.Height) } else { h = int(opt.Height) } + // never resize larger than the original image + if w > imgW { + w = imgW + } + if h > imgH { + h = imgH + } + // resize if w != 0 || h != 0 { if opt.Fit {