From bb4f4602c3aef35ff72c9dbc5416f93baf33be0a Mon Sep 17 00:00:00 2001 From: DarthSim Date: Thu, 29 Nov 2018 16:30:59 +0600 Subject: [PATCH] Fallback to no profile while saving PNG if profile is invalid --- process.go | 5 ++++- vips.h | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/process.go b/process.go index bc948d8f..20807099 100644 --- a/process.go +++ b/process.go @@ -626,7 +626,10 @@ func vipsSaveImage(img *C.struct__VipsImage, imgtype imageType, quality int) ([] case imageTypeJPEG: err = C.vips_jpegsave_go(img, &ptr, &imgsize, 1, C.int(quality), cConf.JpegProgressive) case imageTypePNG: - err = C.vips_pngsave_go(img, &ptr, &imgsize, cConf.PngInterlaced) + if err = C.vips_pngsave_go(img, &ptr, &imgsize, cConf.PngInterlaced, 1); err != 0 { + warning("Failed to save PNG; Trying not to embed icc profile") + err = C.vips_pngsave_go(img, &ptr, &imgsize, cConf.PngInterlaced, 0) + } case imageTypeWEBP: err = C.vips_webpsave_go(img, &ptr, &imgsize, 1, C.int(quality)) case imageTypeGIF: diff --git a/vips.h b/vips.h index ea919ed2..a970e8f9 100644 --- a/vips.h +++ b/vips.h @@ -264,8 +264,12 @@ vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int strip, int quality, } int -vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace) { - return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL); +vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int embed_profile) { + if (embed_profile) { + return vips_pngsave_buffer(in, buf, len, "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL); + } + + return vips_pngsave_buffer(in, buf, len, "profile", "none", "filter", VIPS_FOREIGN_PNG_FILTER_NONE, "interlace", interlace, NULL); } int