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

Function cropImage

processing/crop.go:8–31  ·  view source on GitHub ↗
(img *vips.Image, cropWidth, cropHeight int, gravity *GravityOptions, offsetScale float64)

Source from the content-addressed store, hash-verified

6)
7
8func 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
33func (p *Processor) crop(c *Context) error {
34 width, height := c.CropWidth, c.CropHeight

Callers 2

cropMethod · 0.85
cropToResultMethod · 0.85

Calls 7

MinNonZeroFunction · 0.92
calcPositionFunction · 0.85
CopyMemoryMethod · 0.80
SmartCropMethod · 0.80
CropMethod · 0.80
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected