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()
|
2025-06-04 20:20:20 +03:00
|
|
|
|
2025-06-05 20:19:20 +03:00
|
|
|
if width <= imgWidth && height <= imgHeight {
|
2021-04-26 17:52:50 +06:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-05 20:19:20 +03:00
|
|
|
if width <= 0 {
|
|
|
|
|
width = imgWidth
|
2025-06-04 20:20:20 +03:00
|
|
|
}
|
2025-06-05 20:19:20 +03:00
|
|
|
if height <= 0 {
|
|
|
|
|
height = imgHeight
|
2025-06-04 20:20:20 +03:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
2023-02-19 18:58:30 +03:00
|
|
|
|
2025-09-23 15:55:04 +02:00
|
|
|
func (p *Processor) extend(c *Context) error {
|
2025-09-23 20:16:36 +03:00
|
|
|
if !c.PO.ExtendEnabled() {
|
2025-06-05 20:19:20 +03:00
|
|
|
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)
|
2023-02-19 18:58:30 +03:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 15:55:04 +02:00
|
|
|
func (p *Processor) extendAspectRatio(c *Context) error {
|
2025-09-23 20:16:36 +03:00
|
|
|
if !c.PO.ExtendAspectRatioEnabled() {
|
2025-06-05 20:19:20 +03:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 10:29:42 +02:00
|
|
|
width, height := c.ExtendAspectRatioWidth, c.ExtendAspectRatioHeight
|
2025-06-05 20:19:20 +03:00
|
|
|
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)
|
2023-02-19 18:58:30 +03:00
|
|
|
}
|