mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-01-23 11:14:48 +02:00
Downscale requested WebP dimensions when one of them exceeds WebP limit
This commit is contained in:
parent
feff67e26f
commit
399995deea
@ -10,6 +10,9 @@
|
||||
- Docker image includes the latest versions of dependencies.
|
||||
- Optimize processing of animated images.
|
||||
|
||||
### Fix
|
||||
- Fix error when requested WebP dimension exceeds the WebP dimension limit.
|
||||
|
||||
## [2.13.1] - 2020-05-06
|
||||
### Fixed
|
||||
- Fix and optimize processing of animated images.
|
||||
|
17
process.go
17
process.go
@ -10,7 +10,12 @@ import (
|
||||
"github.com/imgproxy/imgproxy/v2/imagemeta"
|
||||
)
|
||||
|
||||
const msgSmartCropNotSupported = "Smart crop is not supported by used version of libvips"
|
||||
const (
|
||||
msgSmartCropNotSupported = "Smart crop is not supported by used version of libvips"
|
||||
|
||||
// https://chromium.googlesource.com/webm/libwebp/+/refs/heads/master/src/webp/encode.h#529
|
||||
webpMaxDimension = 16383.0
|
||||
)
|
||||
|
||||
var errConvertingNonSvgToSvg = newError(422, "Converting non-SVG images to SVG is not supported", "Converting non-SVG images to SVG is not supported")
|
||||
|
||||
@ -721,6 +726,16 @@ func processImage(ctx context.Context) ([]byte, context.CancelFunc, error) {
|
||||
po.Width, po.Height = 0, 0
|
||||
}
|
||||
|
||||
if po.Format == imageTypeWEBP {
|
||||
webpLimitShrink := float64(maxInt(po.Width, po.Height)) * po.Dpr / webpMaxDimension
|
||||
|
||||
if webpLimitShrink > 1.0 {
|
||||
po.Width = int(float64(po.Width) / webpLimitShrink)
|
||||
po.Height = int(float64(po.Height) / webpLimitShrink)
|
||||
logWarning("WebP dimension size is limited to %d. Requested dimensions are rescaled to %dx%d", int(webpMaxDimension), po.Width, po.Height)
|
||||
}
|
||||
}
|
||||
|
||||
animationSupport := conf.MaxAnimationFrames > 1 && vipsSupportAnimation(imgdata.Type) && vipsSupportAnimation(po.Format)
|
||||
|
||||
pages := 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user