mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
feat(crop): add method shortcuts for crop
This commit is contained in:
parent
6d27b8ef91
commit
c9001cd22c
2 changed files with 53 additions and 3 deletions
24
image.go
24
image.go
|
|
@ -14,6 +14,17 @@ func (i *Image) Resize(width, height int) ([]byte, error) {
|
|||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Resize the image to fixed width and height with additional crop transformation
|
||||
func (i *Image) ResizeAndCrop(width, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
Width: width,
|
||||
Height: height,
|
||||
Embed: true,
|
||||
Crop: true,
|
||||
}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Extract area from the by X/Y axis
|
||||
func (i *Image) Extract(top, left, width, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
|
|
@ -25,7 +36,7 @@ func (i *Image) Extract(top, left, width, height int) ([]byte, error) {
|
|||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Enlarge the image from the by X/Y axis
|
||||
// Enlarge the image by width and height. Aspect ratio is maintained
|
||||
func (i *Image) Enlarge(width, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
Width: width,
|
||||
|
|
@ -35,6 +46,17 @@ func (i *Image) Enlarge(width, height int) ([]byte, error) {
|
|||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Enlarge the image by width and height with additional crop transformation
|
||||
func (i *Image) EnlargeAndCrop(width, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
Width: width,
|
||||
Height: height,
|
||||
Enlarge: true,
|
||||
Crop: true,
|
||||
}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Crop the image to the exact size specified
|
||||
func (i *Image) Crop(width, height int, gravity Gravity) ([]byte, error) {
|
||||
options := Options{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue