mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
Add min dimension logic to smartcrop
The pre-crop operations will sometime yield an image that is already the correct size or 1 pixel smaller (due to rounding error). Currently, bimg will try to smart crop anyways and yield a "bad extract area" error.
This commit is contained in:
parent
15cd115607
commit
ba2a6715ee
3 changed files with 81 additions and 1 deletions
12
resizer.go
12
resizer.go
|
|
@ -256,9 +256,19 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
|
|||
|
||||
switch {
|
||||
case o.Gravity == GravitySmart, o.SmartCrop:
|
||||
image, err = vipsSmartCrop(image, o.Width, o.Height)
|
||||
// it's already at an appropriate size, return immediately
|
||||
if inWidth <= o.Width && inHeight <= o.Height {
|
||||
break
|
||||
}
|
||||
width := int(math.Min(float64(inWidth), float64(o.Width)))
|
||||
height := int(math.Min(float64(inHeight), float64(o.Height)))
|
||||
image, err = vipsSmartCrop(image, width, height)
|
||||
break
|
||||
case o.Crop:
|
||||
// it's already at an appropriate size, return immediately
|
||||
if inWidth <= o.Width && inHeight <= o.Height {
|
||||
break
|
||||
}
|
||||
width := int(math.Min(float64(inWidth), float64(o.Width)))
|
||||
height := int(math.Min(float64(inHeight), float64(o.Height)))
|
||||
left, top := calculateCrop(inWidth, inHeight, o.Width, o.Height, o.Gravity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue