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

26 lines
614 B
Go
Raw Permalink Normal View History

package processing
import (
"math"
)
// vectorGuardScale checks if the image is a vector format and downscales it
// to the maximum allowed resolution if necessary
func (p *Processor) vectorGuardScale(c *Context) error {
2025-09-18 10:29:42 +02:00
if c.ImgData == nil || !c.ImgData.Format().IsVector() {
return nil
}
2025-09-23 20:16:36 +03:00
if resolution := c.Img.Width() * c.Img.Height(); resolution > c.SecOps.MaxSrcResolution {
shrink := math.Sqrt(float64(resolution) / float64(c.SecOps.MaxSrcResolution))
c.VectorBaseShrink = shrink
if err := c.Img.Load(c.ImgData, shrink, 0, 1); err != nil {
return err
}
}
c.CalcParams()
return nil
}