fix(crop): tests

This commit is contained in:
Tomas Aparicio 2015-04-06 02:59:29 +02:00
parent 2e90c11e5b
commit 03f08422d8
8 changed files with 86 additions and 17 deletions

View file

@ -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