mirror of
https://github.com/lovell/sharp.git
synced 2025-07-14 20:50:14 +02:00
Ensure tile overlap option works as expected (#1921)
This commit is contained in:
parent
ca52894651
commit
d5b7040557
@ -575,7 +575,7 @@ function tile (options) {
|
||||
if (options.overlap > this.options.tileSize) {
|
||||
throw is.invalidParameterError('overlap', `<= size (${this.options.tileSize})`, options.overlap);
|
||||
}
|
||||
this.options.tileOverlap = tile.overlap;
|
||||
this.options.tileOverlap = options.overlap;
|
||||
} else {
|
||||
throw is.invalidParameterError('overlap', 'integer between 0 and 8192', options.overlap);
|
||||
}
|
||||
|
@ -63,7 +63,8 @@
|
||||
"Jordan Prudhomme <jordan@raboland.fr>",
|
||||
"Ilya Ovdin <iovdin@gmail.com>",
|
||||
"Andargor <andargor@yahoo.com>",
|
||||
"Paul Neave <paul.neave@gmail.com>"
|
||||
"Paul Neave <paul.neave@gmail.com>",
|
||||
"Brendan Kennedy <brenwken@gmail.com>"
|
||||
],
|
||||
"scripts": {
|
||||
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user