mediaapi/thumbnailer: Check if request is larger than original

This commit is contained in:
Robert Swain 2017-06-08 13:07:41 +02:00
parent f2ac8d442a
commit f7e16450a2
2 changed files with 18 additions and 0 deletions

View file

@ -81,6 +81,11 @@ func createThumbnail(src types.Path, img *bimg.Image, config types.ThumbnailSize
"ResizeMethod": config.ResizeMethod,
})
// Check if request is larger than original
if isLargerThanOriginal(config, img) {
return false, nil
}
dst := GetThumbnailPath(src, config)
// Note: getActiveThumbnailGeneration uses mutexes and conditions from activeThumbnailGeneration
@ -153,6 +158,14 @@ func createThumbnail(src types.Path, img *bimg.Image, config types.ThumbnailSize
return false, nil
}
func isLargerThanOriginal(config types.ThumbnailSize, img *bimg.Image) bool {
imgSize, err := img.Size()
if err == nil && config.Width >= imgSize.Width && config.Height >= imgSize.Height {
return true
}
return false
}
// resize scales an image to fit within the provided width and height
// If the source aspect ratio is different to the target dimensions, one edge will be smaller than requested
// If crop is set to true, the image will be scaled to fill the width and height with any excess being cropped off

View file

@ -113,6 +113,11 @@ func createThumbnail(src types.Path, img image.Image, config types.ThumbnailSize
"ResizeMethod": config.ResizeMethod,
})
// Check if request is larger than original
if config.Width >= img.Bounds().Dx() && config.Height >= img.Bounds().Dy() {
return false, nil
}
dst := GetThumbnailPath(src, config)
// Note: getActiveThumbnailGeneration uses mutexes and conditions from activeThumbnailGeneration