(c *Context)
| 31 | } |
| 32 | |
| 33 | func (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 | |
| 63 | func (p *Processor) cropToResult(c *Context) error { |
| 64 | gravity := c.PO.Gravity() |
nothing calls this directly
no test coverage detected