mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 18:35:54 -07:00
feat(image): pass gravity to crop
This commit is contained in:
parent
5a6ed699e8
commit
2607ff2232
2 changed files with 7 additions and 6 deletions
11
image.go
11
image.go
|
|
@ -35,12 +35,13 @@ func (i *Image) Enlarge(width, height int) ([]byte, error) {
|
||||||
return i.Process(options)
|
return i.Process(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crop an image by width and height
|
// Crop the image to the exact size specified
|
||||||
func (i *Image) Crop(width, height int) ([]byte, error) {
|
func (i *Image) Crop(width, height int, gravity Gravity) ([]byte, error) {
|
||||||
options := Options{
|
options := Options{
|
||||||
Width: width,
|
Width: width,
|
||||||
Height: height,
|
Height: height,
|
||||||
Crop: true,
|
Gravity: gravity,
|
||||||
|
Crop: true,
|
||||||
}
|
}
|
||||||
return i.Process(options)
|
return i.Process(options)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func TestImageEnlarge(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageCrop(t *testing.T) {
|
func TestImageCrop(t *testing.T) {
|
||||||
buf, err := initImage("test.jpg").Crop(800, 600)
|
buf, err := initImage("test.jpg").Crop(800, 600, NORTH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Cannot process the image: %#v", err)
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue