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

properly handle thumbnail requests

if both height and width are specified, we assume you want an image at
exactly those dimensions, so use imaging.Thumbnail, which will resize
and crop the image.

if either height or width are left unspecified, then it's just a simple
resize request.
This commit is contained in:
Will Norris 2013-12-06 12:06:01 -08:00
parent 2794d47390
commit 8310f6eb79

View file

@ -39,7 +39,11 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
if opt.Fit {
m = imaging.Fit(m, opt.Width, opt.Height, imaging.Lanczos)
} else {
m = imaging.Resize(m, opt.Width, opt.Height, imaging.Lanczos)
if opt.Width == 0 || opt.Height == 0 {
m = imaging.Resize(m, opt.Width, opt.Height, imaging.Lanczos)
} else {
m = imaging.Thumbnail(m, opt.Width, opt.Height, imaging.Lanczos)
}
}
// encode image