mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-13 17:30:28 -07:00
feat(#60): support zero top and left params in extract operation
This commit is contained in:
parent
89292e7ead
commit
b7eaa00f10
4 changed files with 26 additions and 1 deletions
6
vips.go
6
vips.go
|
|
@ -8,6 +8,7 @@ import "C"
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
|
@ -340,6 +341,10 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
|||
return buf, nil
|
||||
}
|
||||
|
||||
func max(x int) int {
|
||||
return int(math.Max(float64(x), 0))
|
||||
}
|
||||
|
||||
func vipsExtract(image *C.VipsImage, left, top, width, height int) (*C.VipsImage, error) {
|
||||
var buf *C.VipsImage
|
||||
defer C.g_object_unref(C.gpointer(image))
|
||||
|
|
@ -348,6 +353,7 @@ func vipsExtract(image *C.VipsImage, left, top, width, height int) (*C.VipsImage
|
|||
return nil, errors.New("Maximum image size exceeded")
|
||||
}
|
||||
|
||||
top, left = max(top), max(left)
|
||||
err := C.vips_extract_area_bridge(image, &buf, C.int(left), C.int(top), C.int(width), C.int(height))
|
||||
if err != 0 {
|
||||
return nil, catchVipsError()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue