1
0

extend.go 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package processing
  2. func extendImage(c *Context, width, height int, gravity *GravityOptions) error {
  3. imgWidth := c.Img.Width()
  4. imgHeight := c.Img.Height()
  5. if width <= imgWidth && height <= imgHeight {
  6. return nil
  7. }
  8. if width <= 0 {
  9. width = imgWidth
  10. }
  11. if height <= 0 {
  12. height = imgHeight
  13. }
  14. offX, offY := calcPosition(width, height, imgWidth, imgHeight, gravity, c.DprScale, false)
  15. return c.Img.Embed(width, height, offX, offY)
  16. }
  17. func (p *Processor) extend(c *Context) error {
  18. if !c.PO.ExtendEnabled() {
  19. return nil
  20. }
  21. width, height := c.TargetWidth, c.TargetHeight
  22. gravity := c.PO.ExtendGravity()
  23. return extendImage(c, width, height, &gravity)
  24. }
  25. func (p *Processor) extendAspectRatio(c *Context) error {
  26. if !c.PO.ExtendAspectRatioEnabled() {
  27. return nil
  28. }
  29. width, height := c.ExtendAspectRatioWidth, c.ExtendAspectRatioHeight
  30. if width == 0 || height == 0 {
  31. return nil
  32. }
  33. gravity := c.PO.ExtendAspectRatioGravity()
  34. return extendImage(c, width, height, &gravity)
  35. }