From bb7469b2d170831c1e9c23ba945166d0b4a14e23 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 15 Aug 2023 13:02:20 +0100 Subject: [PATCH] Ensure withMetadata adds default sRGB profile #3761 --- docs/changelog.md | 3 +++ src/pipeline.cc | 4 ++-- test/unit/metadata.js | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 5c3c3f3c7..701feb0ca 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -21,6 +21,9 @@ Requires libvips v8.14.3 [#3758](https://github.com/lovell/sharp/pull/3758) [@sho-xizz](https://github.com/sho-xizz) +* Ensure `withMetadata` adds default sRGB profile. + [#3761](https://github.com/lovell/sharp/issues/3761) + ### v0.32.4 - 21st July 2023 * Upgrade to libvips v8.14.3 for upstream bug fixes. diff --git a/src/pipeline.cc b/src/pipeline.cc index 00879af14..857c0e63d 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -788,9 +788,9 @@ class PipelineWorker : public Napi::AsyncWorker { } // Apply output ICC profile - if (!baton->withMetadataIcc.empty()) { + if (baton->withMetadata) { image = image.icc_transform( - const_cast(baton->withMetadataIcc.data()), + baton->withMetadataIcc.empty() ? "srgb" : const_cast(baton->withMetadataIcc.data()), VImage::option() ->set("input_profile", processingProfile) ->set("embedded", TRUE) diff --git a/test/unit/metadata.js b/test/unit/metadata.js index ac7163397..bd4a554e7 100644 --- a/test/unit/metadata.js +++ b/test/unit/metadata.js @@ -781,6 +781,19 @@ describe('Image metadata', function () { }); }); + it('withMetadata adds default sRGB profile', async () => { + const data = await sharp(fixtures.inputJpg) + .resize(32, 24) + .withMetadata() + .toBuffer(); + + const metadata = await sharp(data).metadata(); + const { colorSpace, deviceClass, intent } = icc.parse(metadata.icc); + assert.strictEqual(colorSpace, 'RGB'); + assert.strictEqual(deviceClass, 'Monitor'); + assert.strictEqual(intent, 'Perceptual'); + }); + it('File input with corrupt header fails gracefully', function (done) { sharp(fixtures.inputJpgWithCorruptHeader) .metadata(function (err) {