Skip to content

Commit

Permalink
Reapply "Using correct ICC profile while exporting Webp Images (david…
Browse files Browse the repository at this point in the history
…byttow#410)" (davidbyttow#412)

This reverts commit 48c3867.
  • Loading branch information
earlbread committed Oct 6, 2024
1 parent d925c83 commit e9c9fa3
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 @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions vips/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check failure on line 57 in vips/image_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ioutil

Check failure on line 57 in vips/image_test.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ioutil
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 e9c9fa3

Please sign in to comment.