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

Method scale

processing/scale.go:3–40  ·  view source on GitHub ↗
(c *Context)

Source from the content-addressed store, hash-verified

1package processing
2
3func (p *Processor) scale(c *Context) error {
4 if c.WScale == 1 && c.HScale == 1 {
5 return nil
6 }
7
8 wscale, hscale := c.WScale, c.HScale
9
10 if (c.Angle+c.PO.Rotate())%180 == 90 {
11 wscale, hscale = hscale, wscale
12 }
13
14 // Save current colorspace
15 cs := c.Img.Type()
16
17 // Convert to linear colorspace if needed
18 if p.config.UseLinearColorspace {
19 // We need this to keep colors consistent after processing
20 if err := c.Img.ImportColourProfile(); err != nil {
21 return err
22 }
23
24 // Convert to linear colorspace
25 if err := c.Img.LinearColourspace(); err != nil {
26 return err
27 }
28 }
29
30 if err := c.Img.Resize(wscale, hscale); err != nil {
31 return err
32 }
33
34 // Convert back to original colorspace if we used linear during processing
35 if p.config.UseLinearColorspace {
36 return c.Img.Colorspace(cs)
37 }
38
39 return nil
40}

Callers

nothing calls this directly

Calls 6

TypeMethod · 0.80
ImportColourProfileMethod · 0.80
LinearColourspaceMethod · 0.80
ResizeMethod · 0.80
ColorspaceMethod · 0.80
RotateMethod · 0.45

Tested by

no test coverage detected