From ea67c79ffea71a159249d4a87b576c7b807fb0bf Mon Sep 17 00:00:00 2001 From: Will Norris Date: Sun, 23 Nov 2014 14:01:50 -0800 Subject: [PATCH] interpret negative height and width values as 0 --- transform.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/transform.go b/transform.go index f0e0399..0879a6c 100644 --- a/transform.go +++ b/transform.go @@ -43,14 +43,18 @@ 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 { + var w, h int + if 0 < opt.Width && opt.Width < 1 { w = int(float64(imgW) * opt.Width) + } else if opt.Width < 0 { + w = 0 } else { w = int(opt.Width) } - if opt.Height > 0 && opt.Height < 1 { + if 0 < opt.Height && opt.Height < 1 { h = int(float64(imgH) * opt.Height) + } else if opt.Height < 0 { + h = 0 } else { h = int(opt.Height) }