mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-25 19:24:38 +02:00
Fix the extend
processing option when only one dimension is set
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
### Fixed
|
### Fixed
|
||||||
- Fix `X-Origin-Content-Length` header value when SVG is sanitized or minified.
|
- Fix `X-Origin-Content-Length` header value when SVG is sanitized or minified.
|
||||||
- Mark JPEG XL format as supporting quality. Fixes autoquality for JPEG XL.
|
- Mark JPEG XL format as supporting quality. Fixes autoquality for JPEG XL.
|
||||||
|
- Fix the `extend` processing option when only one dimension is set.
|
||||||
- (pro) Fix object detection when the `IMGPROXY_USE_LINEAR_COLORSPACE` config is set to `true`.
|
- (pro) Fix object detection when the `IMGPROXY_USE_LINEAR_COLORSPACE` config is set to `true`.
|
||||||
- (pro) Fix BlurHash generation when the `IMGPROXY_USE_LINEAR_COLORSPACE` config is set to `true`.
|
- (pro) Fix BlurHash generation when the `IMGPROXY_USE_LINEAR_COLORSPACE` config is set to `true`.
|
||||||
- (pro) Fix detection of PDF files with a header offset.
|
- (pro) Fix detection of PDF files with a header offset.
|
||||||
|
@@ -8,22 +8,38 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func extendImage(img *vips.Image, resultWidth, resultHeight int, opts *options.ExtendOptions, offsetScale float64, extendAr bool) error {
|
func extendImage(img *vips.Image, resultWidth, resultHeight int, opts *options.ExtendOptions, offsetScale float64, extendAr bool) error {
|
||||||
if !opts.Enabled || (resultWidth <= img.Width() && resultHeight <= img.Height()) || resultWidth == 0 || resultHeight == 0 {
|
imgWidth := img.Width()
|
||||||
|
imgHeight := img.Height()
|
||||||
|
|
||||||
|
if !opts.Enabled || (resultWidth <= imgWidth && resultHeight <= imgHeight) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if extendAr && resultWidth > img.Width() && resultHeight > img.Height() {
|
if resultWidth <= 0 {
|
||||||
diffW := float64(resultWidth) / float64(img.Width())
|
if extendAr {
|
||||||
diffH := float64(resultHeight) / float64(img.Height())
|
return nil
|
||||||
|
}
|
||||||
|
resultWidth = imgWidth
|
||||||
|
}
|
||||||
|
if resultHeight <= 0 {
|
||||||
|
if extendAr {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
resultHeight = imgHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
if extendAr && resultWidth > imgWidth && resultHeight > imgHeight {
|
||||||
|
diffW := float64(resultWidth) / float64(imgWidth)
|
||||||
|
diffH := float64(resultHeight) / float64(imgHeight)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case diffH > diffW:
|
case diffH > diffW:
|
||||||
resultHeight = imath.Scale(img.Width(), float64(resultHeight)/float64(resultWidth))
|
resultHeight = imath.Scale(imgWidth, float64(resultHeight)/float64(resultWidth))
|
||||||
resultWidth = img.Width()
|
resultWidth = imgWidth
|
||||||
|
|
||||||
case diffW > diffH:
|
case diffW > diffH:
|
||||||
resultWidth = imath.Scale(img.Height(), float64(resultWidth)/float64(resultHeight))
|
resultWidth = imath.Scale(imgHeight, float64(resultWidth)/float64(resultHeight))
|
||||||
resultHeight = img.Height()
|
resultHeight = imgHeight
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// The image has the requested arpect ratio
|
// The image has the requested arpect ratio
|
||||||
@@ -31,7 +47,7 @@ func extendImage(img *vips.Image, resultWidth, resultHeight int, opts *options.E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
offX, offY := calcPosition(resultWidth, resultHeight, img.Width(), img.Height(), &opts.Gravity, offsetScale, false)
|
offX, offY := calcPosition(resultWidth, resultHeight, imgWidth, imgHeight, &opts.Gravity, offsetScale, false)
|
||||||
return img.Embed(resultWidth, resultHeight, offX, offY)
|
return img.Embed(resultWidth, resultHeight, offX, offY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user