(img *vips.Image, cropWidth, cropHeight int, gravity *GravityOptions, offsetScale float64)
| 6 | ) |
| 7 | |
| 8 | func cropImage(img *vips.Image, cropWidth, cropHeight int, gravity *GravityOptions, offsetScale float64) error { |
| 9 | if cropWidth == 0 && cropHeight == 0 { |
| 10 | return nil |
| 11 | } |
| 12 | |
| 13 | imgWidth, imgHeight := img.Width(), img.Height() |
| 14 | |
| 15 | cropWidth = imath.MinNonZero(cropWidth, imgWidth) |
| 16 | cropHeight = imath.MinNonZero(cropHeight, imgHeight) |
| 17 | |
| 18 | if cropWidth >= imgWidth && cropHeight >= imgHeight { |
| 19 | return nil |
| 20 | } |
| 21 | |
| 22 | if gravity.Type == GravitySmart { |
| 23 | if err := img.CopyMemory(); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | return img.SmartCrop(cropWidth, cropHeight) |
| 27 | } |
| 28 | |
| 29 | left, top := calcPosition(imgWidth, imgHeight, cropWidth, cropHeight, gravity, offsetScale, false) |
| 30 | return img.Crop(left, top, cropWidth, cropHeight) |
| 31 | } |
| 32 | |
| 33 | func (p *Processor) crop(c *Context) error { |
| 34 | width, height := c.CropWidth, c.CropHeight |
no test coverage detected