From fc9b23852eff7ef2262ffb402aa96de685b648d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Aparicio?= Date: Wed, 4 May 2016 13:57:27 +0100 Subject: [PATCH 1/4] feat(docs): add production note --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 7170832f93731567ff1d4812506ac44c30be92dd Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 14 May 2016 01:32:59 +0000 Subject: [PATCH 2/4] Check if there is an alpha channel before flattening --- vips.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/vips.go b/vips.go index f63c8a6..f5cdc3c 100644 --- a/vips.go +++ b/vips.go @@ -274,13 +274,14 @@ 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 + } return image, nil } From 5f7342a9aa2441deaa32734b55b913ce9584b9fd Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 14 May 2016 01:35:27 +0000 Subject: [PATCH 3/4] Fix formatting --- vips.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vips.go b/vips.go index f5cdc3c..ba68cba 100644 --- a/vips.go +++ b/vips.go @@ -279,8 +279,8 @@ func vipsFlattenBackground(image *C.VipsImage, background Color) (*C.VipsImage, 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 From db78c9b75e1574ec87f1e7ab8e8e6c835744bf2d Mon Sep 17 00:00:00 2001 From: Aarti Parikh Date: Tue, 21 Jun 2016 17:47:08 -0700 Subject: [PATCH 4/4] Take care to not dereference the original image a second time --- vips.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vips.go b/vips.go index ba68cba..6b74199 100644 --- a/vips.go +++ b/vips.go @@ -318,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)