extend.go 601 B

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