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

Method crop

processing/crop.go:33–61  ·  view source on GitHub ↗
(c *Context)

Source from the content-addressed store, hash-verified

31}
32
33func (p *Processor) crop(c *Context) error {
34 width, height := c.CropWidth, c.CropHeight
35 rotateAngle := c.PO.Rotate()
36 flipX := c.PO.FlipHorizontal()
37 flipY := c.PO.FlipVertical()
38
39 // Since we crop before rotating and flipping,
40 // we need to adjust gravity options accordingly.
41 // After rotation and flipping, we'll get the same result
42 // as if we cropped with the original gravity options after
43 // rotation and flipping.
44 //
45 // During rotation/flipping, we first apply the EXIF orientation,
46 // then the user-specified operations.
47 // So here we apply the adjustments in the reverse order.
48 opts := c.CropGravity
49 opts.RotateAndFlip(rotateAngle, flipX, flipY)
50 opts.RotateAndFlip(c.Angle, c.Flip, false)
51
52 // If the final image is rotated by 90 or 270 degrees,
53 // we need to swap width and height for cropping.
54 // After rotation, we'll get the originally intended dimensions.
55 if (c.Angle+rotateAngle)%180 == 90 {
56 width, height = height, width
57 }
58
59 // Since we crop before scaling, we shouldn't consider DPR
60 return cropImage(c.Img, width, height, &opts, 1.0)
61}
62
63func (p *Processor) cropToResult(c *Context) error {
64 gravity := c.PO.Gravity()

Callers

nothing calls this directly

Calls 5

cropImageFunction · 0.85
RotateAndFlipMethod · 0.80
RotateMethod · 0.45
FlipHorizontalMethod · 0.45
FlipVerticalMethod · 0.45

Tested by

no test coverage detected