MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / vectorGuardScale

Method vectorGuardScale

processing/vector_guard_scale.go:9–27  ·  view source on GitHub ↗

vectorGuardScale checks if the image is a vector format and downscales it to the maximum allowed resolution if necessary

(c *Context)

Source from the content-addressed store, hash-verified

7// vectorGuardScale checks if the image is a vector format and downscales it
8// to the maximum allowed resolution if necessary
9func (p *Processor) vectorGuardScale(c *Context) error {
10 if c.ImgData == nil || !c.ImgData.Format().IsVector() {
11 return nil
12 }
13
14 maxSrcRes := c.PO.MaxSrcResolution()
15
16 if resolution := c.Img.Width() * c.Img.Height(); resolution > maxSrcRes {
17 shrink := math.Sqrt(float64(resolution) / float64(maxSrcRes))
18 c.VectorBaseShrink = shrink
19
20 if err := c.Img.Load(c.ImgData, shrink, 0, 1); err != nil {
21 return err
22 }
23 }
24 c.CalcParams()
25
26 return nil
27}

Callers

nothing calls this directly

Calls 7

IsVectorMethod · 0.80
LoadMethod · 0.80
CalcParamsMethod · 0.80
FormatMethod · 0.65
MaxSrcResolutionMethod · 0.45
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected