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:
parent
8f7f5be71c
commit
3c72d0b5ca
1 changed files with 12 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue