mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support to withMetadata for custom ICC profile #2271
This commit is contained in:
committed by
Lovell Fuller
parent
05ca7d3129
commit
eaecb7347b
BIN
test/fixtures/expected/hilutite.jpg
vendored
Normal file
BIN
test/fixtures/expected/hilutite.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
BIN
test/fixtures/expected/icc-cmyk.jpg
vendored
Normal file
BIN
test/fixtures/expected/icc-cmyk.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
BIN
test/fixtures/hilutite.icm
vendored
Normal file
BIN
test/fixtures/hilutite.icm
vendored
Normal file
Binary file not shown.
@@ -501,6 +501,42 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Apply CMYK output ICC profile', function (done) {
|
||||
const output = fixtures.path('output.icc-cmyk.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.withMetadata({ icc: 'cmyk' })
|
||||
.toFile(output, function (err, info) {
|
||||
if (err) throw err;
|
||||
sharp(output).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, metadata.hasProfile);
|
||||
assert.strictEqual('cmyk', metadata.space);
|
||||
assert.strictEqual(4, metadata.channels);
|
||||
// ICC
|
||||
assert.strictEqual('object', typeof metadata.icc);
|
||||
assert.strictEqual(true, metadata.icc instanceof Buffer);
|
||||
const profile = icc.parse(metadata.icc);
|
||||
assert.strictEqual('object', typeof profile);
|
||||
assert.strictEqual('CMYK', profile.colorSpace);
|
||||
assert.strictEqual('Relative', profile.intent);
|
||||
assert.strictEqual('Printer', profile.deviceClass);
|
||||
});
|
||||
fixtures.assertSimilar(output, fixtures.path('expected/icc-cmyk.jpg'), { threshold: 0 }, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('Apply custom output ICC profile', function (done) {
|
||||
const output = fixtures.path('output.hilutite.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.withMetadata({ icc: fixtures.path('hilutite.icm') })
|
||||
.toFile(output, function (err, info) {
|
||||
if (err) throw err;
|
||||
fixtures.assertMaxColourDistance(output, fixtures.path('expected/hilutite.jpg'), 0);
|
||||
fixtures.assertMaxColourDistance(output, fixtures.inputJpg, 16.5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Include metadata in output, enabled via empty object', () =>
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.withMetadata({})
|
||||
@@ -675,5 +711,10 @@ describe('Image metadata', function () {
|
||||
sharp().withMetadata({ orientation: 9 });
|
||||
});
|
||||
});
|
||||
it('Non string icc', function () {
|
||||
assert.throws(function () {
|
||||
sharp().withMetadata({ icc: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user