mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 02:15:54 -07:00
refactor(#55): minor changes, use proper declarations, unref image
This commit is contained in:
parent
e83c80c93c
commit
174de89a40
5 changed files with 41 additions and 20 deletions
18
resize.go
18
resize.go
|
|
@ -103,12 +103,9 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|||
}
|
||||
|
||||
// Flatten image on a background, if necessary
|
||||
black := Color{0, 0, 0}
|
||||
if imageType == PNG && o.Background != black {
|
||||
image, err = vipsFlatten(image, o.Background)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
image, err = imageFlatten(image, imageType, o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
saveOptions := vipsSaveOptions{
|
||||
|
|
@ -312,6 +309,15 @@ func watermakImage(image *C.VipsImage, w Watermark) (*C.VipsImage, error) {
|
|||
return image, nil
|
||||
}
|
||||
|
||||
func imageFlatten(image *C.VipsImage, imageType ImageType, o Options) (*C.VipsImage, error) {
|
||||
// Only PNG images are supported for now
|
||||
if imageType != PNG || o.Background == ColorBlack {
|
||||
return image, nil
|
||||
}
|
||||
|
||||
return vipsFlattenBackground(image, o.Background)
|
||||
}
|
||||
|
||||
func zoomImage(image *C.VipsImage, zoom int) (*C.VipsImage, error) {
|
||||
if zoom == 0 {
|
||||
return image, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue