From e9c9fa39751324e00f798f5b622ecd56710f4616 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Sun, 6 Oct 2024 19:06:28 +0900 Subject: [PATCH] Reapply "Using correct ICC profile while exporting Webp Images (#410)" (#412) This reverts commit 48c38673aaf7242cd7397af5836102b41e128a99. --- vips/image.go | 4 +++- vips/image_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/vips/image.go b/vips/image.go index 82d5fac2..86daf183 100644 --- a/vips/image.go +++ b/vips/image.go @@ -955,7 +955,9 @@ func (r *ImageRef) ExportWebp(params *WebpExportParams) ([]byte, *ImageMetadata, } paramsWithIccProfile := *params - paramsWithIccProfile.IccProfile = r.optimizedIccProfile + if r.optimizedIccProfile != "" && params.IccProfile == "" { + paramsWithIccProfile.IccProfile = r.optimizedIccProfile + } buf, err := vipsSaveWebPToBuffer(r.image, paramsWithIccProfile) if err != nil { diff --git a/vips/image_test.go b/vips/image_test.go index 9c6090bc..43fba292 100644 --- a/vips/image_test.go +++ b/vips/image_test.go @@ -51,6 +51,29 @@ func TestImageRef_WebP__ReducedEffort(t *testing.T) { assert.NoError(t, err) } +func TestImageInbuildIcc_WebP(t *testing.T) { + Startup(nil) + + srcBytes, err := ioutil.ReadFile(resources + "jpg-24bit-icc-iec.jpg") + require.NoError(t, err) + + img, err := NewImageFromBuffer(srcBytes) + require.NoError(t, err) + require.NotNil(t, img) + + params := NewWebpExportParams() + exportedWebpBytes, _, err := img.ExportWebp(params) + assert.NoError(t, err) + assert.NotNil(t, exportedWebpBytes) + + // Check if the exported webp has the same ICC profile as the original image + exportedImg, err := NewImageFromBuffer(exportedWebpBytes) + require.NoError(t, err) + require.NotNil(t, exportedImg) + + assert.Equal(t, img.GetICCProfile(), exportedImg.GetICCProfile()) +} + func TestImageRef_WebP__NearLossless(t *testing.T) { Startup(nil)