diff --git a/README.md b/README.md index 09ecddd..58bf9c9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and it's typically 4x faster than using the quickest ImageMagick and GraphicsMag If you're looking for an HTTP based image processing solution, see [imaginary](https://github.com/h2non/imaginary). -bimg was heavily inspired in [sharp](https://github.com/lovell/sharp), its homologous package built for [node.js](http://nodejs.org). +bimg was heavily inspired in [sharp](https://github.com/lovell/sharp), its homologous package built for [node.js](http://nodejs.org). bimg is used in production environments for more than a year processing thousands of images per day. **v1 notice**: `bimg` introduces some minor breaking changes in `v1` release. If you're using `gopkg.in`, you can still rely in the `v0` without worrying about breaking changes. diff --git a/vips.go b/vips.go index f63c8a6..6b74199 100644 --- a/vips.go +++ b/vips.go @@ -274,14 +274,15 @@ func vipsFlattenBackground(image *C.VipsImage, background Color) (*C.VipsImage, C.double(background.B), } - err := C.vips_flatten_background_brigde(image, &outImage, (*C.double)(&backgroundC[0])) - if int(err) != 0 { - return nil, catchVipsError() + if vipsHasAlpha(image) { + err := C.vips_flatten_background_brigde(image, &outImage, (*C.double)(&backgroundC[0])) + if int(err) != 0 { + return nil, catchVipsError() + } + C.g_object_unref(C.gpointer(image)) + image = outImage } - C.g_object_unref(C.gpointer(image)) - image = outImage - return image, nil } @@ -317,7 +318,12 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { if err != nil { return nil, err } - defer C.g_object_unref(C.gpointer(tmpImage)) + //When an image has an unsupported color space, vipsPreSave returns the pointer of the image passed to it unmodified. + //When this occurs, we must take care to not dereference the original image a second time; + //we may otherwise erroneously free the object twice + if tmpImage != image { + defer C.g_object_unref(C.gpointer(tmpImage)) + } length := C.size_t(0) saveErr := C.int(0)