mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Emit warning for invalid ICC profile #3895
This commit is contained in:
parent
c9e3996007
commit
fe2b298a2f
@ -9,6 +9,9 @@ Requires libvips v8.15.0
|
||||
* Add support for Yarn Plug'n'Play filesystem layout.
|
||||
[#3888](https://github.com/lovell/sharp/issues/3888)
|
||||
|
||||
* Emit warning when attempting to use invalid ICC profiles.
|
||||
[#3895](https://github.com/lovell/sharp/issues/3895)
|
||||
|
||||
### v0.33.0 - 29th November 2023
|
||||
|
||||
* Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0
|
||||
|
@ -794,11 +794,15 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
|
||||
// Apply output ICC profile
|
||||
if (!baton->withIccProfile.empty()) {
|
||||
try {
|
||||
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
|
||||
->set("input_profile", processingProfile)
|
||||
->set("embedded", TRUE)
|
||||
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
||||
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||
} catch(...) {
|
||||
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
|
||||
}
|
||||
} else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) {
|
||||
image = sharp::SetProfile(image, inputProfile);
|
||||
}
|
||||
|
BIN
test/fixtures/invalid-illuminant.icc
vendored
Normal file
BIN
test/fixtures/invalid-illuminant.icc
vendored
Normal file
Binary file not shown.
@ -598,6 +598,24 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(undefined, metadata.icc);
|
||||
});
|
||||
|
||||
it('transform to invalid ICC profile emits warning', async () => {
|
||||
const img = sharp({ create })
|
||||
.png()
|
||||
.withIccProfile(fixtures.path('invalid-illuminant.icc'));
|
||||
|
||||
let warningEmitted = '';
|
||||
img.on('warning', (warning) => {
|
||||
warningEmitted = warning;
|
||||
});
|
||||
|
||||
const data = await img.toBuffer();
|
||||
assert.strictEqual('Invalid profile', warningEmitted);
|
||||
|
||||
const metadata = await sharp(data).metadata();
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
assert.strictEqual(undefined, metadata.icc);
|
||||
});
|
||||
|
||||
it('Apply CMYK output ICC profile', function (done) {
|
||||
const output = fixtures.path('output.icc-cmyk.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
|
Loading…
x
Reference in New Issue
Block a user