Add skipBlanks support for tile layout (#1687)

This commit is contained in:
RaboliotTheGrey
2019-07-12 13:02:51 +02:00
committed by Lovell Fuller
parent b737d4601e
commit 6c02949fc1
6 changed files with 112 additions and 2 deletions

View File

@@ -539,6 +539,7 @@ function toFormat (format, options) {
* @param {Number} [tile.overlap=0] tile overlap in pixels, a value between 0 and 8192.
* @param {Number} [tile.angle=0] tile angle of rotation, must be a multiple of 90.
* @param {String} [tile.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
* @param {Number} [tile.skipBlanks=-1] threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images
* @param {String} [tile.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
* @param {String} [tile.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
* @returns {Sharp}
@@ -599,6 +600,21 @@ function tile (tile) {
throw new Error("Invalid tile depth '" + tile.depth + "', should be one of 'onepixel', 'onetile' or 'one'");
}
}
// Threshold of skipping blanks,
if (is.defined(tile.skipBlanks)) {
if (is.integer(tile.skipBlanks) && is.inRange(tile.skipBlanks, -1, 65535)) {
this.options.skipBlanks = tile.skipBlanks;
} else {
throw new Error('Invalid skipBlank threshold (-1 to 255/65535) ' + tile.skipBlanks);
}
} else {
if (is.defined(tile.layout) && tile.layout === 'google') {
this.options.skipBlanks = 5;
} else {
this.options.skipBlanks = -1;
}
}
}
// Format
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {