From 855de7ca5597e1bd7222c5470d0b37e55c03ce11 Mon Sep 17 00:00:00 2001 From: Mark van der Velden Date: Wed, 24 May 2017 14:20:54 +0200 Subject: [PATCH] Replacing SmartCrop with a Gravity option --- image.go | 8 ++++---- options.go | 3 ++- resize.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/image.go b/image.go index 6f925fb..efaffcb 100644 --- a/image.go +++ b/image.go @@ -44,10 +44,10 @@ func (i *Image) ResizeAndCrop(width, height int) ([]byte, error) { // SmartCrop produces a thumbnail aiming at focus on the interesting part. func (i *Image) SmartCrop(width, height int) ([]byte, error) { options := Options{ - Width: width, - Height: height, - Crop: true, - SmartCrop: true, + Width: width, + Height: height, + Crop: true, + Gravity: GravitySmart, } return i.Process(options) } diff --git a/options.go b/options.go index b8d8a08..4b39039 100644 --- a/options.go +++ b/options.go @@ -27,6 +27,8 @@ const ( GravitySouth // GravityWest represents the west value used for image gravity orientation. GravityWest + // GravitySmart enables libvips Smart Crop algorithm for image gravity orientation. + GravitySmart ) // Interpolator represents the image interpolation value. @@ -193,7 +195,6 @@ type Options struct { Compression int Zoom int Crop bool - SmartCrop bool Enlarge bool Embed bool Flip bool diff --git a/resize.go b/resize.go index c05a6b8..5b2ef4c 100644 --- a/resize.go +++ b/resize.go @@ -249,7 +249,7 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) { inHeight := int(image.Ysize) switch { - case o.SmartCrop: + case o.Gravity == GravitySmart: image, err = vipsSmartCrop(image, o.Width, o.Height) break case o.Crop: