You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2026-04-26 20:02:24 +02:00
41 lines
836 B
Go
41 lines
836 B
Go
package processing
|
|
|
|
func (p *Processor) scale(c *Context) error {
|
|
if c.WScale == 1 && c.HScale == 1 {
|
|
return nil
|
|
}
|
|
|
|
wscale, hscale := c.WScale, c.HScale
|
|
|
|
if (c.Angle+c.PO.Rotate())%180 == 90 {
|
|
wscale, hscale = hscale, wscale
|
|
}
|
|
|
|
// Save current colorspace
|
|
cs := c.Img.Type()
|
|
|
|
// Convert to linear colorspace if needed
|
|
if p.config.UseLinearColorspace {
|
|
// We need this to keep colors consistent after processing
|
|
if err := c.Img.ImportColourProfile(); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Convert to linear colorspace
|
|
if err := c.Img.LinearColourspace(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if err := c.Img.Resize(wscale, hscale); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Convert back to original colorspace if we used linear during processing
|
|
if p.config.UseLinearColorspace {
|
|
return c.Img.Colorspace(cs)
|
|
}
|
|
|
|
return nil
|
|
}
|