Skip to content

Commit

Permalink
Using correct ICC profile while exporting Webp Images (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashik-s authored Mar 3, 2024
1 parent e5b0a3d commit 5c0bc15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions vips/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5c0bc15

Please sign in to comment.