From eff36dc09fdd4c520820006ffc53833a5d78b683 Mon Sep 17 00:00:00 2001 From: Edward Silverton Date: Wed, 18 Mar 2020 13:27:54 +0000 Subject: [PATCH] Add IIIF layout support to tile-based output (#2098) --- lib/output.js | 6 +++--- test/unit/tile.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/output.js b/lib/output.js index a847a5e0..e03026ea 100644 --- a/lib/output.js +++ b/lib/output.js @@ -568,7 +568,7 @@ function raw () { * @param {String} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout. * @param {Number} [options.skipBlanks=-1] threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images * @param {String} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file). - * @param {String} [options.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`. + * @param {String} [options.layout='dz'] filesystem layout, possible values are `dz`, `iiif`, `zoomify` or `google`. * @returns {Sharp} * @throws {Error} Invalid parameters */ @@ -603,10 +603,10 @@ function tile (options) { } // Layout if (is.defined(options.layout)) { - if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'zoomify'])) { + if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'iiif', 'zoomify'])) { this.options.tileLayout = options.layout; } else { - throw is.invalidParameterError('layout', 'one of: dz, google, zoomify', options.layout); + throw is.invalidParameterError('layout', 'one of: dz, google, iiif, zoomify', options.layout); } } // Angle of rotation, diff --git a/test/unit/tile.js b/test/unit/tile.js index 00c24e5e..520aca48 100644 --- a/test/unit/tile.js +++ b/test/unit/tile.js @@ -765,6 +765,30 @@ describe('Tile', function () { }); }); + it('IIIF layout', function (done) { + const directory = fixtures.path('output.iiif.info'); + rimraf(directory, function () { + sharp(fixtures.inputJpg) + .tile({ + layout: 'iiif' + }) + .toFile(directory, function (err, info) { + if (err) throw err; + assert.strictEqual('dz', info.format); + assert.strictEqual(2725, info.width); + assert.strictEqual(2225, info.height); + assert.strictEqual(3, info.channels); + assert.strictEqual('number', typeof info.size); + fs.stat(path.join(directory, '0,0,256,256', '256,', '0', 'default.jpg'), function (err, stat) { + if (err) throw err; + assert.strictEqual(true, stat.isFile()); + assert.strictEqual(true, stat.size > 0); + done(); + }); + }); + }); + }); + it('Write to ZIP container using file extension', function (done) { const container = fixtures.path('output.dz.container.zip'); const extractTo = fixtures.path('output.dz.container');