Skip to content

Commit

Permalink
Ensure withMetadata adds default sRGB profile #3761
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Aug 15, 2023
1 parent a2cac61 commit bb7469b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(baton->withMetadataIcc.data()),
baton->withMetadataIcc.empty() ? "srgb" : const_cast<char*>(baton->withMetadataIcc.data()),
VImage::option()
->set("input_profile", processingProfile)
->set("embedded", TRUE)
Expand Down
13 changes: 13 additions & 0 deletions test/unit/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bb7469b

Please sign in to comment.