123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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)
- }
|