interpret negative height and width values as 0

This commit is contained in:
Will Norris 2014-11-23 14:01:50 -08:00
parent 2dd79ebd20
commit ea67c79ffe

View file

@ -43,14 +43,18 @@ func Transform(img []byte, opt Options) ([]byte, error) {
// convert percentage width and height values to absolute values // convert percentage width and height values to absolute values
imgW := m.Bounds().Max.X - m.Bounds().Min.X imgW := m.Bounds().Max.X - m.Bounds().Min.X
imgH := m.Bounds().Max.Y - m.Bounds().Min.Y imgH := m.Bounds().Max.Y - m.Bounds().Min.Y
var h, w int var w, h int
if opt.Width > 0 && opt.Width < 1 { if 0 < opt.Width && opt.Width < 1 {
w = int(float64(imgW) * opt.Width) w = int(float64(imgW) * opt.Width)
} else if opt.Width < 0 {
w = 0
} else { } else {
w = int(opt.Width) w = int(opt.Width)
} }
if opt.Height > 0 && opt.Height < 1 { if 0 < opt.Height && opt.Height < 1 {
h = int(float64(imgH) * opt.Height) h = int(float64(imgH) * opt.Height)
} else if opt.Height < 0 {
h = 0
} else { } else {
h = int(opt.Height) h = int(opt.Height)
} }