@basemaps/lambda-tiler 6.19.0 → 6.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +2 -2
- package/build/__test__/tile.style.json.test.d.ts +2 -0
- package/build/__test__/tile.style.json.test.d.ts.map +1 -0
- package/build/__test__/tile.style.json.test.js +33 -0
- package/build/__test__/xyz.test.js +24 -23
- package/build/cli/dump.js +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/routes/esri/rest.d.ts +10 -0
- package/build/routes/esri/rest.d.ts.map +1 -0
- package/build/routes/esri/rest.js +87 -0
- package/build/routes/imagery.d.ts +2 -0
- package/build/routes/imagery.d.ts.map +1 -1
- package/build/routes/imagery.js +3 -1
- package/build/routes/response.d.ts +4 -0
- package/build/routes/response.d.ts.map +1 -0
- package/build/routes/response.js +3 -0
- package/build/routes/tile.d.ts +0 -20
- package/build/routes/tile.d.ts.map +1 -1
- package/build/routes/tile.js +11 -161
- package/build/routes/tile.json.d.ts +10 -0
- package/build/routes/tile.json.d.ts.map +1 -0
- package/build/routes/tile.json.js +31 -0
- package/build/routes/tile.style.json.d.ts +10 -0
- package/build/routes/tile.style.json.d.ts.map +1 -0
- package/build/routes/tile.style.json.js +74 -0
- package/build/routes/tile.wmts.d.ts +9 -0
- package/build/routes/tile.wmts.d.ts.map +1 -0
- package/build/routes/tile.wmts.js +57 -0
- package/build/routes/tile.xyz.d.ts +13 -0
- package/build/routes/tile.xyz.d.ts.map +1 -0
- package/build/routes/tile.xyz.js +28 -0
- package/build/tile.set.raster.d.ts +2 -0
- package/build/tile.set.raster.d.ts.map +1 -1
- package/build/tile.set.raster.js +3 -1
- package/build/tile.set.vector.js +1 -1
- package/dist/index.js +10545 -9583
- package/dist/node_modules/color/README.md +7 -7
- package/dist/node_modules/color/index.js +173 -158
- package/dist/node_modules/color/package.json +18 -16
- package/dist/node_modules/color-convert/conversions.js +281 -310
- package/dist/node_modules/color-convert/index.js +27 -24
- package/dist/node_modules/color-convert/package.json +16 -14
- package/dist/node_modules/color-convert/route.js +22 -22
- package/dist/node_modules/color-name/package.json +17 -14
- package/dist/node_modules/color-string/package.json +5 -5
- package/dist/node_modules/decompress-response/index.d.ts +14 -21
- package/dist/node_modules/decompress-response/index.js +34 -16
- package/dist/node_modules/decompress-response/license +1 -1
- package/dist/node_modules/decompress-response/package.json +23 -17
- package/dist/node_modules/decompress-response/readme.md +2 -6
- package/dist/node_modules/detect-libc/package.json +0 -1
- package/dist/node_modules/mimic-response/index.d.ts +2 -2
- package/dist/node_modules/mimic-response/index.js +41 -2
- package/dist/node_modules/mimic-response/package.json +17 -17
- package/dist/node_modules/mimic-response/readme.md +22 -1
- package/dist/node_modules/node-abi/.circleci/config.yml +63 -0
- package/dist/node_modules/node-abi/.releaserc.json +9 -0
- package/dist/node_modules/node-abi/abi_registry.json +39 -4
- package/dist/node_modules/node-abi/index.js +5 -2
- package/dist/node_modules/node-abi/package.json +17 -16
- package/dist/node_modules/node-abi/test/index.js +7 -15
- package/dist/node_modules/node-addon-api/README.md +2 -2
- package/dist/node_modules/node-addon-api/except.gypi +20 -11
- package/dist/node_modules/node-addon-api/napi-inl.h +734 -196
- package/dist/node_modules/node-addon-api/napi.h +420 -164
- package/dist/node_modules/node-addon-api/noexcept.gypi +21 -11
- package/dist/node_modules/node-addon-api/package.json +43 -14
- package/dist/node_modules/node-addon-api/tools/clang-format.js +18 -17
- package/dist/node_modules/node-addon-api/tools/eslint-format.js +71 -0
- package/dist/node_modules/prebuild-install/CHANGELOG.md +24 -7
- package/dist/node_modules/prebuild-install/README.md +24 -4
- package/dist/node_modules/prebuild-install/asset.js +10 -10
- package/dist/node_modules/prebuild-install/bin.js +13 -13
- package/dist/node_modules/prebuild-install/download.js +22 -22
- package/dist/node_modules/prebuild-install/log.js +4 -4
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/LICENSE +201 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/README.md +160 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/index.d.ts +11 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/detect-libc.js +178 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/process.js +16 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/package.json +71 -0
- package/dist/node_modules/prebuild-install/package.json +18 -19
- package/dist/node_modules/prebuild-install/proxy.js +10 -10
- package/dist/node_modules/prebuild-install/rc.js +12 -12
- package/dist/node_modules/prebuild-install/util.js +14 -14
- package/dist/node_modules/semver/package.json +1 -0
- package/dist/node_modules/sharp/README.md +2 -2
- package/dist/node_modules/sharp/binding.gyp +12 -9
- package/dist/node_modules/sharp/build/Release/sharp-linux-x64.node +0 -0
- package/dist/node_modules/sharp/install/dll-copy.js +6 -6
- package/dist/node_modules/sharp/install/libvips.js +4 -8
- package/dist/node_modules/sharp/lib/channel.js +11 -7
- package/dist/node_modules/sharp/lib/colour.js +42 -1
- package/dist/node_modules/sharp/lib/constructor.js +18 -31
- package/dist/node_modules/sharp/lib/input.js +45 -3
- package/dist/node_modules/sharp/lib/is.js +19 -5
- package/dist/node_modules/sharp/lib/libvips.js +4 -19
- package/dist/node_modules/sharp/lib/operation.js +28 -5
- package/dist/node_modules/sharp/lib/output.js +147 -16
- package/dist/node_modules/sharp/lib/sharp.js +31 -0
- package/dist/node_modules/sharp/lib/utility.js +3 -2
- package/dist/node_modules/sharp/package.json +32 -23
- package/dist/node_modules/sharp/src/common.cc +67 -11
- package/dist/node_modules/sharp/src/common.h +25 -5
- package/dist/node_modules/sharp/src/libvips/cplusplus/VConnection.cpp +0 -26
- package/dist/node_modules/sharp/src/libvips/cplusplus/VImage.cpp +54 -16
- package/dist/node_modules/sharp/src/libvips/cplusplus/VInterpolate.cpp +0 -13
- package/dist/node_modules/sharp/src/libvips/cplusplus/vips-operators.cpp +185 -1
- package/dist/node_modules/sharp/src/metadata.cc +14 -0
- package/dist/node_modules/sharp/src/metadata.h +1 -0
- package/dist/node_modules/sharp/src/operations.cc +29 -3
- package/dist/node_modules/sharp/src/operations.h +13 -2
- package/dist/node_modules/sharp/src/pipeline.cc +103 -35
- package/dist/node_modules/sharp/src/pipeline.h +23 -3
- package/dist/node_modules/sharp/src/utilities.cc +1 -1
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/THIRD-PARTY-NOTICES.md +2 -3
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/lib/libvips-cpp.so.42 +0 -0
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/platform.json +0 -0
- package/dist/node_modules/sharp/vendor/8.11.3/linux-x64/versions.json +30 -0
- package/dist/node_modules/simple-get/.github/dependabot.yml +15 -0
- package/dist/node_modules/simple-get/.github/workflows/ci.yml +23 -0
- package/dist/node_modules/simple-get/README.md +17 -3
- package/dist/node_modules/simple-get/index.js +9 -0
- package/dist/node_modules/simple-get/package.json +27 -13
- package/dist/package-lock.json +51 -51
- package/dist/package.json +9 -9
- package/package.json +10 -10
- package/src/__test__/tile.style.json.test.ts +40 -0
- package/src/__test__/xyz.test.ts +32 -30
- package/src/cli/dump.ts +2 -2
- package/src/index.ts +2 -0
- package/src/routes/esri/rest.ts +90 -0
- package/src/routes/imagery.ts +3 -1
- package/src/routes/response.ts +4 -0
- package/src/routes/tile.json.ts +44 -0
- package/src/routes/tile.style.json.ts +77 -0
- package/src/routes/tile.ts +11 -183
- package/src/routes/tile.wmts.ts +59 -0
- package/src/routes/tile.xyz.ts +30 -0
- package/src/tile.set.raster.ts +4 -1
- package/src/tile.set.vector.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/node_modules/color-name/.eslintrc.json +0 -43
- package/dist/node_modules/color-name/test.js +0 -7
- package/dist/node_modules/node-abi/.travis.yml +0 -17
- package/dist/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -39
- package/dist/node_modules/node-abi/node_modules/semver/LICENSE +0 -15
- package/dist/node_modules/node-abi/node_modules/semver/README.md +0 -412
- package/dist/node_modules/node-abi/node_modules/semver/bin/semver +0 -160
- package/dist/node_modules/node-abi/node_modules/semver/package.json +0 -60
- package/dist/node_modules/node-abi/node_modules/semver/range.bnf +0 -16
- package/dist/node_modules/node-abi/node_modules/semver/semver.js +0 -1483
- package/dist/node_modules/node-addon-api/CHANGELOG.md +0 -722
- package/dist/node_modules/sharp/build/Release/sharp.node +0 -0
- package/dist/node_modules/sharp/vendor/8.10.6/versions.json +0 -31
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const color = require('color');
|
|
4
4
|
const is = require('./is');
|
|
5
|
-
const sharp = require('
|
|
5
|
+
const sharp = require('./sharp');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Extract input options, if any, from an object.
|
|
@@ -34,8 +34,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
34
34
|
throw Error('Input Buffer is empty');
|
|
35
35
|
}
|
|
36
36
|
inputDescriptor.buffer = input;
|
|
37
|
-
} else if (is.
|
|
38
|
-
// Uint8Array or Uint8ClampedArray
|
|
37
|
+
} else if (is.typedArray(input)) {
|
|
39
38
|
if (input.length === 0) {
|
|
40
39
|
throw Error('Input Bit Array is empty');
|
|
41
40
|
}
|
|
@@ -104,6 +103,37 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|
|
104
103
|
inputDescriptor.rawHeight = inputOptions.raw.height;
|
|
105
104
|
inputDescriptor.rawChannels = inputOptions.raw.channels;
|
|
106
105
|
inputDescriptor.rawPremultiplied = !!inputOptions.raw.premultiplied;
|
|
106
|
+
|
|
107
|
+
switch (input.constructor) {
|
|
108
|
+
case Uint8Array:
|
|
109
|
+
case Uint8ClampedArray:
|
|
110
|
+
inputDescriptor.rawDepth = 'uchar';
|
|
111
|
+
break;
|
|
112
|
+
case Int8Array:
|
|
113
|
+
inputDescriptor.rawDepth = 'char';
|
|
114
|
+
break;
|
|
115
|
+
case Uint16Array:
|
|
116
|
+
inputDescriptor.rawDepth = 'ushort';
|
|
117
|
+
break;
|
|
118
|
+
case Int16Array:
|
|
119
|
+
inputDescriptor.rawDepth = 'short';
|
|
120
|
+
break;
|
|
121
|
+
case Uint32Array:
|
|
122
|
+
inputDescriptor.rawDepth = 'uint';
|
|
123
|
+
break;
|
|
124
|
+
case Int32Array:
|
|
125
|
+
inputDescriptor.rawDepth = 'int';
|
|
126
|
+
break;
|
|
127
|
+
case Float32Array:
|
|
128
|
+
inputDescriptor.rawDepth = 'float';
|
|
129
|
+
break;
|
|
130
|
+
case Float64Array:
|
|
131
|
+
inputDescriptor.rawDepth = 'double';
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
inputDescriptor.rawDepth = 'uchar';
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
107
137
|
} else {
|
|
108
138
|
throw new Error('Expected width, height and channels for raw pixel input');
|
|
109
139
|
}
|
|
@@ -271,6 +301,8 @@ function _isStreamInput () {
|
|
|
271
301
|
* - `pagePrimary`: Number of the primary page in a HEIF image
|
|
272
302
|
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
|
273
303
|
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
|
304
|
+
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
|
305
|
+
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
|
274
306
|
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
|
275
307
|
* - `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
|
276
308
|
* - `orientation`: Number value of the EXIF Orientation header, if present
|
|
@@ -356,6 +388,9 @@ function metadata (callback) {
|
|
|
356
388
|
* - `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental)
|
|
357
389
|
* - `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
|
358
390
|
*
|
|
391
|
+
* **Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
|
392
|
+
* written to a buffer in order to run `stats` on the result (see third example).
|
|
393
|
+
*
|
|
359
394
|
* @example
|
|
360
395
|
* const image = sharp(inputJpg);
|
|
361
396
|
* image
|
|
@@ -368,6 +403,13 @@ function metadata (callback) {
|
|
|
368
403
|
* const { entropy, sharpness, dominant } = await sharp(input).stats();
|
|
369
404
|
* const { r, g, b } = dominant;
|
|
370
405
|
*
|
|
406
|
+
* @example
|
|
407
|
+
* const image = sharp(input);
|
|
408
|
+
* // store intermediate result
|
|
409
|
+
* const part = await image.extract(region).toBuffer();
|
|
410
|
+
* // create new instance to obtain statistics of extracted region
|
|
411
|
+
* const stats = await sharp(part).stats();
|
|
412
|
+
*
|
|
371
413
|
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
|
372
414
|
* @returns {Promise<Object>}
|
|
373
415
|
*/
|
|
@@ -49,12 +49,26 @@ const buffer = function (val) {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
* Is this value a Uint8Array or Uint8ClampedArray
|
|
52
|
+
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
|
|
53
53
|
* @private
|
|
54
54
|
*/
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const typedArray = function (val) {
|
|
56
|
+
if (defined(val)) {
|
|
57
|
+
switch (val.constructor) {
|
|
58
|
+
case Uint8Array:
|
|
59
|
+
case Uint8ClampedArray:
|
|
60
|
+
case Int8Array:
|
|
61
|
+
case Uint16Array:
|
|
62
|
+
case Int16Array:
|
|
63
|
+
case Uint32Array:
|
|
64
|
+
case Int32Array:
|
|
65
|
+
case Float32Array:
|
|
66
|
+
case Float64Array:
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return false;
|
|
58
72
|
};
|
|
59
73
|
|
|
60
74
|
/**
|
|
@@ -119,7 +133,7 @@ module.exports = {
|
|
|
119
133
|
fn: fn,
|
|
120
134
|
bool: bool,
|
|
121
135
|
buffer: buffer,
|
|
122
|
-
|
|
136
|
+
typedArray: typedArray,
|
|
123
137
|
string: string,
|
|
124
138
|
number: number,
|
|
125
139
|
integer: integer,
|
|
@@ -21,9 +21,9 @@ const spawnSyncOptions = {
|
|
|
21
21
|
|
|
22
22
|
const mkdirSync = function (dirPath) {
|
|
23
23
|
try {
|
|
24
|
-
fs.mkdirSync(dirPath);
|
|
24
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
25
25
|
} catch (err) {
|
|
26
|
-
/* istanbul ignore
|
|
26
|
+
/* istanbul ignore next */
|
|
27
27
|
if (err.code !== 'EEXIST') {
|
|
28
28
|
throw err;
|
|
29
29
|
}
|
|
@@ -67,23 +67,8 @@ const globalLibvipsVersion = function () {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
const hasVendoredLibvips = function () {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
let vendorPlatformId;
|
|
73
|
-
try {
|
|
74
|
-
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
|
75
|
-
} catch (err) {}
|
|
76
|
-
/* istanbul ignore else */
|
|
77
|
-
if (vendorPlatformId) {
|
|
78
|
-
/* istanbul ignore else */
|
|
79
|
-
if (currentPlatformId === vendorPlatformId) {
|
|
80
|
-
return true;
|
|
81
|
-
} else {
|
|
82
|
-
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the '${currentPlatformId}' platform.`);
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
70
|
+
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platform());
|
|
71
|
+
return fs.existsSync(vendorPath);
|
|
87
72
|
};
|
|
88
73
|
|
|
89
74
|
const pkgConfigPath = function () {
|
|
@@ -325,11 +325,19 @@ function gamma (gamma, gammaOut) {
|
|
|
325
325
|
|
|
326
326
|
/**
|
|
327
327
|
* Produce the "negative" of the image.
|
|
328
|
-
* @param {
|
|
328
|
+
* @param {Object} [options]
|
|
329
|
+
* @param {Boolean} [options.alpha=true] Whether or not to negate any alpha channel
|
|
329
330
|
* @returns {Sharp}
|
|
330
331
|
*/
|
|
331
|
-
function negate (
|
|
332
|
-
this.options.negate = is.bool(
|
|
332
|
+
function negate (options) {
|
|
333
|
+
this.options.negate = is.bool(options) ? options : true;
|
|
334
|
+
if (is.plainObject(options) && 'alpha' in options) {
|
|
335
|
+
if (!is.bool(options.alpha)) {
|
|
336
|
+
throw is.invalidParameterError('alpha', 'should be boolean value', options.alpha);
|
|
337
|
+
} else {
|
|
338
|
+
this.options.negateAlpha = options.alpha;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
333
341
|
return this;
|
|
334
342
|
}
|
|
335
343
|
|
|
@@ -562,14 +570,16 @@ function recomb (inputMatrix) {
|
|
|
562
570
|
}
|
|
563
571
|
|
|
564
572
|
/**
|
|
565
|
-
* Transforms the image using brightness, saturation
|
|
573
|
+
* Transforms the image using brightness, saturation, hue rotation, and lightness.
|
|
574
|
+
* Brightness and lightness both operate on luminance, with the difference being that
|
|
575
|
+
* brightness is multiplicative whereas lightness is additive.
|
|
566
576
|
*
|
|
567
577
|
* @since 0.22.1
|
|
568
578
|
*
|
|
569
579
|
* @example
|
|
570
580
|
* sharp(input)
|
|
571
581
|
* .modulate({
|
|
572
|
-
* brightness: 2 // increase
|
|
582
|
+
* brightness: 2 // increase brightness by a factor of 2
|
|
573
583
|
* });
|
|
574
584
|
*
|
|
575
585
|
* sharp(input)
|
|
@@ -577,6 +587,11 @@ function recomb (inputMatrix) {
|
|
|
577
587
|
* hue: 180 // hue-rotate by 180 degrees
|
|
578
588
|
* });
|
|
579
589
|
*
|
|
590
|
+
* sharp(input)
|
|
591
|
+
* .modulate({
|
|
592
|
+
* lightness: 50 // increase lightness by +50
|
|
593
|
+
* });
|
|
594
|
+
*
|
|
580
595
|
* // decreate brightness and saturation while also hue-rotating by 90 degrees
|
|
581
596
|
* sharp(input)
|
|
582
597
|
* .modulate({
|
|
@@ -589,6 +604,7 @@ function recomb (inputMatrix) {
|
|
|
589
604
|
* @param {number} [options.brightness] Brightness multiplier
|
|
590
605
|
* @param {number} [options.saturation] Saturation multiplier
|
|
591
606
|
* @param {number} [options.hue] Degrees for hue rotation
|
|
607
|
+
* @param {number} [options.lightness] Lightness addend
|
|
592
608
|
* @returns {Sharp}
|
|
593
609
|
*/
|
|
594
610
|
function modulate (options) {
|
|
@@ -616,6 +632,13 @@ function modulate (options) {
|
|
|
616
632
|
throw is.invalidParameterError('hue', 'number', options.hue);
|
|
617
633
|
}
|
|
618
634
|
}
|
|
635
|
+
if ('lightness' in options) {
|
|
636
|
+
if (is.number(options.lightness)) {
|
|
637
|
+
this.options.lightness = options.lightness;
|
|
638
|
+
} else {
|
|
639
|
+
throw is.invalidParameterError('lightness', 'number', options.lightness);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
619
642
|
return this;
|
|
620
643
|
}
|
|
621
644
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
3
4
|
const is = require('./is');
|
|
4
|
-
const sharp = require('
|
|
5
|
+
const sharp = require('./sharp');
|
|
5
6
|
|
|
6
7
|
const formats = new Map([
|
|
7
8
|
['heic', 'heif'],
|
|
@@ -12,11 +13,17 @@ const formats = new Map([
|
|
|
12
13
|
['png', 'png'],
|
|
13
14
|
['raw', 'raw'],
|
|
14
15
|
['tiff', 'tiff'],
|
|
16
|
+
['tif', 'tiff'],
|
|
15
17
|
['webp', 'webp'],
|
|
16
|
-
['gif', 'gif']
|
|
18
|
+
['gif', 'gif'],
|
|
19
|
+
['jp2', 'jp2'],
|
|
20
|
+
['jpx', 'jp2'],
|
|
21
|
+
['j2k', 'jp2'],
|
|
22
|
+
['j2c', 'jp2']
|
|
17
23
|
]);
|
|
18
24
|
|
|
19
25
|
const errMagickSave = new Error('GIF output requires libvips with support for ImageMagick');
|
|
26
|
+
const errJp2Save = new Error('JP2 output requires libvips with support for OpenJPEG');
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* Write output image data to a file.
|
|
@@ -28,6 +35,8 @@ const errMagickSave = new Error('GIF output requires libvips with support for Im
|
|
|
28
35
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
29
36
|
* See {@link withMetadata} for control over this.
|
|
30
37
|
*
|
|
38
|
+
* The caller is responsible for ensuring directory structures and permissions exist.
|
|
39
|
+
*
|
|
31
40
|
* A `Promise` is returned when `callback` is not provided.
|
|
32
41
|
*
|
|
33
42
|
* @example
|
|
@@ -52,7 +61,7 @@ function toFile (fileOut, callback) {
|
|
|
52
61
|
let err;
|
|
53
62
|
if (!is.string(fileOut)) {
|
|
54
63
|
err = new Error('Missing output file path');
|
|
55
|
-
} else if (this.options.input.file === fileOut) {
|
|
64
|
+
} else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
|
|
56
65
|
err = new Error('Cannot use same file for input and output');
|
|
57
66
|
} else if (this.options.formatOut === 'input' && fileOut.toLowerCase().endsWith('.gif') && !this.constructor.format.magick.output.file) {
|
|
58
67
|
err = errMagickSave;
|
|
@@ -403,7 +412,7 @@ function png (options) {
|
|
|
403
412
|
const colours = options.colours || options.colors;
|
|
404
413
|
if (is.defined(colours)) {
|
|
405
414
|
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
|
406
|
-
this.options.
|
|
415
|
+
this.options.pngBitdepth = 1 << 31 - Math.clz32(Math.ceil(Math.log2(colours)));
|
|
407
416
|
} else {
|
|
408
417
|
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
|
409
418
|
}
|
|
@@ -509,6 +518,84 @@ function gif (options) {
|
|
|
509
518
|
return this._updateFormatOut('gif', options);
|
|
510
519
|
}
|
|
511
520
|
|
|
521
|
+
/**
|
|
522
|
+
* Use these JP2 options for output image.
|
|
523
|
+
*
|
|
524
|
+
* Requires libvips compiled with support for OpenJPEG.
|
|
525
|
+
* The prebuilt binaries do not include this - see
|
|
526
|
+
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* // Convert any input to lossless JP2 output
|
|
530
|
+
* const data = await sharp(input)
|
|
531
|
+
* .jp2({ lossless: true })
|
|
532
|
+
* .toBuffer();
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* // Convert any input to very high quality JP2 output
|
|
536
|
+
* const data = await sharp(input)
|
|
537
|
+
* .jp2({
|
|
538
|
+
* quality: 100,
|
|
539
|
+
* chromaSubsampling: '4:4:4'
|
|
540
|
+
* })
|
|
541
|
+
* .toBuffer();
|
|
542
|
+
*
|
|
543
|
+
* @since 0.29.1
|
|
544
|
+
*
|
|
545
|
+
* @param {Object} [options] - output options
|
|
546
|
+
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
547
|
+
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
|
548
|
+
* @param {number} [options.tileWidth=512] - horizontal tile size
|
|
549
|
+
* @param {number} [options.tileHeight=512] - vertical tile size
|
|
550
|
+
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
551
|
+
* @returns {Sharp}
|
|
552
|
+
* @throws {Error} Invalid options
|
|
553
|
+
*/
|
|
554
|
+
/* istanbul ignore next */
|
|
555
|
+
function jp2 (options) {
|
|
556
|
+
if (!this.constructor.format.jp2k.output.buffer) {
|
|
557
|
+
throw errJp2Save;
|
|
558
|
+
}
|
|
559
|
+
if (is.object(options)) {
|
|
560
|
+
if (is.defined(options.quality)) {
|
|
561
|
+
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
|
562
|
+
this.options.jp2Quality = options.quality;
|
|
563
|
+
} else {
|
|
564
|
+
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (is.defined(options.lossless)) {
|
|
568
|
+
if (is.bool(options.lossless)) {
|
|
569
|
+
this.options.jp2Lossless = options.lossless;
|
|
570
|
+
} else {
|
|
571
|
+
throw is.invalidParameterError('lossless', 'boolean', options.lossless);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (is.defined(options.tileWidth)) {
|
|
575
|
+
if (is.integer(options.tileWidth) && is.inRange(options.tileWidth, 1, 32768)) {
|
|
576
|
+
this.options.jp2TileWidth = options.tileWidth;
|
|
577
|
+
} else {
|
|
578
|
+
throw is.invalidParameterError('tileWidth', 'integer between 1 and 32768', options.tileWidth);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (is.defined(options.tileHeight)) {
|
|
582
|
+
if (is.integer(options.tileHeight) && is.inRange(options.tileHeight, 1, 32768)) {
|
|
583
|
+
this.options.jp2TileHeight = options.tileHeight;
|
|
584
|
+
} else {
|
|
585
|
+
throw is.invalidParameterError('tileHeight', 'integer between 1 and 32768', options.tileHeight);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (is.defined(options.chromaSubsampling)) {
|
|
589
|
+
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
|
|
590
|
+
this.options.heifChromaSubsampling = options.chromaSubsampling;
|
|
591
|
+
} else {
|
|
592
|
+
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return this._updateFormatOut('jp2', options);
|
|
597
|
+
}
|
|
598
|
+
|
|
512
599
|
/**
|
|
513
600
|
* Set animation options if available.
|
|
514
601
|
* @private
|
|
@@ -550,6 +637,8 @@ function trySetAnimationOptions (source, target) {
|
|
|
550
637
|
/**
|
|
551
638
|
* Use these TIFF options for output image.
|
|
552
639
|
*
|
|
640
|
+
* The `density` can be set in pixels/inch via {@link withMetadata} instead of providing `xres` and `yres` in pixels/mm.
|
|
641
|
+
*
|
|
553
642
|
* @example
|
|
554
643
|
* // Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
|
555
644
|
* sharp('input.svg')
|
|
@@ -654,13 +743,15 @@ function tiff (options) {
|
|
|
654
743
|
* Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
|
655
744
|
* most web browsers do not display these properly.
|
|
656
745
|
*
|
|
746
|
+
* AVIF image sequences are not supported.
|
|
747
|
+
*
|
|
657
748
|
* @since 0.27.0
|
|
658
749
|
*
|
|
659
750
|
* @param {Object} [options] - output options
|
|
660
751
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
|
661
752
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
662
|
-
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to
|
|
663
|
-
* @param {string} [options.chromaSubsampling='4:
|
|
753
|
+
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 9 (fastest/largest)
|
|
754
|
+
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
664
755
|
* @returns {Sharp}
|
|
665
756
|
* @throws {Error} Invalid options
|
|
666
757
|
*/
|
|
@@ -680,8 +771,8 @@ function avif (options) {
|
|
|
680
771
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
|
681
772
|
* @param {string} [options.compression='av1'] - compression format: av1, hevc
|
|
682
773
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
683
|
-
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to
|
|
684
|
-
* @param {string} [options.chromaSubsampling='4:
|
|
774
|
+
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 9 (fastest/largest)
|
|
775
|
+
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
685
776
|
* @returns {Sharp}
|
|
686
777
|
* @throws {Error} Invalid options
|
|
687
778
|
*/
|
|
@@ -709,10 +800,10 @@ function heif (options) {
|
|
|
709
800
|
}
|
|
710
801
|
}
|
|
711
802
|
if (is.defined(options.speed)) {
|
|
712
|
-
if (is.integer(options.speed) && is.inRange(options.speed, 0,
|
|
803
|
+
if (is.integer(options.speed) && is.inRange(options.speed, 0, 9)) {
|
|
713
804
|
this.options.heifSpeed = options.speed;
|
|
714
805
|
} else {
|
|
715
|
-
throw is.invalidParameterError('speed', 'integer between 0 and
|
|
806
|
+
throw is.invalidParameterError('speed', 'integer between 0 and 9', options.speed);
|
|
716
807
|
}
|
|
717
808
|
}
|
|
718
809
|
if (is.defined(options.chromaSubsampling)) {
|
|
@@ -727,28 +818,41 @@ function heif (options) {
|
|
|
727
818
|
}
|
|
728
819
|
|
|
729
820
|
/**
|
|
730
|
-
* Force output to be raw, uncompressed
|
|
821
|
+
* Force output to be raw, uncompressed pixel data.
|
|
731
822
|
* Pixel ordering is left-to-right, top-to-bottom, without padding.
|
|
732
823
|
* Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
|
733
824
|
*
|
|
734
825
|
* @example
|
|
735
|
-
* // Extract raw RGB pixel data from JPEG input
|
|
826
|
+
* // Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
|
736
827
|
* const { data, info } = await sharp('input.jpg')
|
|
737
828
|
* .raw()
|
|
738
829
|
* .toBuffer({ resolveWithObject: true });
|
|
739
830
|
*
|
|
740
831
|
* @example
|
|
741
|
-
* // Extract alpha channel as raw pixel data from PNG input
|
|
832
|
+
* // Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
|
742
833
|
* const data = await sharp('input.png')
|
|
743
834
|
* .ensureAlpha()
|
|
744
835
|
* .extractChannel(3)
|
|
745
836
|
* .toColourspace('b-w')
|
|
746
|
-
* .raw()
|
|
837
|
+
* .raw({ depth: 'ushort' })
|
|
747
838
|
* .toBuffer();
|
|
748
839
|
*
|
|
749
|
-
* @
|
|
840
|
+
* @param {Object} [options] - output options
|
|
841
|
+
* @param {string} [options.depth='uchar'] - bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex
|
|
842
|
+
* @throws {Error} Invalid options
|
|
750
843
|
*/
|
|
751
|
-
function raw () {
|
|
844
|
+
function raw (options) {
|
|
845
|
+
if (is.object(options)) {
|
|
846
|
+
if (is.defined(options.depth)) {
|
|
847
|
+
if (is.string(options.depth) && is.inArray(options.depth,
|
|
848
|
+
['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'float', 'complex', 'double', 'dpcomplex']
|
|
849
|
+
)) {
|
|
850
|
+
this.options.rawDepth = options.depth;
|
|
851
|
+
} else {
|
|
852
|
+
throw is.invalidParameterError('depth', 'one of: char, uchar, short, ushort, int, uint, float, complex, double, dpcomplex', options.depth);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
752
856
|
return this._updateFormatOut('raw');
|
|
753
857
|
}
|
|
754
858
|
|
|
@@ -873,6 +977,31 @@ function tile (options) {
|
|
|
873
977
|
return this._updateFormatOut('dz');
|
|
874
978
|
}
|
|
875
979
|
|
|
980
|
+
/**
|
|
981
|
+
* Set a timeout for processing, in seconds.
|
|
982
|
+
* Use a value of zero to continue processing indefinitely, the default behaviour.
|
|
983
|
+
*
|
|
984
|
+
* The clock starts when libvips opens an input image for processing.
|
|
985
|
+
* Time spent waiting for a libuv thread to become available is not included.
|
|
986
|
+
*
|
|
987
|
+
* @since 0.29.2
|
|
988
|
+
*
|
|
989
|
+
* @param {Object} options
|
|
990
|
+
* @param {number} options.seconds - Number of seconds after which processing will be stopped
|
|
991
|
+
* @returns {Sharp}
|
|
992
|
+
*/
|
|
993
|
+
function timeout (options) {
|
|
994
|
+
if (!is.plainObject(options)) {
|
|
995
|
+
throw is.invalidParameterError('options', 'object', options);
|
|
996
|
+
}
|
|
997
|
+
if (is.integer(options.seconds) && is.inRange(options.seconds, 0, 3600)) {
|
|
998
|
+
this.options.timeoutSeconds = options.seconds;
|
|
999
|
+
} else {
|
|
1000
|
+
throw is.invalidParameterError('seconds', 'integer between 0 and 3600', options.seconds);
|
|
1001
|
+
}
|
|
1002
|
+
return this;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
876
1005
|
/**
|
|
877
1006
|
* Update the output format unless options.force is false,
|
|
878
1007
|
* in which case revert to input format.
|
|
@@ -1018,6 +1147,7 @@ module.exports = function (Sharp) {
|
|
|
1018
1147
|
withMetadata,
|
|
1019
1148
|
toFormat,
|
|
1020
1149
|
jpeg,
|
|
1150
|
+
jp2,
|
|
1021
1151
|
png,
|
|
1022
1152
|
webp,
|
|
1023
1153
|
tiff,
|
|
@@ -1026,6 +1156,7 @@ module.exports = function (Sharp) {
|
|
|
1026
1156
|
gif,
|
|
1027
1157
|
raw,
|
|
1028
1158
|
tile,
|
|
1159
|
+
timeout,
|
|
1029
1160
|
// Private
|
|
1030
1161
|
_updateFormatOut,
|
|
1031
1162
|
_setBooleanOption,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const platformAndArch = require('./platform')();
|
|
4
|
+
|
|
5
|
+
/* istanbul ignore next */
|
|
6
|
+
try {
|
|
7
|
+
module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
// Bail early if bindings aren't available
|
|
10
|
+
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, '', 'Possible solutions:'];
|
|
11
|
+
if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
|
|
12
|
+
help.push('- Update Homebrew: "brew update && brew upgrade vips"');
|
|
13
|
+
} else {
|
|
14
|
+
help.push(
|
|
15
|
+
'- Install with the --verbose flag and look for errors: "npm install --ignore-scripts=false --verbose sharp"',
|
|
16
|
+
`- Install for the current runtime: "npm install --platform=${process.platform} --arch=${process.arch} sharp"`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
help.push(
|
|
20
|
+
'- Consult the installation documentation: https://sharp.pixelplumbing.com/install'
|
|
21
|
+
);
|
|
22
|
+
// Check loaded
|
|
23
|
+
if (process.platform === 'win32') {
|
|
24
|
+
const loadedModule = Object.keys(require.cache).find((i) => /[\\/]build[\\/]Release[\\/]sharp(.*)\.node$/.test(i));
|
|
25
|
+
if (loadedModule) {
|
|
26
|
+
const [, loadedPackage] = loadedModule.match(/node_modules[\\/]([^\\/]+)[\\/]/);
|
|
27
|
+
help.push(`- Ensure the version of sharp aligns with the ${loadedPackage} package: "npm ls sharp"`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error(help.join('\n'));
|
|
31
|
+
}
|
|
@@ -4,7 +4,8 @@ const events = require('events');
|
|
|
4
4
|
const detectLibc = require('detect-libc');
|
|
5
5
|
|
|
6
6
|
const is = require('./is');
|
|
7
|
-
const
|
|
7
|
+
const platformAndArch = require('./platform')();
|
|
8
|
+
const sharp = require('./sharp');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* An Object containing nested boolean values representing the available input and output formats/methods.
|
|
@@ -45,7 +46,7 @@ let versions = {
|
|
|
45
46
|
vips: sharp.libvipsVersion()
|
|
46
47
|
};
|
|
47
48
|
try {
|
|
48
|
-
versions = require(`../vendor/${versions.vips}/versions.json`);
|
|
49
|
+
versions = require(`../vendor/${versions.vips}/${platformAndArch}/versions.json`);
|
|
49
50
|
} catch (err) {}
|
|
50
51
|
|
|
51
52
|
/**
|