@revizly/sharp 0.34.5-revizly3 → 0.35.0-revizly1
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/lib/channel.js +2 -2
- package/lib/colour.js +4 -4
- package/lib/composite.js +4 -4
- package/lib/constructor.js +5 -3
- package/lib/index.d.ts +13 -8
- package/lib/input.js +5 -5
- package/lib/is.js +15 -41
- package/lib/operation.js +5 -7
- package/lib/output.js +16 -9
- package/lib/resize.js +1 -1
- package/lib/utility.js +2 -2
- package/package.json +7 -13
- package/src/binding.gyp +1 -1
- package/src/common.h +3 -3
- package/src/metadata.cc +6 -6
- package/src/pipeline.cc +13 -26
package/lib/channel.js
CHANGED
|
@@ -18,7 +18,7 @@ const bool = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Remove alpha channels, if any. This is a no-op if the image does not have an alpha channel.
|
|
20
20
|
*
|
|
21
|
-
* See also {@link /api-operation
|
|
21
|
+
* See also {@link /api-operation/#flatten flatten}.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* sharp('rgba.png')
|
|
@@ -163,7 +163,7 @@ function bandbool (boolOp) {
|
|
|
163
163
|
* @module Sharp
|
|
164
164
|
* @private
|
|
165
165
|
*/
|
|
166
|
-
module.exports =
|
|
166
|
+
module.exports = (Sharp) => {
|
|
167
167
|
Object.assign(Sharp.prototype, {
|
|
168
168
|
// Public instance functions
|
|
169
169
|
removeAlpha,
|
package/lib/colour.js
CHANGED
|
@@ -69,7 +69,7 @@ function grayscale (grayscale) {
|
|
|
69
69
|
*
|
|
70
70
|
* The input image will be converted to the provided colourspace at the start of the pipeline.
|
|
71
71
|
* All operations will use this colourspace before converting to the output colourspace,
|
|
72
|
-
* as defined by {@link #tocolourspace
|
|
72
|
+
* as defined by {@link #tocolourspace toColourspace}.
|
|
73
73
|
*
|
|
74
74
|
* @since 0.29.0
|
|
75
75
|
*
|
|
@@ -80,7 +80,7 @@ function grayscale (grayscale) {
|
|
|
80
80
|
* .toColourspace('srgb')
|
|
81
81
|
* .toFile('16bpc-pipeline-to-8bpc-output.png')
|
|
82
82
|
*
|
|
83
|
-
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://
|
|
83
|
+
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://www.libvips.org/API/current/enum.Interpretation.html)
|
|
84
84
|
* @returns {Sharp}
|
|
85
85
|
* @throws {Error} Invalid parameters
|
|
86
86
|
*/
|
|
@@ -112,7 +112,7 @@ function pipelineColorspace (colorspace) {
|
|
|
112
112
|
* .toColourspace('rgb16')
|
|
113
113
|
* .toFile('16-bpp.png')
|
|
114
114
|
*
|
|
115
|
-
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://
|
|
115
|
+
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/enum.Interpretation.html)
|
|
116
116
|
* @returns {Sharp}
|
|
117
117
|
* @throws {Error} Invalid parameters
|
|
118
118
|
*/
|
|
@@ -175,7 +175,7 @@ function _setBackgroundColourOption (key, value) {
|
|
|
175
175
|
* @module Sharp
|
|
176
176
|
* @private
|
|
177
177
|
*/
|
|
178
|
-
module.exports =
|
|
178
|
+
module.exports = (Sharp) => {
|
|
179
179
|
Object.assign(Sharp.prototype, {
|
|
180
180
|
// Public
|
|
181
181
|
tint,
|
package/lib/composite.js
CHANGED
|
@@ -56,7 +56,7 @@ const blend = {
|
|
|
56
56
|
* `hard-light`, `soft-light`, `difference`, `exclusion`.
|
|
57
57
|
*
|
|
58
58
|
* More information about blend modes can be found at
|
|
59
|
-
* https://www.libvips.org/API/current/
|
|
59
|
+
* https://www.libvips.org/API/current/enum.BlendMode.html
|
|
60
60
|
* and https://www.cairographics.org/operators/
|
|
61
61
|
*
|
|
62
62
|
* @since 0.22.0
|
|
@@ -123,8 +123,8 @@ const blend = {
|
|
|
123
123
|
* @param {Number} [images[].raw.height]
|
|
124
124
|
* @param {Number} [images[].raw.channels]
|
|
125
125
|
* @param {boolean} [images[].animated=false] - Set to `true` to read all frames/pages of an animated image.
|
|
126
|
-
* @param {string} [images[].failOn='warning'] - @see {@link /api-constructor
|
|
127
|
-
* @param {number|boolean} [images[].limitInputPixels=268402689] - @see {@link /api-constructor
|
|
126
|
+
* @param {string} [images[].failOn='warning'] - @see {@link /api-constructor/ constructor parameters}
|
|
127
|
+
* @param {number|boolean} [images[].limitInputPixels=268402689] - @see {@link /api-constructor/ constructor parameters}
|
|
128
128
|
* @returns {Sharp}
|
|
129
129
|
* @throws {Error} Invalid parameters
|
|
130
130
|
*/
|
|
@@ -206,7 +206,7 @@ function composite (images) {
|
|
|
206
206
|
* @module Sharp
|
|
207
207
|
* @private
|
|
208
208
|
*/
|
|
209
|
-
module.exports =
|
|
209
|
+
module.exports = (Sharp) => {
|
|
210
210
|
Sharp.prototype.composite = composite;
|
|
211
211
|
Sharp.blend = blend;
|
|
212
212
|
};
|
package/lib/constructor.js
CHANGED
|
@@ -12,6 +12,10 @@ require('./sharp');
|
|
|
12
12
|
// Use NODE_DEBUG=sharp to enable libvips warnings
|
|
13
13
|
const debuglog = util.debuglog('sharp');
|
|
14
14
|
|
|
15
|
+
const queueListener = (queueLength) => {
|
|
16
|
+
Sharp.queue.emit('change', queueLength);
|
|
17
|
+
};
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
|
17
21
|
*
|
|
@@ -398,9 +402,7 @@ const Sharp = function (input, options) {
|
|
|
398
402
|
debuglog(warning);
|
|
399
403
|
},
|
|
400
404
|
// Function to notify of queue length changes
|
|
401
|
-
queueListener
|
|
402
|
-
Sharp.queue.emit('change', queueLength);
|
|
403
|
-
}
|
|
405
|
+
queueListener
|
|
404
406
|
};
|
|
405
407
|
this.options.input = this._createInputDescriptor(input, options, { allowStream: true });
|
|
406
408
|
return this;
|
package/lib/index.d.ts
CHANGED
|
@@ -860,6 +860,7 @@ declare namespace sharp {
|
|
|
860
860
|
| JxlOptions
|
|
861
861
|
| GifOptions
|
|
862
862
|
| Jp2Options
|
|
863
|
+
| RawOptions
|
|
863
864
|
| TiffOptions,
|
|
864
865
|
): Sharp;
|
|
865
866
|
|
|
@@ -1027,11 +1028,11 @@ declare namespace sharp {
|
|
|
1027
1028
|
openSlide?: OpenSlideInputOptions | undefined;
|
|
1028
1029
|
/** JPEG 2000 specific input options */
|
|
1029
1030
|
jp2?: Jp2InputOptions | undefined;
|
|
1030
|
-
/**
|
|
1031
|
+
/** @deprecated Use {@link SharpOptions.tiff} instead */
|
|
1031
1032
|
subifd?: number | undefined;
|
|
1032
|
-
/**
|
|
1033
|
+
/** @deprecated Use {@link SharpOptions.pdf} instead */
|
|
1033
1034
|
pdfBackground?: Colour | Color | undefined;
|
|
1034
|
-
/**
|
|
1035
|
+
/** @deprecated Use {@link SharpOptions.openSlide} instead */
|
|
1035
1036
|
level?: number | undefined;
|
|
1036
1037
|
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
|
|
1037
1038
|
animated?: boolean | undefined;
|
|
@@ -1181,6 +1182,10 @@ declare namespace sharp {
|
|
|
1181
1182
|
'IFD3'?: ExifDir;
|
|
1182
1183
|
}
|
|
1183
1184
|
|
|
1185
|
+
type HeifCompression = 'av1' | 'hevc';
|
|
1186
|
+
|
|
1187
|
+
type Unit = 'inch' | 'cm';
|
|
1188
|
+
|
|
1184
1189
|
interface WriteableMetadata {
|
|
1185
1190
|
/** Number of pixels per inch (DPI) */
|
|
1186
1191
|
density?: number | undefined;
|
|
@@ -1259,7 +1264,7 @@ declare namespace sharp {
|
|
|
1259
1264
|
/** Buffer containing raw TIFFTAG_PHOTOSHOP data, if present */
|
|
1260
1265
|
tifftagPhotoshop?: Buffer | undefined;
|
|
1261
1266
|
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
|
1262
|
-
compression?:
|
|
1267
|
+
compression?: HeifCompression | undefined;
|
|
1263
1268
|
/** Default background colour, if present, for PNG (bKGD) and GIF images */
|
|
1264
1269
|
background?: { r: number; g: number; b: number } | { gray: number };
|
|
1265
1270
|
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
|
|
@@ -1267,7 +1272,7 @@ declare namespace sharp {
|
|
|
1267
1272
|
/** Number of Sub Image File Directories in an OME-TIFF image */
|
|
1268
1273
|
subifds?: number | undefined;
|
|
1269
1274
|
/** The unit of resolution (density) */
|
|
1270
|
-
resolutionUnit?:
|
|
1275
|
+
resolutionUnit?: Unit | undefined;
|
|
1271
1276
|
/** String containing format for images loaded via *magick */
|
|
1272
1277
|
formatMagick?: string | undefined;
|
|
1273
1278
|
/** Array of keyword/text pairs representing PNG text blocks, if present. */
|
|
@@ -1423,7 +1428,7 @@ declare namespace sharp {
|
|
|
1423
1428
|
/** quality, integer 1-100 (optional, default 50) */
|
|
1424
1429
|
quality?: number | undefined;
|
|
1425
1430
|
/** compression format: av1, hevc (optional, default 'av1') */
|
|
1426
|
-
compression?:
|
|
1431
|
+
compression?: HeifCompression | undefined;
|
|
1427
1432
|
/** use lossless compression (optional, default false) */
|
|
1428
1433
|
lossless?: boolean | undefined;
|
|
1429
1434
|
/** Level of CPU effort to reduce file size, between 0 (fastest) and 9 (slowest) (optional, default 4) */
|
|
@@ -1481,7 +1486,7 @@ declare namespace sharp {
|
|
|
1481
1486
|
/** Write 1-bit images as miniswhite (optional, default false) */
|
|
1482
1487
|
miniswhite?: boolean | undefined;
|
|
1483
1488
|
/** Resolution unit options: inch, cm (optional, default 'inch') */
|
|
1484
|
-
resolutionUnit?:
|
|
1489
|
+
resolutionUnit?: Unit | undefined;
|
|
1485
1490
|
}
|
|
1486
1491
|
|
|
1487
1492
|
interface PngOptions extends OutputOptions {
|
|
@@ -1606,7 +1611,7 @@ declare namespace sharp {
|
|
|
1606
1611
|
}
|
|
1607
1612
|
|
|
1608
1613
|
interface RawOptions {
|
|
1609
|
-
depth?:
|
|
1614
|
+
depth?: keyof DepthEnum;
|
|
1610
1615
|
}
|
|
1611
1616
|
|
|
1612
1617
|
/** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
|
package/lib/input.js
CHANGED
|
@@ -570,17 +570,17 @@ function _isStreamInput () {
|
|
|
570
570
|
* such as resize or rotate.
|
|
571
571
|
*
|
|
572
572
|
* Dimensions in the response will respect the `page` and `pages` properties of the
|
|
573
|
-
* {@link /api-constructor
|
|
573
|
+
* {@link /api-constructor/ constructor parameters}.
|
|
574
574
|
*
|
|
575
575
|
* A `Promise` is returned when `callback` is not provided.
|
|
576
576
|
*
|
|
577
|
-
* - `format`: Name of decoder used to
|
|
577
|
+
* - `format`: Name of decoder used to parse image e.g. `jpeg`, `png`, `webp`, `gif`, `svg`, `heif`, `tiff`
|
|
578
578
|
* - `size`: Total size of image in bytes, for Stream and Buffer input only
|
|
579
579
|
* - `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
|
|
580
580
|
* - `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
|
|
581
|
-
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/
|
|
581
|
+
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/enum.Interpretation.html)
|
|
582
582
|
* - `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
|
583
|
-
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/
|
|
583
|
+
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/enum.BandFormat.html)
|
|
584
584
|
* - `density`: Number of pixels per inch (DPI), if present
|
|
585
585
|
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
|
586
586
|
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
|
@@ -792,7 +792,7 @@ function stats (callback) {
|
|
|
792
792
|
* @module Sharp
|
|
793
793
|
* @private
|
|
794
794
|
*/
|
|
795
|
-
module.exports =
|
|
795
|
+
module.exports = (Sharp) => {
|
|
796
796
|
Object.assign(Sharp.prototype, {
|
|
797
797
|
// Private
|
|
798
798
|
_inputOptionsFromObject,
|
package/lib/is.js
CHANGED
|
@@ -7,55 +7,43 @@
|
|
|
7
7
|
* Is this value defined and not null?
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
|
-
const defined =
|
|
11
|
-
return typeof val !== 'undefined' && val !== null;
|
|
12
|
-
};
|
|
10
|
+
const defined = (val) => typeof val !== 'undefined' && val !== null;
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Is this value an object?
|
|
16
14
|
* @private
|
|
17
15
|
*/
|
|
18
|
-
const object =
|
|
19
|
-
return typeof val === 'object';
|
|
20
|
-
};
|
|
16
|
+
const object = (val) => typeof val === 'object';
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* Is this value a plain object?
|
|
24
20
|
* @private
|
|
25
21
|
*/
|
|
26
|
-
const plainObject =
|
|
27
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
28
|
-
};
|
|
22
|
+
const plainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
|
|
29
23
|
|
|
30
24
|
/**
|
|
31
25
|
* Is this value a function?
|
|
32
26
|
* @private
|
|
33
27
|
*/
|
|
34
|
-
const fn =
|
|
35
|
-
return typeof val === 'function';
|
|
36
|
-
};
|
|
28
|
+
const fn = (val) => typeof val === 'function';
|
|
37
29
|
|
|
38
30
|
/**
|
|
39
31
|
* Is this value a boolean?
|
|
40
32
|
* @private
|
|
41
33
|
*/
|
|
42
|
-
const bool =
|
|
43
|
-
return typeof val === 'boolean';
|
|
44
|
-
};
|
|
34
|
+
const bool = (val) => typeof val === 'boolean';
|
|
45
35
|
|
|
46
36
|
/**
|
|
47
37
|
* Is this value a Buffer object?
|
|
48
38
|
* @private
|
|
49
39
|
*/
|
|
50
|
-
const buffer =
|
|
51
|
-
return val instanceof Buffer;
|
|
52
|
-
};
|
|
40
|
+
const buffer = (val) => val instanceof Buffer;
|
|
53
41
|
|
|
54
42
|
/**
|
|
55
43
|
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
|
|
56
44
|
* @private
|
|
57
45
|
*/
|
|
58
|
-
const typedArray =
|
|
46
|
+
const typedArray = (val) => {
|
|
59
47
|
if (defined(val)) {
|
|
60
48
|
switch (val.constructor) {
|
|
61
49
|
case Uint8Array:
|
|
@@ -78,49 +66,37 @@ const typedArray = function (val) {
|
|
|
78
66
|
* Is this value an ArrayBuffer object?
|
|
79
67
|
* @private
|
|
80
68
|
*/
|
|
81
|
-
const arrayBuffer =
|
|
82
|
-
return val instanceof ArrayBuffer;
|
|
83
|
-
};
|
|
69
|
+
const arrayBuffer = (val) => val instanceof ArrayBuffer;
|
|
84
70
|
|
|
85
71
|
/**
|
|
86
72
|
* Is this value a non-empty string?
|
|
87
73
|
* @private
|
|
88
74
|
*/
|
|
89
|
-
const string =
|
|
90
|
-
return typeof val === 'string' && val.length > 0;
|
|
91
|
-
};
|
|
75
|
+
const string = (val) => typeof val === 'string' && val.length > 0;
|
|
92
76
|
|
|
93
77
|
/**
|
|
94
78
|
* Is this value a real number?
|
|
95
79
|
* @private
|
|
96
80
|
*/
|
|
97
|
-
const number =
|
|
98
|
-
return typeof val === 'number' && !Number.isNaN(val);
|
|
99
|
-
};
|
|
81
|
+
const number = (val) => typeof val === 'number' && !Number.isNaN(val);
|
|
100
82
|
|
|
101
83
|
/**
|
|
102
84
|
* Is this value an integer?
|
|
103
85
|
* @private
|
|
104
86
|
*/
|
|
105
|
-
const integer =
|
|
106
|
-
return Number.isInteger(val);
|
|
107
|
-
};
|
|
87
|
+
const integer = (val) => Number.isInteger(val);
|
|
108
88
|
|
|
109
89
|
/**
|
|
110
90
|
* Is this value within an inclusive given range?
|
|
111
91
|
* @private
|
|
112
92
|
*/
|
|
113
|
-
const inRange =
|
|
114
|
-
return val >= min && val <= max;
|
|
115
|
-
};
|
|
93
|
+
const inRange = (val, min, max) => val >= min && val <= max;
|
|
116
94
|
|
|
117
95
|
/**
|
|
118
96
|
* Is this value within the elements of an array?
|
|
119
97
|
* @private
|
|
120
98
|
*/
|
|
121
|
-
const inArray =
|
|
122
|
-
return list.includes(val);
|
|
123
|
-
};
|
|
99
|
+
const inArray = (val, list) => list.includes(val);
|
|
124
100
|
|
|
125
101
|
/**
|
|
126
102
|
* Create an Error with a message relating to an invalid parameter.
|
|
@@ -131,11 +107,9 @@ const inArray = function (val, list) {
|
|
|
131
107
|
* @returns {Error} Containing the formatted message.
|
|
132
108
|
* @private
|
|
133
109
|
*/
|
|
134
|
-
const invalidParameterError =
|
|
135
|
-
return new Error(
|
|
110
|
+
const invalidParameterError = (name, expected, actual) => new Error(
|
|
136
111
|
`Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
|
|
137
112
|
);
|
|
138
|
-
};
|
|
139
113
|
|
|
140
114
|
/**
|
|
141
115
|
* Ensures an Error from C++ contains a JS stack.
|
|
@@ -145,7 +119,7 @@ const invalidParameterError = function (name, expected, actual) {
|
|
|
145
119
|
* @returns {Error} Error with message and stack.
|
|
146
120
|
* @private
|
|
147
121
|
*/
|
|
148
|
-
const nativeError =
|
|
122
|
+
const nativeError = (native, context) => {
|
|
149
123
|
context.message = native.message;
|
|
150
124
|
return context;
|
|
151
125
|
};
|
package/lib/operation.js
CHANGED
|
@@ -239,7 +239,7 @@ function affine (matrix, options) {
|
|
|
239
239
|
* When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
|
240
240
|
* Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
|
|
241
241
|
*
|
|
242
|
-
* See {@link https://www.libvips.org/API/current/
|
|
242
|
+
* See {@link https://www.libvips.org/API/current/method.Image.sharpen.html libvips sharpen} operation.
|
|
243
243
|
*
|
|
244
244
|
* @example
|
|
245
245
|
* const data = await sharp(input).sharpen().toBuffer();
|
|
@@ -485,7 +485,7 @@ function erode (width) {
|
|
|
485
485
|
/**
|
|
486
486
|
* Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
|
487
487
|
*
|
|
488
|
-
* See also {@link /api-channel#removealpha
|
|
488
|
+
* See also {@link /api-channel#removealpha removeAlpha}.
|
|
489
489
|
*
|
|
490
490
|
* @example
|
|
491
491
|
* await sharp(rgbaInput)
|
|
@@ -660,7 +660,7 @@ function normalize (options) {
|
|
|
660
660
|
|
|
661
661
|
/**
|
|
662
662
|
* Perform contrast limiting adaptive histogram equalization
|
|
663
|
-
* {@link https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
|
|
663
|
+
* {@link https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE CLAHE}.
|
|
664
664
|
*
|
|
665
665
|
* This will, in general, enhance the clarity of the image by bringing out darker details.
|
|
666
666
|
*
|
|
@@ -742,9 +742,7 @@ function convolve (kernel) {
|
|
|
742
742
|
}
|
|
743
743
|
// Default scale is sum of kernel values
|
|
744
744
|
if (!is.integer(kernel.scale)) {
|
|
745
|
-
kernel.scale = kernel.kernel.reduce(
|
|
746
|
-
return a + b;
|
|
747
|
-
}, 0);
|
|
745
|
+
kernel.scale = kernel.kernel.reduce((a, b) => a + b, 0);
|
|
748
746
|
}
|
|
749
747
|
// Clip scale to a minimum value of 1
|
|
750
748
|
if (kernel.scale < 1) {
|
|
@@ -989,7 +987,7 @@ function modulate (options) {
|
|
|
989
987
|
* @module Sharp
|
|
990
988
|
* @private
|
|
991
989
|
*/
|
|
992
|
-
module.exports =
|
|
990
|
+
module.exports = (Sharp) => {
|
|
993
991
|
Object.assign(Sharp.prototype, {
|
|
994
992
|
autoOrient,
|
|
995
993
|
rotate,
|
package/lib/output.js
CHANGED
|
@@ -43,7 +43,7 @@ const bitdepthFromColourCount = (colours) => 1 << 31 - Math.clz32(Math.ceil(Math
|
|
|
43
43
|
* Note that raw pixel data is only supported for buffer output.
|
|
44
44
|
*
|
|
45
45
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
46
|
-
* See {@link #withmetadata
|
|
46
|
+
* See {@link #withmetadata withMetadata} for control over this.
|
|
47
47
|
*
|
|
48
48
|
* The caller is responsible for ensuring directory structures and permissions exist.
|
|
49
49
|
*
|
|
@@ -97,12 +97,12 @@ function toFile (fileOut, callback) {
|
|
|
97
97
|
* Write output to a Buffer.
|
|
98
98
|
* JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.
|
|
99
99
|
*
|
|
100
|
-
* Use {@link #toformat
|
|
100
|
+
* Use {@link #toformat toFormat} or one of the format-specific functions such as {@link #jpeg jpeg}, {@link #png png} etc. to set the output format.
|
|
101
101
|
*
|
|
102
102
|
* If no explicit format is set, the output format will match the input image, except SVG input which becomes PNG output.
|
|
103
103
|
*
|
|
104
104
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
105
|
-
* See {@link #withmetadata
|
|
105
|
+
* See {@link #withmetadata withMetadata} for control over this.
|
|
106
106
|
*
|
|
107
107
|
* `callback`, if present, gets three arguments `(err, data, info)` where:
|
|
108
108
|
* - `err` is an error, if any.
|
|
@@ -256,7 +256,7 @@ function withExifMerge (exif) {
|
|
|
256
256
|
/**
|
|
257
257
|
* Keep ICC profile from the input image in the output image.
|
|
258
258
|
*
|
|
259
|
-
*
|
|
259
|
+
* When input and output colour spaces differ, use with {@link /api-colour/#tocolourspace toColourspace} and optionally {@link /api-colour/#pipelinecolourspace pipelineColourspace}.
|
|
260
260
|
*
|
|
261
261
|
* @since 0.33.0
|
|
262
262
|
*
|
|
@@ -265,6 +265,13 @@ function withExifMerge (exif) {
|
|
|
265
265
|
* .keepIccProfile()
|
|
266
266
|
* .toBuffer();
|
|
267
267
|
*
|
|
268
|
+
* @example
|
|
269
|
+
* const cmykOutputWithIccProfile = await sharp(cmykInputWithIccProfile)
|
|
270
|
+
* .pipelineColourspace('cmyk')
|
|
271
|
+
* .toColourspace('cmyk')
|
|
272
|
+
* .keepIccProfile()
|
|
273
|
+
* .toBuffer();
|
|
274
|
+
*
|
|
268
275
|
* @returns {Sharp}
|
|
269
276
|
*/
|
|
270
277
|
function keepIccProfile () {
|
|
@@ -565,7 +572,7 @@ function jpeg (options) {
|
|
|
565
572
|
* Set `palette` to `true` for slower, indexed PNG output.
|
|
566
573
|
*
|
|
567
574
|
* For 16 bits per pixel output, convert to `rgb16` via
|
|
568
|
-
* {@link /api-colour
|
|
575
|
+
* {@link /api-colour/#tocolourspace toColourspace}.
|
|
569
576
|
*
|
|
570
577
|
* @example
|
|
571
578
|
* // Convert any input to full colour PNG output
|
|
@@ -850,7 +857,7 @@ function gif (options) {
|
|
|
850
857
|
*
|
|
851
858
|
* Requires libvips compiled with support for OpenJPEG.
|
|
852
859
|
* The prebuilt binaries do not include this - see
|
|
853
|
-
* {@link
|
|
860
|
+
* {@link /install#custom-libvips installing a custom libvips}.
|
|
854
861
|
*
|
|
855
862
|
* @example
|
|
856
863
|
* // Convert any input to lossless JP2 output
|
|
@@ -959,7 +966,7 @@ function trySetAnimationOptions (source, target) {
|
|
|
959
966
|
/**
|
|
960
967
|
* Use these TIFF options for output image.
|
|
961
968
|
*
|
|
962
|
-
* The `density` can be set in pixels/inch via {@link #withmetadata
|
|
969
|
+
* The `density` can be set in pixels/inch via {@link #withmetadata withMetadata}
|
|
963
970
|
* instead of providing `xres` and `yres` in pixels/mm.
|
|
964
971
|
*
|
|
965
972
|
* @example
|
|
@@ -1194,7 +1201,7 @@ function heif (options) {
|
|
|
1194
1201
|
*
|
|
1195
1202
|
* Requires libvips compiled with support for libjxl.
|
|
1196
1203
|
* The prebuilt binaries do not include this - see
|
|
1197
|
-
* {@link
|
|
1204
|
+
* {@link /install/#custom-libvips installing a custom libvips}.
|
|
1198
1205
|
*
|
|
1199
1206
|
* @since 0.31.3
|
|
1200
1207
|
*
|
|
@@ -1623,7 +1630,7 @@ function _pipeline (callback, stack) {
|
|
|
1623
1630
|
* @module Sharp
|
|
1624
1631
|
* @private
|
|
1625
1632
|
*/
|
|
1626
|
-
module.exports =
|
|
1633
|
+
module.exports = (Sharp) => {
|
|
1627
1634
|
Object.assign(Sharp.prototype, {
|
|
1628
1635
|
// Public
|
|
1629
1636
|
toFile,
|
package/lib/resize.js
CHANGED
package/lib/utility.js
CHANGED
|
@@ -136,7 +136,7 @@ cache(true);
|
|
|
136
136
|
* and these are independent of the value set here.
|
|
137
137
|
*
|
|
138
138
|
* :::note
|
|
139
|
-
* Further {@link /performance
|
|
139
|
+
* Further {@link /performance/ control over performance} is available.
|
|
140
140
|
* :::
|
|
141
141
|
*
|
|
142
142
|
* @example
|
|
@@ -277,7 +277,7 @@ function unblock (options) {
|
|
|
277
277
|
* @module Sharp
|
|
278
278
|
* @private
|
|
279
279
|
*/
|
|
280
|
-
module.exports =
|
|
280
|
+
module.exports = (Sharp) => {
|
|
281
281
|
Sharp.cache = cache;
|
|
282
282
|
Sharp.concurrency = concurrency;
|
|
283
283
|
Sharp.counters = counters;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revizly/sharp",
|
|
3
3
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.35.0-revizly1",
|
|
5
5
|
"author": "Lovell Fuller <npm@lovell.info>",
|
|
6
6
|
"homepage": "https://sharp.pixelplumbing.com",
|
|
7
7
|
"contributors": [
|
|
@@ -144,18 +144,18 @@
|
|
|
144
144
|
"semver": "^7.7.3"
|
|
145
145
|
},
|
|
146
146
|
"optionalDependencies": {
|
|
147
|
-
"@revizly/sharp-libvips-linux-arm64": "1.0.
|
|
148
|
-
"@revizly/sharp-libvips-linux-x64": "1.0.
|
|
147
|
+
"@revizly/sharp-libvips-linux-arm64": "1.0.26",
|
|
148
|
+
"@revizly/sharp-libvips-linux-x64": "1.0.26",
|
|
149
149
|
"@revizly/sharp-linux-arm64": "0.34.5-revizly1",
|
|
150
150
|
"@revizly/sharp-linux-x64": "0.34.5-revizly1"
|
|
151
151
|
},
|
|
152
152
|
"devDependencies": {
|
|
153
|
-
"@biomejs/biome": "^2.3.
|
|
153
|
+
"@biomejs/biome": "^2.3.4",
|
|
154
154
|
"@cpplint/cli": "^0.1.0",
|
|
155
|
-
"@emnapi/runtime": "^1.
|
|
156
|
-
"@revizly/sharp-libvips-dev": "1.0.
|
|
155
|
+
"@emnapi/runtime": "^1.7.0",
|
|
156
|
+
"@revizly/sharp-libvips-dev": "1.0.26",
|
|
157
157
|
"@types/node": "*",
|
|
158
|
-
"emnapi": "^1.
|
|
158
|
+
"emnapi": "^1.7.0",
|
|
159
159
|
"exif-reader": "^2.0.2",
|
|
160
160
|
"extract-zip": "^2.0.1",
|
|
161
161
|
"icc": "^3.0.0",
|
|
@@ -174,11 +174,5 @@
|
|
|
174
174
|
},
|
|
175
175
|
"funding": {
|
|
176
176
|
"url": "https://opencollective.com/libvips"
|
|
177
|
-
},
|
|
178
|
-
"cc": {
|
|
179
|
-
"linelength": "120",
|
|
180
|
-
"filter": [
|
|
181
|
-
"build/include"
|
|
182
|
-
]
|
|
183
177
|
}
|
|
184
178
|
}
|
package/src/binding.gyp
CHANGED
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
'conditions': [
|
|
121
121
|
['use_global_libvips == "true"', {
|
|
122
122
|
# Use pkg-config for include and lib
|
|
123
|
-
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s
|
|
123
|
+
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s/-I//g)'],
|
|
124
124
|
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
|
|
125
125
|
'defines': [
|
|
126
126
|
'SHARP_USE_GLOBAL_LIBVIPS'
|
package/src/common.h
CHANGED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
// Verify platform and compiler compatibility
|
|
19
19
|
|
|
20
20
|
#if (VIPS_MAJOR_VERSION < 8) || \
|
|
21
|
-
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION <
|
|
22
|
-
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION ==
|
|
23
|
-
#error "libvips version 8.
|
|
21
|
+
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 18) || \
|
|
22
|
+
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 0)
|
|
23
|
+
#error "libvips version 8.18.0+ is required - please see https://sharp.pixelplumbing.com/install"
|
|
24
24
|
#endif
|
|
25
25
|
|
|
26
26
|
#if defined(__has_include)
|
package/src/metadata.cc
CHANGED
|
@@ -219,10 +219,10 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
219
219
|
if (!baton->levels.empty()) {
|
|
220
220
|
int i = 0;
|
|
221
221
|
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
|
|
222
|
-
for (
|
|
222
|
+
for (const auto& [width, height] : baton->levels) {
|
|
223
223
|
Napi::Object level = Napi::Object::New(env);
|
|
224
|
-
level.Set("width",
|
|
225
|
-
level.Set("height",
|
|
224
|
+
level.Set("width", width);
|
|
225
|
+
level.Set("height", height);
|
|
226
226
|
levels.Set(i++, level);
|
|
227
227
|
}
|
|
228
228
|
info.Set("levels", levels);
|
|
@@ -279,10 +279,10 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
|
279
279
|
if (baton->comments.size() > 0) {
|
|
280
280
|
int i = 0;
|
|
281
281
|
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
|
|
282
|
-
for (auto
|
|
282
|
+
for (const auto& [keyword, text] : baton->comments) {
|
|
283
283
|
Napi::Object comment = Napi::Object::New(env);
|
|
284
|
-
comment.Set("keyword",
|
|
285
|
-
comment.Set("text",
|
|
284
|
+
comment.Set("keyword", keyword);
|
|
285
|
+
comment.Set("text", text);
|
|
286
286
|
comments.Set(i++, comment);
|
|
287
287
|
}
|
|
288
288
|
info.Set("comments", comments);
|
package/src/pipeline.cc
CHANGED
|
@@ -455,12 +455,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
455
455
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha);
|
|
456
456
|
|
|
457
457
|
// Embed
|
|
458
|
-
|
|
459
|
-
int top;
|
|
460
|
-
std::tie(left, top) = sharp::CalculateEmbedPosition(
|
|
458
|
+
const auto& [left, top] = sharp::CalculateEmbedPosition(
|
|
461
459
|
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
|
462
|
-
int width = std::max(inputWidth, baton->width);
|
|
463
|
-
int height = std::max(inputHeight, baton->height);
|
|
460
|
+
const int width = std::max(inputWidth, baton->width);
|
|
461
|
+
const int height = std::max(inputHeight, baton->height);
|
|
464
462
|
|
|
465
463
|
image = nPages > 1
|
|
466
464
|
? sharp::EmbedMultiPage(image,
|
|
@@ -479,13 +477,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
479
477
|
// Crop
|
|
480
478
|
if (baton->position < 9) {
|
|
481
479
|
// Gravity-based crop
|
|
482
|
-
|
|
483
|
-
int top;
|
|
484
|
-
|
|
485
|
-
std::tie(left, top) = sharp::CalculateCrop(
|
|
480
|
+
const auto& [left, top] = sharp::CalculateCrop(
|
|
486
481
|
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
|
487
|
-
int width = std::min(inputWidth, baton->width);
|
|
488
|
-
int height = std::min(inputHeight, baton->height);
|
|
482
|
+
const int width = std::min(inputWidth, baton->width);
|
|
483
|
+
const int height = std::min(inputHeight, baton->height);
|
|
489
484
|
|
|
490
485
|
image = nPages > 1
|
|
491
486
|
? sharp::CropMultiPage(image,
|
|
@@ -797,20 +792,14 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
797
792
|
image = sharp::EnsureAlpha(image, baton->ensureAlpha);
|
|
798
793
|
}
|
|
799
794
|
|
|
800
|
-
//
|
|
795
|
+
// Ensure output colour space
|
|
801
796
|
if (sharp::Is16Bit(image.interpretation())) {
|
|
802
797
|
image = image.cast(VIPS_FORMAT_USHORT);
|
|
803
798
|
}
|
|
804
799
|
if (image.interpretation() != baton->colourspace) {
|
|
805
|
-
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
|
806
800
|
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
baton->withIccProfile.empty() && sharp::HasProfile(image)) {
|
|
810
|
-
image = image.icc_transform(processingProfile, VImage::option()
|
|
811
|
-
->set("embedded", true)
|
|
812
|
-
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
|
813
|
-
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
|
801
|
+
if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
|
|
802
|
+
image = sharp::SetProfile(image, inputProfile);
|
|
814
803
|
}
|
|
815
804
|
}
|
|
816
805
|
|
|
@@ -845,8 +834,6 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
845
834
|
} catch(...) {
|
|
846
835
|
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
|
|
847
836
|
}
|
|
848
|
-
} else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) {
|
|
849
|
-
image = sharp::SetProfile(image, inputProfile);
|
|
850
837
|
}
|
|
851
838
|
|
|
852
839
|
// Negate the colours in the image
|
|
@@ -868,8 +855,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
868
855
|
if (!baton->withExifMerge) {
|
|
869
856
|
image = sharp::RemoveExif(image);
|
|
870
857
|
}
|
|
871
|
-
for (const auto&
|
|
872
|
-
image.set(
|
|
858
|
+
for (const auto& [key, value] : baton->withExif) {
|
|
859
|
+
image.set(key.c_str(), value.c_str());
|
|
873
860
|
}
|
|
874
861
|
}
|
|
875
862
|
// XMP buffer
|
|
@@ -1448,11 +1435,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1448
1435
|
std::string
|
|
1449
1436
|
AssembleSuffixString(std::string extname, std::vector<std::pair<std::string, std::string>> options) {
|
|
1450
1437
|
std::string argument;
|
|
1451
|
-
for (
|
|
1438
|
+
for (const auto& [key, value] : options) {
|
|
1452
1439
|
if (!argument.empty()) {
|
|
1453
1440
|
argument += ",";
|
|
1454
1441
|
}
|
|
1455
|
-
argument +=
|
|
1442
|
+
argument += key + "=" + value;
|
|
1456
1443
|
}
|
|
1457
1444
|
return extname + "[" + argument + "]";
|
|
1458
1445
|
}
|