mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
fix(crop): tests
This commit is contained in:
parent
2e90c11e5b
commit
03f08422d8
8 changed files with 86 additions and 17 deletions
|
|
@ -11,12 +11,6 @@ import (
|
|||
"math"
|
||||
)
|
||||
|
||||
const (
|
||||
BICUBIC Interpolator = iota
|
||||
BILINEAR
|
||||
NOHALO
|
||||
)
|
||||
|
||||
const (
|
||||
CENTRE Gravity = iota
|
||||
NORTH
|
||||
|
|
@ -163,9 +157,10 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|||
|
||||
if affinedWidth != o.Width || affinedHeight != o.Height {
|
||||
if o.Crop {
|
||||
left, top := calculateCrop(inWidth, inHeight, o.Width, o.Height, o.Gravity)
|
||||
left, top := calculateCrop(affinedWidth, affinedHeight, o.Width, o.Height, o.Gravity)
|
||||
o.Width = int(math.Min(float64(inWidth), float64(o.Width)))
|
||||
o.Height = int(math.Min(float64(inHeight), float64(o.Height)))
|
||||
debug("crop image to %dx%d to %dx%d", left, top, o.Width, o.Height)
|
||||
image, err = vipsExtract(image, left, top, o.Width, o.Height)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue