1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/processing/extend.go

45 lines
997 B
Go
Raw Permalink Normal View History

2021-04-26 17:52:50 +06:00
package processing
2025-09-25 17:28:09 +03:00
func extendImage(c *Context, width, height int, gravity *GravityOptions) error {
imgWidth := c.Img.Width()
imgHeight := c.Img.Height()
if width <= imgWidth && height <= imgHeight {
2021-04-26 17:52:50 +06:00
return nil
}
if width <= 0 {
width = imgWidth
}
if height <= 0 {
height = imgHeight
}
2025-09-25 17:28:09 +03:00
offX, offY := calcPosition(width, height, imgWidth, imgHeight, gravity, c.DprScale, false)
return c.Img.Embed(width, height, offX, offY)
2021-04-26 17:52:50 +06:00
}
func (p *Processor) extend(c *Context) error {
2025-09-23 20:16:36 +03:00
if !c.PO.ExtendEnabled() {
return nil
}
2025-09-18 10:29:42 +02:00
width, height := c.TargetWidth, c.TargetHeight
2025-09-23 20:16:36 +03:00
gravity := c.PO.ExtendGravity()
2025-09-25 17:28:09 +03:00
return extendImage(c, width, height, &gravity)
}
func (p *Processor) extendAspectRatio(c *Context) error {
2025-09-23 20:16:36 +03:00
if !c.PO.ExtendAspectRatioEnabled() {
return nil
}
2025-09-18 10:29:42 +02:00
width, height := c.ExtendAspectRatioWidth, c.ExtendAspectRatioHeight
if width == 0 || height == 0 {
return nil
}
2025-09-23 20:16:36 +03:00
gravity := c.PO.ExtendAspectRatioGravity()
2025-09-25 17:28:09 +03:00
return extendImage(c, width, height, &gravity)
}