Merge branch 'master' into master

This commit is contained in:
evanoberholster 2019-10-01 23:59:30 +08:00 committed by GitHub
commit 599dc0ba03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 82 additions and 20 deletions

View file

@ -12,6 +12,10 @@ import (
"math"
)
var (
ErrExtractAreaParamsRequired = errors.New("extract area width/height params are required")
)
// resizer is used to transform a given image as byte buffer
// with the passed options.
func resizer(buf []byte, o Options) ([]byte, error) {
@ -274,7 +278,7 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
break
case o.Top != 0 || o.Left != 0 || o.AreaWidth != 0 || o.AreaHeight != 0:
if o.AreaWidth == 0 {
o.AreaHeight = o.Width
o.AreaWidth = o.Width
}
if o.AreaHeight == 0 {
o.AreaHeight = o.Height
@ -444,7 +448,11 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 {
switch {
// Fixed width and height
case o.Width > 0 && o.Height > 0:
factor = math.Min(xfactor, yfactor)
if o.Crop {
factor = math.Min(xfactor, yfactor)
} else {
factor = math.Max(xfactor, yfactor)
}
// Fixed width, auto height
case o.Width > 0:
if o.Crop {