mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Ensure tile overlap option works as expected (#1921)
This commit is contained in:
committed by
Lovell Fuller
parent
ca52894651
commit
d5b7040557
@@ -91,6 +91,29 @@ const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels,
|
||||
});
|
||||
};
|
||||
|
||||
// Verifies tiles at specified level in a given output directory are > size+overlap
|
||||
const assertTileOverlap = function (directory, tileSize, done) {
|
||||
// Get sorted levels
|
||||
const levels = fs.readdirSync(directory).sort((a, b) => a - b);
|
||||
// Select the highest tile level
|
||||
const highestLevel = levels[levels.length - 1];
|
||||
// Get sorted tiles from greatest level
|
||||
const tiles = fs.readdirSync(path.join(directory, highestLevel)).sort();
|
||||
// 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) {
|
||||
if (err) {
|
||||
throw err;
|
||||
} else {
|
||||
// Tile with an overlap should be larger than original size
|
||||
assert.strictEqual(true, metadata.width > tileSize);
|
||||
assert.strictEqual(true, metadata.height > tileSize);
|
||||
done();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
describe('Tile', function () {
|
||||
it('Valid size values pass', function () {
|
||||
[1, 8192].forEach(function (size) {
|
||||
@@ -297,7 +320,9 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('undefined', typeof info.size);
|
||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, done);
|
||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, function () {
|
||||
assertTileOverlap(directory, 512, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user