Files
imgproxy/processing/extend.go
Victor Sokolov 3d14c85de3 IMG-13: http.Header, *ImageData -> ImageData (#1473)
* ImageData.Headers()

* *ImageData -> ImageData

* withmatt -> httpheaders of our own

* .Clone() headers, nil

* NewFromBytesWithFormat -> nil

* svg.go -> do not Clone()
2025-08-01 15:44:21 +02:00

49 lines
1.3 KiB
Go

package processing
import (
"github.com/imgproxy/imgproxy/v3/imagedata"
"github.com/imgproxy/imgproxy/v3/options"
"github.com/imgproxy/imgproxy/v3/vips"
)
func extendImage(img *vips.Image, width, height int, gravity *options.GravityOptions, offsetScale float64) error {
imgWidth := img.Width()
imgHeight := img.Height()
if width <= imgWidth && height <= imgHeight {
return nil
}
if width <= 0 {
width = imgWidth
}
if height <= 0 {
height = imgHeight
}
offX, offY := calcPosition(width, height, imgWidth, imgHeight, gravity, offsetScale, false)
return img.Embed(width, height, offX, offY)
}
func extend(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata imagedata.ImageData) error {
if !po.Extend.Enabled {
return nil
}
width, height := pctx.targetWidth, pctx.targetHeight
return extendImage(img, width, height, &po.Extend.Gravity, pctx.dprScale)
}
func extendAspectRatio(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata imagedata.ImageData) error {
if !po.ExtendAspectRatio.Enabled {
return nil
}
width, height := pctx.extendAspectRatioWidth, pctx.extendAspectRatioHeight
if width == 0 || height == 0 {
return nil
}
return extendImage(img, width, height, &po.ExtendAspectRatio.Gravity, pctx.dprScale)
}