Add resolutionUnit to metadata and as tiff option #3023

Co-authored-by: Lovell Fuller <github@lovell.info>
This commit is contained in:
ompal
2021-12-23 11:38:36 +05:30
committed by Lovell Fuller
parent 7aa340232e
commit f7bed69ffb
9 changed files with 61 additions and 3 deletions

View File

@@ -99,6 +99,7 @@ describe('Image metadata', function () {
assert.strictEqual(1, metadata.orientation);
assert.strictEqual('undefined', typeof metadata.exif);
assert.strictEqual('undefined', typeof metadata.icc);
assert.strictEqual('inch', metadata.resolutionUnit);
done();
});
});

View File

@@ -288,6 +288,30 @@ describe('TIFF', function () {
});
});
it('TIFF resolutionUnit of inch (default)', async () => {
const data = await sharp({ create: { width: 8, height: 8, channels: 3, background: 'red' } })
.tiff()
.toBuffer();
const { resolutionUnit } = await sharp(data).metadata();
assert.strictEqual(resolutionUnit, 'inch');
});
it('TIFF resolutionUnit of inch', async () => {
const data = await sharp({ create: { width: 8, height: 8, channels: 3, background: 'red' } })
.tiff({ resolutionUnit: 'inch' })
.toBuffer();
const { resolutionUnit } = await sharp(data).metadata();
assert.strictEqual(resolutionUnit, 'inch');
});
it('TIFF resolutionUnit of cm', async () => {
const data = await sharp({ create: { width: 8, height: 8, channels: 3, background: 'red' } })
.tiff({ resolutionUnit: 'cm' })
.toBuffer();
const { resolutionUnit } = await sharp(data).metadata();
assert.strictEqual(resolutionUnit, 'cm');
});
it('TIFF deflate compression with horizontal predictor shrinks test file', function (done) {
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
sharp(fixtures.inputTiffUncompressed)
@@ -383,6 +407,12 @@ describe('TIFF', function () {
});
});
it('TIFF invalid resolutionUnit option throws', function () {
assert.throws(function () {
sharp().tiff({ resolutionUnit: 'none' });
});
});
it('TIFF horizontal predictor does not throw error', function () {
assert.doesNotThrow(function () {
sharp().tiff({ predictor: 'horizontal' });