mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Linter: apply all recommended biome settings
Enforces previously-skipped useArrowFunction check
This commit is contained in:
@@ -14,27 +14,26 @@ const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
// Verifies all tiles in a given dz output directory are <= size
|
||||
const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, done) {
|
||||
const assertDeepZoomTiles = (directory, expectedSize, expectedLevels, done) => {
|
||||
// Get levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
||||
assert.strictEqual(expectedLevels, levels.length);
|
||||
// Get tiles
|
||||
const tiles = [];
|
||||
levels.forEach(function (level) {
|
||||
levels.forEach((level) => {
|
||||
// Verify level directory name
|
||||
assert.strictEqual(true, /^[0-9]+$/.test(level));
|
||||
fs.readdirSync(path.join(directory, level)).forEach(function (tile) {
|
||||
fs.readdirSync(path.join(directory, level)).forEach((tile) => {
|
||||
// Verify tile file name
|
||||
assert.strictEqual(true, /^[0-9]+_[0-9]+\.jpeg$/.test(tile));
|
||||
tiles.push(path.join(directory, level, tile));
|
||||
});
|
||||
});
|
||||
// Verify each tile is <= expectedSize
|
||||
Promise.all(tiles.map(function (tile) {
|
||||
return sharp(tile)
|
||||
Promise.all(tiles.map((tile) => sharp(tile)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
.then((metadata) => {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
@@ -42,20 +41,19 @@ const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, d
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(true, metadata.width <= expectedSize);
|
||||
assert.strictEqual(true, metadata.height <= expectedSize);
|
||||
});
|
||||
}))
|
||||
})))
|
||||
.then(() => done())
|
||||
.catch(done);
|
||||
};
|
||||
|
||||
const assertZoomifyTiles = function (directory, expectedLevels, done) {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||
const assertZoomifyTiles = (directory, expectedLevels, done) => {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.ok(stat.isFile());
|
||||
assert.ok(stat.size > 0);
|
||||
|
||||
let maxTileLevel = -1;
|
||||
fs.readdirSync(path.join(directory, 'TileGroup0')).forEach(function (tile) {
|
||||
fs.readdirSync(path.join(directory, 'TileGroup0')).forEach((tile) => {
|
||||
// Verify tile file name
|
||||
assert.ok(/^[0-9]+-[0-9]+-[0-9]+\.jpg$/.test(tile));
|
||||
const level = Number(tile.split('-')[0]);
|
||||
@@ -68,24 +66,24 @@ const assertZoomifyTiles = function (directory, expectedLevels, done) {
|
||||
});
|
||||
};
|
||||
|
||||
const assertGoogleTiles = function (directory, expectedLevels, done) {
|
||||
const assertGoogleTiles = (directory, expectedLevels, done) => {
|
||||
// Get levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
||||
assert.strictEqual(expectedLevels, levels.length);
|
||||
|
||||
fs.stat(path.join(directory, 'blank.png'), function (err, stat) {
|
||||
fs.stat(path.join(directory, 'blank.png'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.ok(stat.isFile());
|
||||
assert.ok(stat.size > 0);
|
||||
|
||||
// Basic check to confirm lowest and highest level tiles exist
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
|
||||
fs.stat(path.join(directory, (expectedLevels - 1).toString(), '0', '0.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, (expectedLevels - 1).toString(), '0', '0.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -96,7 +94,7 @@ const assertGoogleTiles = function (directory, expectedLevels, done) {
|
||||
};
|
||||
|
||||
// Verifies tiles at specified level in a given output directory are > size+overlap
|
||||
const assertTileOverlap = function (directory, tileSize, done) {
|
||||
const assertTileOverlap = (directory, tileSize, done) => {
|
||||
// Get sorted levels
|
||||
const dirents = fs.readdirSync(directory, { withFileTypes: true });
|
||||
const levels = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name).sort((a, b) => a - b);
|
||||
@@ -107,7 +105,7 @@ const assertTileOverlap = function (directory, tileSize, done) {
|
||||
// Select a tile from the approximate center of the image
|
||||
const squareTile = path.join(directory, highestLevel, tiles[Math.floor(tiles.length / 2)]);
|
||||
|
||||
sharp(squareTile).metadata(function (err, metadata) {
|
||||
sharp(squareTile).metadata((err, metadata) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@@ -119,10 +117,10 @@ const assertTileOverlap = function (directory, tileSize, done) {
|
||||
});
|
||||
};
|
||||
|
||||
describe('Tile', function () {
|
||||
it('Valid size values pass', function () {
|
||||
[1, 8192].forEach(function (size) {
|
||||
assert.doesNotThrow(function () {
|
||||
describe('Tile', () => {
|
||||
it('Valid size values pass', () => {
|
||||
[1, 8192].forEach((size) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
size
|
||||
});
|
||||
@@ -130,9 +128,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid size values fail', function () {
|
||||
['zoinks', 1.1, -1, 0, 8193].forEach(function (size) {
|
||||
assert.throws(function () {
|
||||
it('Invalid size values fail', () => {
|
||||
['zoinks', 1.1, -1, 0, 8193].forEach((size) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
size
|
||||
});
|
||||
@@ -140,9 +138,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid overlap values pass', function () {
|
||||
[0, 8192].forEach(function (overlap) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid overlap values pass', () => {
|
||||
[0, 8192].forEach((overlap) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
size: 8192,
|
||||
overlap
|
||||
@@ -151,9 +149,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid overlap values fail', function () {
|
||||
['zoinks', 1.1, -1, 8193].forEach(function (overlap) {
|
||||
assert.throws(function () {
|
||||
it('Invalid overlap values fail', () => {
|
||||
['zoinks', 1.1, -1, 8193].forEach((overlap) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
overlap
|
||||
});
|
||||
@@ -161,9 +159,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid container values pass', function () {
|
||||
['fs', 'zip'].forEach(function (container) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid container values pass', () => {
|
||||
['fs', 'zip'].forEach((container) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
container
|
||||
});
|
||||
@@ -171,9 +169,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid container values fail', function () {
|
||||
['zoinks', 1].forEach(function (container) {
|
||||
assert.throws(function () {
|
||||
it('Invalid container values fail', () => {
|
||||
['zoinks', 1].forEach((container) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
container
|
||||
});
|
||||
@@ -181,9 +179,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid layout values pass', function () {
|
||||
['dz', 'google', 'zoomify'].forEach(function (layout) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid layout values pass', () => {
|
||||
['dz', 'google', 'zoomify'].forEach((layout) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
layout
|
||||
});
|
||||
@@ -191,9 +189,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid layout values fail', function () {
|
||||
['zoinks', 1].forEach(function (layout) {
|
||||
assert.throws(function () {
|
||||
it('Invalid layout values fail', () => {
|
||||
['zoinks', 1].forEach((layout) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
layout
|
||||
});
|
||||
@@ -201,30 +199,30 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid formats pass', function () {
|
||||
['jpeg', 'png', 'webp'].forEach(function (format) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid formats pass', () => {
|
||||
['jpeg', 'png', 'webp'].forEach((format) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().toFormat(format).tile();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid formats fail', function () {
|
||||
['tiff', 'raw'].forEach(function (format) {
|
||||
assert.throws(function () {
|
||||
it('Invalid formats fail', () => {
|
||||
['tiff', 'raw'].forEach((format) => {
|
||||
assert.throws(() => {
|
||||
sharp().toFormat(format).tile();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid depths pass', function () {
|
||||
['onepixel', 'onetile', 'one'].forEach(function (depth) {
|
||||
it('Valid depths pass', () => {
|
||||
['onepixel', 'onetile', 'one'].forEach((depth) => {
|
||||
assert.doesNotThrow(() => sharp().tile({ depth }));
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid depths fail', function () {
|
||||
['depth', 1].forEach(function (depth) {
|
||||
it('Invalid depths fail', () => {
|
||||
['depth', 1].forEach((depth) => {
|
||||
assert.throws(
|
||||
() => sharp().tile({ depth }),
|
||||
/Expected one of: onepixel, onetile, one for depth but received/
|
||||
@@ -232,16 +230,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Prevent larger overlap than default size', function () {
|
||||
assert.throws(function () {
|
||||
it('Prevent larger overlap than default size', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
overlap: 257
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Prevent larger overlap than provided size', function () {
|
||||
assert.throws(function () {
|
||||
it('Prevent larger overlap than provided size', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
size: 512,
|
||||
overlap: 513
|
||||
@@ -249,9 +247,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid rotation angle values pass', function () {
|
||||
[90, 270, -90].forEach(function (angle) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid rotation angle values pass', () => {
|
||||
[90, 270, -90].forEach((angle) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
angle
|
||||
});
|
||||
@@ -259,9 +257,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid rotation angle values fail', function () {
|
||||
['zoinks', 1.1, -1, 27].forEach(function (angle) {
|
||||
assert.throws(function () {
|
||||
it('Invalid rotation angle values fail', () => {
|
||||
['zoinks', 1.1, -1, 27].forEach((angle) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
angle
|
||||
});
|
||||
@@ -269,9 +267,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid skipBlanks threshold values pass', function () {
|
||||
[-1, 0, 255, 65535].forEach(function (skipBlanksThreshold) {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid skipBlanks threshold values pass', () => {
|
||||
[-1, 0, 255, 65535].forEach((skipBlanksThreshold) => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
skipBlanks: skipBlanksThreshold
|
||||
});
|
||||
@@ -279,9 +277,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('InvalidskipBlanks threshold values fail', function () {
|
||||
['zoinks', -2, 65536].forEach(function (skipBlanksThreshold) {
|
||||
assert.throws(function () {
|
||||
it('InvalidskipBlanks threshold values fail', () => {
|
||||
['zoinks', -2, 65536].forEach((skipBlanksThreshold) => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
skipBlanks: skipBlanksThreshold
|
||||
});
|
||||
@@ -289,42 +287,42 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid center parameter value passes', function () {
|
||||
it('Valid center parameter value passes', () => {
|
||||
assert.doesNotThrow(
|
||||
() => sharp().tile({ center: true })
|
||||
);
|
||||
});
|
||||
|
||||
it('Invalid centre parameter value fails', function () {
|
||||
it('Invalid centre parameter value fails', () => {
|
||||
assert.throws(
|
||||
() => sharp().tile({ centre: 'true' }),
|
||||
/Expected boolean for tileCentre but received true of type string/
|
||||
);
|
||||
});
|
||||
|
||||
it('Valid id parameter value passes', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
it('Valid id parameter value passes', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
sharp().tile({
|
||||
id: 'test'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid id parameter value fails', function () {
|
||||
assert.throws(function () {
|
||||
it('Invalid id parameter value fails', () => {
|
||||
assert.throws(() => {
|
||||
sharp().tile({
|
||||
id: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Valid basename parameter value passes', function () {
|
||||
it('Valid basename parameter value passes', () => {
|
||||
assert.doesNotThrow(
|
||||
() => sharp().tile({ basename: 'pass' })
|
||||
);
|
||||
});
|
||||
|
||||
it('Invalid basename parameter value fails', function () {
|
||||
it('Invalid basename parameter value fails', () => {
|
||||
assert.throws(
|
||||
() => sharp().tile({ basename: true }),
|
||||
/Expected string for basename but received/
|
||||
@@ -332,11 +330,11 @@ describe('Tile', function () {
|
||||
});
|
||||
|
||||
if (sharp.format.dz.output.file) {
|
||||
it('Deep Zoom layout', function (_t, done) {
|
||||
it('Deep Zoom layout', (_t, done) => {
|
||||
const directory = fixtures.path('output.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFile(fixtures.path('output.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.dzi'), (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -348,37 +346,37 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with custom size+overlap', function (_t, done) {
|
||||
it('Deep Zoom layout with custom size+overlap', (_t, done) => {
|
||||
const directory = fixtures.path('output.512.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
overlap: 16
|
||||
})
|
||||
.toFile(fixtures.path('output.512.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.512.dzi'), (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('undefined', typeof info.size);
|
||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, function () {
|
||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, () => {
|
||||
assertTileOverlap(directory, 512, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with custom size+angle', function (_t, done) {
|
||||
it('Deep Zoom layout with custom size+angle', (_t, done) => {
|
||||
const directory = fixtures.path('output.512_90.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
angle: 90
|
||||
})
|
||||
.toFile(fixtures.path('output.512_90.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.512_90.dzi'), (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -392,7 +390,7 @@ describe('Tile', function () {
|
||||
// expected are w=512 and h=170 for the 0_1.jpeg.
|
||||
// if a 0 angle is supplied to the .tile function
|
||||
// the expected values are w=170 and h=512 for the 1_0.jpeg
|
||||
sharp(tile).metadata(function (err, metadata) {
|
||||
sharp(tile).metadata((err, metadata) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
@@ -404,15 +402,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with depth of one', function (_t, done) {
|
||||
it('Deep Zoom layout with depth of one', (_t, done) => {
|
||||
const directory = fixtures.path('output.512_depth_one.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
depth: 'one'
|
||||
})
|
||||
.toFile(fixtures.path('output.512_depth_one.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.512_depth_one.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 512, 1, done);
|
||||
@@ -420,15 +418,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with depth of onepixel', function (_t, done) {
|
||||
it('Deep Zoom layout with depth of onepixel', (_t, done) => {
|
||||
const directory = fixtures.path('output.512_depth_onepixel.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 512,
|
||||
depth: 'onepixel'
|
||||
})
|
||||
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 512, 13, done);
|
||||
@@ -436,15 +434,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with depth of onetile', function (_t, done) {
|
||||
it('Deep Zoom layout with depth of onetile', (_t, done) => {
|
||||
const directory = fixtures.path('output.256_depth_onetile.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
depth: 'onetile'
|
||||
})
|
||||
.toFile(fixtures.path('output.256_depth_onetile.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.256_depth_onetile.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// Verify only one depth generated
|
||||
assertDeepZoomTiles(directory, 256, 5, done);
|
||||
@@ -452,15 +450,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Deep Zoom layout with skipBlanks', function (_t, done) {
|
||||
it('Deep Zoom layout with skipBlanks', (_t, done) => {
|
||||
const directory = fixtures.path('output.256_skip_blanks.dzi_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpgOverlayLayer2)
|
||||
.tile({
|
||||
size: 256,
|
||||
skipBlanks: 0
|
||||
})
|
||||
.toFile(fixtures.path('output.256_skip_blanks.dzi'), function (err) {
|
||||
.toFile(fixtures.path('output.256_skip_blanks.dzi'), (err) => {
|
||||
if (err) throw err;
|
||||
// assert them 0_0.jpeg doesn't exist because it's a white tile
|
||||
const whiteTilePath = path.join(directory, '11', '0_0.jpeg');
|
||||
@@ -471,21 +469,21 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout', function (_t, done) {
|
||||
it('Zoomify layout', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'zoomify'
|
||||
})
|
||||
.toFile(fixtures.path('output.zoomify.dzi'), function (err, info) {
|
||||
.toFile(fixtures.path('output.zoomify.dzi'), (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(undefined, info.size);
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -495,16 +493,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with depth one', function (_t, done) {
|
||||
it('Zoomify layout with depth one', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.depth_one.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
depth: 'one'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -516,16 +514,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with depth onetile', function (_t, done) {
|
||||
it('Zoomify layout with depth onetile', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.depth_onetile.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
depth: 'onetile'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -537,16 +535,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with depth onepixel', function (_t, done) {
|
||||
it('Zoomify layout with depth onepixel', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.depth_onepixel.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
depth: 'onepixel'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -558,16 +556,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Zoomify layout with skip blanks', function (_t, done) {
|
||||
it('Zoomify layout with skip blanks', (_t, done) => {
|
||||
const directory = fixtures.path('output.zoomify.skipBlanks.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpgOverlayLayer2)
|
||||
.tile({
|
||||
size: 256,
|
||||
layout: 'zoomify',
|
||||
skipBlanks: 0
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
// assert them 0_0.jpeg doesn't exist because it's a white tile
|
||||
const whiteTilePath = path.join(directory, 'TileGroup0', '2-0-0.jpg');
|
||||
@@ -582,21 +580,21 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout', function (_t, done) {
|
||||
it('Google layout', (_t, done) => {
|
||||
const directory = fixtures.path('output.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (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(undefined, info.size);
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -606,9 +604,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with jpeg format', function (_t, done) {
|
||||
it('Google layout with jpeg format', (_t, done) => {
|
||||
const directory = fixtures.path('output.jpg.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.jpeg({
|
||||
quality: 1
|
||||
@@ -616,7 +614,7 @@ describe('Tile', function () {
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -624,7 +622,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.jpg');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
sharp(sample).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
@@ -633,7 +631,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(256, metadata.width);
|
||||
assert.strictEqual(256, metadata.height);
|
||||
fs.stat(sample, function (err, stat) {
|
||||
fs.stat(sample, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.size < 2000);
|
||||
done();
|
||||
@@ -643,9 +641,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with png format', function (_t, done) {
|
||||
it('Google layout with png format', (_t, done) => {
|
||||
const directory = fixtures.path('output.png.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.png({
|
||||
compressionLevel: 0
|
||||
@@ -653,7 +651,7 @@ describe('Tile', function () {
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -661,7 +659,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.png');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
sharp(sample).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
@@ -670,7 +668,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(256, metadata.width);
|
||||
assert.strictEqual(256, metadata.height);
|
||||
fs.stat(sample, function (err, stat) {
|
||||
fs.stat(sample, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.size > 44000);
|
||||
done();
|
||||
@@ -680,9 +678,9 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with webp format', function (_t, done) {
|
||||
it('Google layout with webp format', (_t, done) => {
|
||||
const directory = fixtures.path('output.webp.google.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.webp({
|
||||
quality: 1,
|
||||
@@ -691,7 +689,7 @@ describe('Tile', function () {
|
||||
.tile({
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -699,7 +697,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.webp');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
sharp(sample).metadata((err, metadata) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('webp', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
@@ -708,7 +706,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(256, metadata.width);
|
||||
assert.strictEqual(256, metadata.height);
|
||||
fs.stat(sample, function (err, stat) {
|
||||
fs.stat(sample, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.size < 2000);
|
||||
done();
|
||||
@@ -718,16 +716,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with depth one', function (_t, done) {
|
||||
it('Google layout with depth one', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_depth_one.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'google',
|
||||
depth: 'one',
|
||||
size: 256
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -739,16 +737,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with depth onetile', function (_t, done) {
|
||||
it('Google layout with depth onetile', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_depth_onetile.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'google',
|
||||
depth: 'onetile',
|
||||
size: 256
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -760,15 +758,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with default skip Blanks', function (_t, done) {
|
||||
it('Google layout with default skip Blanks', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_depth_skipBlanks.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputPng)
|
||||
.tile({
|
||||
layout: 'google',
|
||||
size: 256
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
|
||||
const whiteTilePath = path.join(directory, '4', '8', '0.jpg');
|
||||
@@ -784,15 +782,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with center image in tile', function (_t, done) {
|
||||
it('Google layout with center image in tile', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_center.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
center: true,
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -804,15 +802,15 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Google layout with center image in tile centre', function (_t, done) {
|
||||
it('Google layout with center image in tile centre', (_t, done) => {
|
||||
const directory = fixtures.path('output.google_center.dzi');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
centre: true,
|
||||
layout: 'google'
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -824,17 +822,17 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('IIIFv2 layout', function (_t, done) {
|
||||
it('IIIFv2 layout', (_t, done) => {
|
||||
const name = 'output.iiif.info';
|
||||
const directory = fixtures.path(name);
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
const id = 'https://sharp.test.com/iiif';
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'iiif',
|
||||
id
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -844,7 +842,7 @@ describe('Tile', function () {
|
||||
const infoJson = require(path.join(directory, 'info.json'));
|
||||
assert.strictEqual('http://iiif.io/api/image/2/context.json', infoJson['@context']);
|
||||
assert.strictEqual(`${id}/${name}`, infoJson['@id']);
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,', '0', 'default.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,', '0', 'default.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -854,17 +852,17 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('IIIFv3 layout', function (_t, done) {
|
||||
it('IIIFv3 layout', (_t, done) => {
|
||||
const name = 'output.iiif3.info';
|
||||
const directory = fixtures.path(name);
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
const id = 'https://sharp.test.com/iiif3';
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
layout: 'iiif3',
|
||||
id
|
||||
})
|
||||
.toFile(directory, function (err, info) {
|
||||
.toFile(directory, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -875,7 +873,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual('http://iiif.io/api/image/3/context.json', infoJson['@context']);
|
||||
assert.strictEqual('ImageService3', infoJson.type);
|
||||
assert.strictEqual(`${id}/${name}`, infoJson.id);
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,256', '0', 'default.jpg'), function (err, stat) {
|
||||
fs.stat(path.join(directory, '0,0,256,256', '256,256', '0', 'default.jpg'), (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -885,20 +883,20 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write to ZIP container using file extension', function (_t, done) {
|
||||
it('Write to ZIP container using file extension', (_t, done) => {
|
||||
const container = fixtures.path('output.dz.container.zip');
|
||||
const extractTo = fixtures.path('output.dz.container');
|
||||
const directory = path.join(extractTo, 'output.dz.container_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.toFile(container, function (err, info) {
|
||||
.toFile(container, (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(container, function (err, stat) {
|
||||
fs.stat(container, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -912,16 +910,16 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write to ZIP container using container tile option', function (_t, done) {
|
||||
it('Write to ZIP container using container tile option', (_t, done) => {
|
||||
const container = fixtures.path('output.dz.containeropt.zip');
|
||||
const extractTo = fixtures.path('output.dz.containeropt');
|
||||
const directory = path.join(extractTo, 'output.dz.containeropt_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({
|
||||
container: 'zip'
|
||||
})
|
||||
.toFile(container, function (err, info) {
|
||||
.toFile(container, (err, info) => {
|
||||
// Vips overrides .dzi extension to .zip used by container var below
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
@@ -929,7 +927,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
fs.stat(container, function (err, stat) {
|
||||
fs.stat(container, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
@@ -943,14 +941,14 @@ describe('Tile', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Write ZIP container to Buffer', function (_t, done) {
|
||||
it('Write ZIP container to Buffer', (_t, done) => {
|
||||
const container = fixtures.path('output.dz.tiles.zip');
|
||||
const extractTo = fixtures.path('output.dz.tiles');
|
||||
const directory = path.join(extractTo, 'output.dz.tiles_files');
|
||||
fs.rm(directory, { recursive: true }, function () {
|
||||
fs.rm(directory, { recursive: true }, () => {
|
||||
sharp(fixtures.inputJpg)
|
||||
.tile({ basename: 'output.dz.tiles' })
|
||||
.toBuffer(function (err, data, info) {
|
||||
.toBuffer((err, data, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('dz', info.format);
|
||||
assert.strictEqual(2725, info.width);
|
||||
@@ -958,7 +956,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
fs.writeFileSync(container, data);
|
||||
fs.stat(container, function (err, stat) {
|
||||
fs.stat(container, (err, stat) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
assert.strictEqual(true, stat.size > 0);
|
||||
|
||||
Reference in New Issue
Block a user