extend.go 691 B

1234567891011121314151617181920
  1. package processing
  2. import (
  3. "github.com/imgproxy/imgproxy/v2/imagedata"
  4. "github.com/imgproxy/imgproxy/v2/imath"
  5. "github.com/imgproxy/imgproxy/v2/options"
  6. "github.com/imgproxy/imgproxy/v2/vips"
  7. )
  8. func extend(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
  9. resultWidth := imath.Scale(po.Width, po.Dpr)
  10. resultHeight := imath.Scale(po.Height, po.Dpr)
  11. if !po.Extend.Enabled || (resultWidth <= img.Width() && resultHeight <= img.Height()) {
  12. return nil
  13. }
  14. offX, offY := calcPosition(resultWidth, resultHeight, img.Width(), img.Height(), &po.Extend.Gravity, false)
  15. return img.Embed(resultWidth, resultHeight, offX, offY)
  16. }