mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
Replacing SmartCrop with a Gravity option
This commit is contained in:
parent
d232b4098a
commit
855de7ca55
3 changed files with 7 additions and 6 deletions
8
image.go
8
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue