mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support for page selection with multi-page TIFF input (#1204)
This commit is contained in:
committed by
Lovell Fuller
parent
8ef1532691
commit
b154cd0418
BIN
test/fixtures/G31D_MULTI.TIF
vendored
Normal file
BIN
test/fixtures/G31D_MULTI.TIF
vendored
Normal file
Binary file not shown.
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@@ -94,6 +94,7 @@ module.exports = {
|
||||
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
||||
inputTiffMultipage: getPath('G31D_MULTI.TIF'), // gm convert G31D.TIF -resize 50% G31D_2.TIF ; tiffcp G31D.TIF G31D_2.TIF G31D_MULTI.TIF
|
||||
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
||||
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
||||
inputTiff8BitDepth: getPath('8bit_depth.tiff'),
|
||||
|
||||
@@ -528,6 +528,22 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF file input with invalid page fails gracefully', function (done) {
|
||||
sharp(fixtures.inputTiffMultipage, { page: 2 })
|
||||
.toBuffer(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF buffer input with invalid page fails gracefully', function (done) {
|
||||
sharp(fs.readFileSync(fixtures.inputTiffMultipage), { page: 2 })
|
||||
.toBuffer(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Output filename with unknown extension', function () {
|
||||
it('Match JPEG input', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
@@ -880,6 +896,53 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Load multi-page TIFF\'s from file', function (done) {
|
||||
sharp(fixtures.inputTiffMultipage) // defaults to page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, defaultData.length > 0);
|
||||
assert.strictEqual(defaultData.length, defaultInfo.size);
|
||||
assert.strictEqual('jpeg', defaultInfo.format);
|
||||
|
||||
sharp(fixtures.inputTiffMultipage, { page: 1 }) // 50%-scale copy of page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, scaledData, scaledInfo) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, scaledData.length > 0);
|
||||
assert.strictEqual(scaledData.length, scaledInfo.size);
|
||||
assert.strictEqual('jpeg', scaledInfo.format);
|
||||
assert.strictEqual(defaultInfo.width, scaledInfo.width * 2);
|
||||
assert.strictEqual(defaultInfo.height, scaledInfo.height * 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Load multi-page TIFF\'s from Buffer', function (done) {
|
||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiffMultipage);
|
||||
sharp(inputTiffBuffer) // defaults to page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, defaultData.length > 0);
|
||||
assert.strictEqual(defaultData.length, defaultInfo.size);
|
||||
assert.strictEqual('jpeg', defaultInfo.format);
|
||||
|
||||
sharp(inputTiffBuffer, { page: 1 }) // 50%-scale copy of page 0
|
||||
.jpeg()
|
||||
.toBuffer(function (err, scaledData, scaledInfo) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, scaledData.length > 0);
|
||||
assert.strictEqual(scaledData.length, scaledInfo.size);
|
||||
assert.strictEqual('jpeg', scaledInfo.format);
|
||||
assert.strictEqual(defaultInfo.width, scaledInfo.width * 2);
|
||||
assert.strictEqual(defaultInfo.height, scaledInfo.height * 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Save TIFF to Buffer', function (done) {
|
||||
sharp(fixtures.inputTiff)
|
||||
.resize(320, 240)
|
||||
|
||||
Reference in New Issue
Block a user