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

never resize larger than the original image

This commit is contained in:
Will Norris 2013-12-26 19:32:23 -08:00
parent 8f7f5be71c
commit 3c72d0b5ca

View file

@ -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 {