0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

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
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)
}