refactor(#55): minor changes, use proper declarations, unref image

This commit is contained in:
Tomas Aparicio 2015-09-29 08:45:02 +01:00
parent e83c80c93c
commit 174de89a40
5 changed files with 41 additions and 20 deletions

View file

@ -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