mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-28 20:43:54 +02:00
* ImageData.Headers() * *ImageData -> ImageData * withmatt -> httpheaders of our own * .Clone() headers, nil * NewFromBytesWithFormat -> nil * svg.go -> do not Clone()
49 lines
1.3 KiB
Go
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)
|
|
}
|