Replacing SmartCrop with a Gravity option

master
Mark van der Velden 9 years ago
parent d232b4098a
commit 855de7ca55

@ -44,10 +44,10 @@ func (i *Image) ResizeAndCrop(width, height int) ([]byte, error) {
// SmartCrop produces a thumbnail aiming at focus on the interesting part. // SmartCrop produces a thumbnail aiming at focus on the interesting part.
func (i *Image) SmartCrop(width, height int) ([]byte, error) { func (i *Image) SmartCrop(width, height int) ([]byte, error) {
options := Options{ options := Options{
Width: width, Width: width,
Height: height, Height: height,
Crop: true, Crop: true,
SmartCrop: true, Gravity: GravitySmart,
} }
return i.Process(options) return i.Process(options)
} }

@ -27,6 +27,8 @@ const (
GravitySouth GravitySouth
// GravityWest represents the west value used for image gravity orientation. // GravityWest represents the west value used for image gravity orientation.
GravityWest GravityWest
// GravitySmart enables libvips Smart Crop algorithm for image gravity orientation.
GravitySmart
) )
// Interpolator represents the image interpolation value. // Interpolator represents the image interpolation value.
@ -193,7 +195,6 @@ type Options struct {
Compression int Compression int
Zoom int Zoom int
Crop bool Crop bool
SmartCrop bool
Enlarge bool Enlarge bool
Embed bool Embed bool
Flip bool Flip bool

@ -249,7 +249,7 @@ func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
inHeight := int(image.Ysize) inHeight := int(image.Ysize)
switch { switch {
case o.SmartCrop: case o.Gravity == GravitySmart:
image, err = vipsSmartCrop(image, o.Width, o.Height) image, err = vipsSmartCrop(image, o.Width, o.Height)
break break
case o.Crop: case o.Crop:

Loading…
Cancel
Save