diff --git a/vips/image.go b/vips/image.go index 4d6b382f..770983f8 100644 --- a/vips/image.go +++ b/vips/image.go @@ -950,7 +950,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 5a76322e..b1d1fe1a 100644 --- a/vips/image_test.go +++ b/vips/image_test.go @@ -52,6 +52,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)