sharp 0.33.5 → 0.34.0-rc.1
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 -1
- package/lib/colour.js +3 -2
- package/lib/composite.js +4 -2
- package/lib/constructor.js +33 -2
- package/lib/index.d.ts +166 -55
- package/lib/input.js +92 -16
- package/lib/libvips.js +3 -1
- package/lib/operation.js +92 -25
- package/lib/output.js +11 -9
- package/lib/resize.js +5 -2
- package/lib/sharp.js +10 -2
- package/lib/utility.js +1 -0
- package/package.json +39 -39
- package/src/binding.gyp +15 -8
- package/src/common.cc +42 -15
- package/src/common.h +26 -19
- package/src/metadata.cc +26 -8
- package/src/metadata.h +4 -2
- package/src/operations.cc +31 -9
- package/src/operations.h +9 -0
- package/src/pipeline.cc +109 -45
- package/src/pipeline.h +8 -3
- package/src/sharp.cc +1 -0
- package/src/stats.cc +1 -1
- package/src/utilities.cc +20 -3
- package/src/utilities.h +1 -0
package/lib/channel.js
CHANGED
|
@@ -16,7 +16,7 @@ const bool = {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Remove alpha
|
|
19
|
+
* Remove alpha channels, if any. This is a no-op if the image does not have an alpha channel.
|
|
20
20
|
*
|
|
21
21
|
* See also {@link /api-operation#flatten|flatten}.
|
|
22
22
|
*
|
|
@@ -158,6 +158,7 @@ function bandbool (boolOp) {
|
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* Decorate the Sharp prototype with channel-related functions.
|
|
161
|
+
* @module Sharp
|
|
161
162
|
* @private
|
|
162
163
|
*/
|
|
163
164
|
module.exports = function (Sharp) {
|
package/lib/colour.js
CHANGED
|
@@ -39,9 +39,9 @@ function tint (tint) {
|
|
|
39
39
|
/**
|
|
40
40
|
* Convert to 8-bit greyscale; 256 shades of grey.
|
|
41
41
|
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
|
42
|
-
* By default the output image will be web-friendly sRGB and contain three (identical)
|
|
42
|
+
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
|
43
43
|
* This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
|
44
|
-
* which will produce an output image containing one
|
|
44
|
+
* which will produce an output image containing one colour channel.
|
|
45
45
|
* An alpha channel may be present, and will be unchanged by the operation.
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
@@ -159,6 +159,7 @@ function _setBackgroundColourOption (key, value) {
|
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* Decorate the Sharp prototype with colour-related functions.
|
|
162
|
+
* @module Sharp
|
|
162
163
|
* @private
|
|
163
164
|
*/
|
|
164
165
|
module.exports = function (Sharp) {
|
package/lib/composite.js
CHANGED
|
@@ -46,8 +46,8 @@ const blend = {
|
|
|
46
46
|
* The images to composite must be the same size or smaller than the processed image.
|
|
47
47
|
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
|
48
48
|
*
|
|
49
|
-
*
|
|
50
|
-
* will always be applied to the input image before composition.
|
|
49
|
+
* Other operations in the same processing pipeline (e.g. resize, rotate, flip,
|
|
50
|
+
* flop, extract) will always be applied to the input image before composition.
|
|
51
51
|
*
|
|
52
52
|
* The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
|
53
53
|
* `dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
|
@@ -110,6 +110,7 @@ const blend = {
|
|
|
110
110
|
* @param {number} [images[].input.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
|
111
111
|
* @param {boolean} [images[].input.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`.
|
|
112
112
|
* @param {number} [images[].input.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
|
113
|
+
* @param {Boolean} [images[].autoOrient=false] - set to true to use EXIF orientation data, if present, to orient the image.
|
|
113
114
|
* @param {String} [images[].blend='over'] - how to blend this image with the image below.
|
|
114
115
|
* @param {String} [images[].gravity='centre'] - gravity at which to place the overlay.
|
|
115
116
|
* @param {Number} [images[].top] - the pixel offset from the top edge.
|
|
@@ -202,6 +203,7 @@ function composite (images) {
|
|
|
202
203
|
|
|
203
204
|
/**
|
|
204
205
|
* Decorate the Sharp prototype with composite-related functions.
|
|
206
|
+
* @module Sharp
|
|
205
207
|
* @private
|
|
206
208
|
*/
|
|
207
209
|
module.exports = function (Sharp) {
|
package/lib/constructor.js
CHANGED
|
@@ -121,10 +121,25 @@ const debuglog = util.debuglog('sharp');
|
|
|
121
121
|
* }
|
|
122
122
|
* }).toFile('text_rgba.png');
|
|
123
123
|
*
|
|
124
|
-
* @
|
|
124
|
+
* @example
|
|
125
|
+
* // Join four input images as a 2x2 grid with a 4 pixel gutter
|
|
126
|
+
* const data = await sharp(
|
|
127
|
+
* [image1, image2, image3, image4],
|
|
128
|
+
* { join: { across: 2, shim: 4 } }
|
|
129
|
+
* ).toBuffer();
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // Generate a two-frame animated image from emoji
|
|
133
|
+
* const images = ['😀', '😛'].map(text => ({
|
|
134
|
+
* text: { text, width: 64, height: 64, channels: 4, rgba: true }
|
|
135
|
+
* }));
|
|
136
|
+
* await sharp(images, { join: { animated: true } }).toFile('out.gif');
|
|
137
|
+
*
|
|
138
|
+
* @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string|Array)} [input] - if present, can be
|
|
125
139
|
* a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
|
|
126
140
|
* a TypedArray containing raw pixel image data, or
|
|
127
141
|
* a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
|
|
142
|
+
* An array of inputs can be provided, and these will be joined together.
|
|
128
143
|
* JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
|
129
144
|
* @param {Object} [options] - if present, is an Object with optional attributes.
|
|
130
145
|
* @param {string} [options.failOn='warning'] - When to abort processing of invalid pixel data, one of (in order of sensitivity, least to most): 'none', 'truncated', 'error', 'warning'. Higher levels imply lower levels. Invalid metadata will always abort.
|
|
@@ -132,6 +147,7 @@ const debuglog = util.debuglog('sharp');
|
|
|
132
147
|
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
|
133
148
|
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
|
|
134
149
|
* @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
|
|
150
|
+
* @param {boolean} [options.autoOrient=false] - Set this to `true` to rotate/flip the image to match EXIF `Orientation`, if any.
|
|
135
151
|
* @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
|
|
136
152
|
* @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
|
|
137
153
|
* @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
|
|
@@ -139,6 +155,7 @@ const debuglog = util.debuglog('sharp');
|
|
|
139
155
|
* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
|
|
140
156
|
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
|
|
141
157
|
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
|
|
158
|
+
* @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
|
|
142
159
|
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
|
|
143
160
|
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
|
144
161
|
* @param {number} [options.raw.width] - integral number of pixels wide.
|
|
@@ -167,6 +184,14 @@ const debuglog = util.debuglog('sharp');
|
|
|
167
184
|
* @param {boolean} [options.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`.
|
|
168
185
|
* @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
|
169
186
|
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'.
|
|
187
|
+
* @param {Object} [options.join] - describes how an array of input images should be joined.
|
|
188
|
+
* @param {number} [options.join.across=1] - number of images to join horizontally.
|
|
189
|
+
* @param {boolean} [options.join.animated=false] - set this to `true` to join the images as an animated image.
|
|
190
|
+
* @param {number} [options.join.shim=0] - number of pixels to insert between joined images.
|
|
191
|
+
* @param {string|Object} [options.join.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
|
192
|
+
* @param {string} [options.join.halign='left'] - horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`).
|
|
193
|
+
* @param {string} [options.join.valign='top'] - vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`).
|
|
194
|
+
*
|
|
170
195
|
* @returns {Sharp}
|
|
171
196
|
* @throws {Error} Invalid parameters
|
|
172
197
|
*/
|
|
@@ -193,7 +218,6 @@ const Sharp = function (input, options) {
|
|
|
193
218
|
canvas: 'crop',
|
|
194
219
|
position: 0,
|
|
195
220
|
resizeBackground: [0, 0, 0, 255],
|
|
196
|
-
useExifOrientation: false,
|
|
197
221
|
angle: 0,
|
|
198
222
|
rotationAngle: 0,
|
|
199
223
|
rotationBackground: [0, 0, 0, 255],
|
|
@@ -239,6 +263,8 @@ const Sharp = function (input, options) {
|
|
|
239
263
|
trimBackground: [],
|
|
240
264
|
trimThreshold: -1,
|
|
241
265
|
trimLineArt: false,
|
|
266
|
+
dilateWidth: 0,
|
|
267
|
+
erodeWidth: 0,
|
|
242
268
|
gamma: 0,
|
|
243
269
|
gammaOut: 0,
|
|
244
270
|
greyscale: false,
|
|
@@ -272,6 +298,8 @@ const Sharp = function (input, options) {
|
|
|
272
298
|
withExif: {},
|
|
273
299
|
withExifMerge: true,
|
|
274
300
|
resolveWithObject: false,
|
|
301
|
+
loop: 1,
|
|
302
|
+
delay: [],
|
|
275
303
|
// output format
|
|
276
304
|
jpegQuality: 80,
|
|
277
305
|
jpegProgressive: false,
|
|
@@ -299,6 +327,7 @@ const Sharp = function (input, options) {
|
|
|
299
327
|
webpLossless: false,
|
|
300
328
|
webpNearLossless: false,
|
|
301
329
|
webpSmartSubsample: false,
|
|
330
|
+
webpSmartDeblock: false,
|
|
302
331
|
webpPreset: 'default',
|
|
303
332
|
webpEffort: 4,
|
|
304
333
|
webpMinSize: false,
|
|
@@ -348,6 +377,7 @@ const Sharp = function (input, options) {
|
|
|
348
377
|
timeoutSeconds: 0,
|
|
349
378
|
linearA: [],
|
|
350
379
|
linearB: [],
|
|
380
|
+
pdfBackground: [255, 255, 255, 255],
|
|
351
381
|
// Function to notify of libvips warnings
|
|
352
382
|
debuglog: warning => {
|
|
353
383
|
this.emit('warning', warning);
|
|
@@ -447,6 +477,7 @@ Object.assign(Sharp.prototype, { clone });
|
|
|
447
477
|
|
|
448
478
|
/**
|
|
449
479
|
* Export constructor.
|
|
480
|
+
* @module Sharp
|
|
450
481
|
* @private
|
|
451
482
|
*/
|
|
452
483
|
module.exports = Sharp;
|
package/lib/index.d.ts
CHANGED
|
@@ -40,19 +40,7 @@ import { Duplex } from 'stream';
|
|
|
40
40
|
*/
|
|
41
41
|
declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;
|
|
42
42
|
declare function sharp(
|
|
43
|
-
input?:
|
|
44
|
-
| Buffer
|
|
45
|
-
| ArrayBuffer
|
|
46
|
-
| Uint8Array
|
|
47
|
-
| Uint8ClampedArray
|
|
48
|
-
| Int8Array
|
|
49
|
-
| Uint16Array
|
|
50
|
-
| Int16Array
|
|
51
|
-
| Uint32Array
|
|
52
|
-
| Int32Array
|
|
53
|
-
| Float32Array
|
|
54
|
-
| Float64Array
|
|
55
|
-
| string,
|
|
43
|
+
input?: sharp.SharpInput | Array<sharp.SharpInput>,
|
|
56
44
|
options?: sharp.SharpOptions,
|
|
57
45
|
): sharp.Sharp;
|
|
58
46
|
|
|
@@ -62,33 +50,35 @@ declare namespace sharp {
|
|
|
62
50
|
|
|
63
51
|
/** An Object containing the version numbers of sharp, libvips and its dependencies. */
|
|
64
52
|
const versions: {
|
|
65
|
-
|
|
53
|
+
aom?: string | undefined;
|
|
54
|
+
archive?: string | undefined;
|
|
66
55
|
cairo?: string | undefined;
|
|
67
|
-
|
|
56
|
+
cgif?: string | undefined;
|
|
68
57
|
exif?: string | undefined;
|
|
69
58
|
expat?: string | undefined;
|
|
70
59
|
ffi?: string | undefined;
|
|
71
60
|
fontconfig?: string | undefined;
|
|
72
61
|
freetype?: string | undefined;
|
|
73
|
-
|
|
74
|
-
gif?: string | undefined;
|
|
62
|
+
fribidi?: string | undefined;
|
|
75
63
|
glib?: string | undefined;
|
|
76
|
-
gsf?: string | undefined;
|
|
77
64
|
harfbuzz?: string | undefined;
|
|
78
|
-
|
|
65
|
+
heif?: string | undefined;
|
|
66
|
+
highway?: string | undefined;
|
|
67
|
+
imagequant?: string | undefined;
|
|
79
68
|
lcms?: string | undefined;
|
|
80
|
-
|
|
69
|
+
mozjpeg?: string | undefined;
|
|
81
70
|
pango?: string | undefined;
|
|
82
71
|
pixman?: string | undefined;
|
|
83
72
|
png?: string | undefined;
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
"proxy-libintl"?: string | undefined;
|
|
74
|
+
rsvg?: string | undefined;
|
|
75
|
+
sharp: string;
|
|
76
|
+
spng?: string | undefined;
|
|
86
77
|
tiff?: string | undefined;
|
|
78
|
+
vips: string;
|
|
87
79
|
webp?: string | undefined;
|
|
88
|
-
avif?: string | undefined;
|
|
89
|
-
heif?: string | undefined;
|
|
90
80
|
xml?: string | undefined;
|
|
91
|
-
zlib?: string | undefined;
|
|
81
|
+
"zlib-ng"?: string | undefined;
|
|
92
82
|
};
|
|
93
83
|
|
|
94
84
|
/** An Object containing the available interpolators and their proper values */
|
|
@@ -244,14 +234,14 @@ declare namespace sharp {
|
|
|
244
234
|
* @param tint Parsed by the color module.
|
|
245
235
|
* @returns A sharp instance that can be used to chain operations
|
|
246
236
|
*/
|
|
247
|
-
tint(tint: Color): Sharp;
|
|
237
|
+
tint(tint: Colour | Color): Sharp;
|
|
248
238
|
|
|
249
239
|
/**
|
|
250
240
|
* Convert to 8-bit greyscale; 256 shades of grey.
|
|
251
241
|
* This is a linear operation.
|
|
252
242
|
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
|
|
253
|
-
* By default the output image will be web-friendly sRGB and contain three (identical)
|
|
254
|
-
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one
|
|
243
|
+
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
|
244
|
+
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel.
|
|
255
245
|
* An alpha channel may be present, and will be unchanged by the operation.
|
|
256
246
|
* @param greyscale true to enable and false to disable (defaults to true)
|
|
257
247
|
* @returns A sharp instance that can be used to chain operations
|
|
@@ -364,24 +354,72 @@ declare namespace sharp {
|
|
|
364
354
|
//#region Operation functions
|
|
365
355
|
|
|
366
356
|
/**
|
|
367
|
-
* Rotate the output image by either an explicit angle
|
|
357
|
+
* Rotate the output image by either an explicit angle
|
|
358
|
+
* or auto-orient based on the EXIF `Orientation` tag.
|
|
368
359
|
*
|
|
369
|
-
* If an angle is provided, it is converted to a valid positive degree rotation.
|
|
360
|
+
* If an angle is provided, it is converted to a valid positive degree rotation.
|
|
361
|
+
* For example, `-450` will produce a 270 degree rotation.
|
|
370
362
|
*
|
|
371
|
-
* When rotating by an angle other than a multiple of 90,
|
|
363
|
+
* When rotating by an angle other than a multiple of 90,
|
|
364
|
+
* the background colour can be provided with the `background` option.
|
|
372
365
|
*
|
|
373
|
-
* If no angle is provided, it is determined from the EXIF data.
|
|
366
|
+
* If no angle is provided, it is determined from the EXIF data.
|
|
367
|
+
* Mirroring is supported and may infer the use of a flip operation.
|
|
374
368
|
*
|
|
375
|
-
* The use of rotate
|
|
369
|
+
* The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
|
376
370
|
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
371
|
+
* Only one rotation can occur per pipeline (aside from an initial call without
|
|
372
|
+
* arguments to orient via EXIF data). Previous calls to `rotate` in the same
|
|
373
|
+
* pipeline will be ignored.
|
|
374
|
+
*
|
|
375
|
+
* Multi-page images can only be rotated by 180 degrees.
|
|
376
|
+
*
|
|
377
|
+
* Method order is important when rotating, resizing and/or extracting regions,
|
|
378
|
+
* for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* const pipeline = sharp()
|
|
382
|
+
* .rotate()
|
|
383
|
+
* .resize(null, 200)
|
|
384
|
+
* .toBuffer(function (err, outputBuffer, info) {
|
|
385
|
+
* // outputBuffer contains 200px high JPEG image data,
|
|
386
|
+
* // auto-rotated using EXIF Orientation tag
|
|
387
|
+
* // info.width and info.height contain the dimensions of the resized image
|
|
388
|
+
* });
|
|
389
|
+
* readableStream.pipe(pipeline);
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* const rotateThenResize = await sharp(input)
|
|
393
|
+
* .rotate(90)
|
|
394
|
+
* .resize({ width: 16, height: 8, fit: 'fill' })
|
|
395
|
+
* .toBuffer();
|
|
396
|
+
* const resizeThenRotate = await sharp(input)
|
|
397
|
+
* .resize({ width: 16, height: 8, fit: 'fill' })
|
|
398
|
+
* .rotate(90)
|
|
399
|
+
* .toBuffer();
|
|
400
|
+
*
|
|
401
|
+
* @param {number} [angle=auto] angle of rotation.
|
|
402
|
+
* @param {Object} [options] - if present, is an Object with optional attributes.
|
|
403
|
+
* @param {string|Object} [options.background="#000000"] parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
|
404
|
+
* @returns {Sharp}
|
|
380
405
|
* @throws {Error} Invalid parameters
|
|
381
|
-
* @returns A sharp instance that can be used to chain operations
|
|
382
406
|
*/
|
|
383
407
|
rotate(angle?: number, options?: RotateOptions): Sharp;
|
|
384
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Alias for calling `rotate()` with no arguments, which orients the image based
|
|
411
|
+
* on EXIF orientsion.
|
|
412
|
+
*
|
|
413
|
+
* This operation is aliased to emphasize its purpose, helping to remove any
|
|
414
|
+
* confusion between rotation and orientation.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* const output = await sharp(input).autoOrient().toBuffer();
|
|
418
|
+
*
|
|
419
|
+
* @returns {Sharp}
|
|
420
|
+
*/
|
|
421
|
+
autoOrient(): Sharp
|
|
422
|
+
|
|
385
423
|
/**
|
|
386
424
|
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
|
387
425
|
* The use of flip implies the removal of the EXIF Orientation tag, if any.
|
|
@@ -401,7 +439,7 @@ declare namespace sharp {
|
|
|
401
439
|
/**
|
|
402
440
|
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
|
403
441
|
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
|
404
|
-
* By default, new pixels are filled with a black background. You can provide a background
|
|
442
|
+
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
|
405
443
|
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
|
406
444
|
*
|
|
407
445
|
* In the case of a 2x2 matrix, the transform is:
|
|
@@ -466,6 +504,22 @@ declare namespace sharp {
|
|
|
466
504
|
*/
|
|
467
505
|
blur(sigma?: number | boolean | BlurOptions): Sharp;
|
|
468
506
|
|
|
507
|
+
/**
|
|
508
|
+
* Expand foreground objects using the dilate morphological operator.
|
|
509
|
+
* @param {Number} [width=1] dilation width in pixels.
|
|
510
|
+
* @throws {Error} Invalid parameters
|
|
511
|
+
* @returns A sharp instance that can be used to chain operations
|
|
512
|
+
*/
|
|
513
|
+
dilate(width?: number): Sharp;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Shrink foreground objects using the erode morphological operator.
|
|
517
|
+
* @param {Number} [width=1] erosion width in pixels.
|
|
518
|
+
* @throws {Error} Invalid parameters
|
|
519
|
+
* @returns A sharp instance that can be used to chain operations
|
|
520
|
+
*/
|
|
521
|
+
erode(width?: number): Sharp;
|
|
522
|
+
|
|
469
523
|
/**
|
|
470
524
|
* Merge alpha transparency channel, if any, with background.
|
|
471
525
|
* @param flatten true to enable and false to disable (defaults to true)
|
|
@@ -799,8 +853,6 @@ declare namespace sharp {
|
|
|
799
853
|
* Use tile-based deep zoom (image pyramid) output.
|
|
800
854
|
* Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
|
|
801
855
|
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
|
|
802
|
-
*
|
|
803
|
-
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
|
804
856
|
* @param tile tile options
|
|
805
857
|
* @throws {Error} Invalid options
|
|
806
858
|
* @returns A sharp instance that can be used to chain operations
|
|
@@ -899,7 +951,27 @@ declare namespace sharp {
|
|
|
899
951
|
//#endregion
|
|
900
952
|
}
|
|
901
953
|
|
|
954
|
+
type SharpInput = Buffer
|
|
955
|
+
| ArrayBuffer
|
|
956
|
+
| Uint8Array
|
|
957
|
+
| Uint8ClampedArray
|
|
958
|
+
| Int8Array
|
|
959
|
+
| Uint16Array
|
|
960
|
+
| Int16Array
|
|
961
|
+
| Uint32Array
|
|
962
|
+
| Int32Array
|
|
963
|
+
| Float32Array
|
|
964
|
+
| Float64Array
|
|
965
|
+
| string;
|
|
966
|
+
|
|
902
967
|
interface SharpOptions {
|
|
968
|
+
/**
|
|
969
|
+
* Auto-orient based on the EXIF `Orientation` tag, if present.
|
|
970
|
+
* Mirroring is supported and may infer the use of a flip operation.
|
|
971
|
+
*
|
|
972
|
+
* Using this option will remove the EXIF `Orientation` tag, if any.
|
|
973
|
+
*/
|
|
974
|
+
autoOrient?: boolean;
|
|
903
975
|
/**
|
|
904
976
|
* When to abort processing of invalid pixel data, one of (in order of sensitivity):
|
|
905
977
|
* 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
|
|
@@ -935,6 +1007,8 @@ declare namespace sharp {
|
|
|
935
1007
|
subifd?: number | undefined;
|
|
936
1008
|
/** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
|
|
937
1009
|
level?: number | undefined;
|
|
1010
|
+
/** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
|
|
1011
|
+
pdfBackground?: Colour | Color | undefined;
|
|
938
1012
|
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
|
|
939
1013
|
animated?: boolean | undefined;
|
|
940
1014
|
/** Describes raw pixel input image data. See raw() for pixel ordering. */
|
|
@@ -943,6 +1017,8 @@ declare namespace sharp {
|
|
|
943
1017
|
create?: Create | undefined;
|
|
944
1018
|
/** Describes a new text image to be created. */
|
|
945
1019
|
text?: CreateText | undefined;
|
|
1020
|
+
/** Describes how array of input images should be joined. */
|
|
1021
|
+
join?: Join | undefined;
|
|
946
1022
|
}
|
|
947
1023
|
|
|
948
1024
|
interface CacheOptions {
|
|
@@ -969,7 +1045,7 @@ declare namespace sharp {
|
|
|
969
1045
|
interface Raw {
|
|
970
1046
|
width: number;
|
|
971
1047
|
height: number;
|
|
972
|
-
channels:
|
|
1048
|
+
channels: Channels;
|
|
973
1049
|
}
|
|
974
1050
|
|
|
975
1051
|
interface CreateRaw extends Raw {
|
|
@@ -977,15 +1053,17 @@ declare namespace sharp {
|
|
|
977
1053
|
premultiplied?: boolean | undefined;
|
|
978
1054
|
}
|
|
979
1055
|
|
|
1056
|
+
type CreateChannels = 3 | 4;
|
|
1057
|
+
|
|
980
1058
|
interface Create {
|
|
981
1059
|
/** Number of pixels wide. */
|
|
982
1060
|
width: number;
|
|
983
1061
|
/** Number of pixels high. */
|
|
984
1062
|
height: number;
|
|
985
|
-
/** Number of bands
|
|
986
|
-
channels:
|
|
1063
|
+
/** Number of bands, 3 for RGB, 4 for RGBA */
|
|
1064
|
+
channels: CreateChannels;
|
|
987
1065
|
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
|
|
988
|
-
background: Color;
|
|
1066
|
+
background: Colour | Color;
|
|
989
1067
|
/** Describes a noise to be created. */
|
|
990
1068
|
noise?: Noise | undefined;
|
|
991
1069
|
}
|
|
@@ -1021,6 +1099,21 @@ declare namespace sharp {
|
|
|
1021
1099
|
wrap?: TextWrap;
|
|
1022
1100
|
}
|
|
1023
1101
|
|
|
1102
|
+
interface Join {
|
|
1103
|
+
/** Number of images per row. */
|
|
1104
|
+
across?: number | undefined;
|
|
1105
|
+
/** Treat input as frames of an animated image. */
|
|
1106
|
+
animated?: boolean | undefined;
|
|
1107
|
+
/** Space between images, in pixels. */
|
|
1108
|
+
shim?: number | undefined;
|
|
1109
|
+
/** Background colour. */
|
|
1110
|
+
background?: Colour | Color | undefined;
|
|
1111
|
+
/** Horizontal alignment. */
|
|
1112
|
+
halign?: HorizontalAlignment | undefined;
|
|
1113
|
+
/** Vertical alignment. */
|
|
1114
|
+
valign?: VerticalAlignment | undefined;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1024
1117
|
interface ExifDir {
|
|
1025
1118
|
[k: string]: string;
|
|
1026
1119
|
}
|
|
@@ -1060,6 +1153,13 @@ declare namespace sharp {
|
|
|
1060
1153
|
width?: number | undefined;
|
|
1061
1154
|
/** Number of pixels high (EXIF orientation is not taken into consideration) */
|
|
1062
1155
|
height?: number | undefined;
|
|
1156
|
+
/** Any changed metadata after the image orientation is applied. */
|
|
1157
|
+
autoOrient: {
|
|
1158
|
+
/** Number of pixels wide (EXIF orientation is taken into consideration) */
|
|
1159
|
+
width: number;
|
|
1160
|
+
/** Number of pixels high (EXIF orientation is taken into consideration) */
|
|
1161
|
+
height: number;
|
|
1162
|
+
};
|
|
1063
1163
|
/** Name of colour space interpretation */
|
|
1064
1164
|
space?: keyof ColourspaceEnum | undefined;
|
|
1065
1165
|
/** Number of bands e.g. 3 for sRGB, 4 for CMYK */
|
|
@@ -1072,6 +1172,10 @@ declare namespace sharp {
|
|
|
1072
1172
|
chromaSubsampling?: string | undefined;
|
|
1073
1173
|
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
|
1074
1174
|
isProgressive?: boolean | undefined;
|
|
1175
|
+
/** Boolean indicating whether the image is palette-based (GIF, PNG). */
|
|
1176
|
+
isPalette?: boolean | undefined;
|
|
1177
|
+
/** Number of bits per sample for each channel (GIF, PNG). */
|
|
1178
|
+
bitsPerSample?: number | undefined;
|
|
1075
1179
|
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
|
1076
1180
|
pages?: number | undefined;
|
|
1077
1181
|
/** Number of pixels high each page in a multi-page image will be. */
|
|
@@ -1098,8 +1202,8 @@ declare namespace sharp {
|
|
|
1098
1202
|
tifftagPhotoshop?: Buffer | undefined;
|
|
1099
1203
|
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
|
1100
1204
|
compression?: 'av1' | 'hevc';
|
|
1101
|
-
/** Default background colour, if present, for PNG (bKGD) and GIF images
|
|
1102
|
-
background?: { r: number; g: number; b: number } | number;
|
|
1205
|
+
/** Default background colour, if present, for PNG (bKGD) and GIF images */
|
|
1206
|
+
background?: { r: number; g: number; b: number } | { gray: number };
|
|
1103
1207
|
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
|
|
1104
1208
|
levels?: LevelMetadata[] | undefined;
|
|
1105
1209
|
/** Number of Sub Image File Directories in an OME-TIFF image */
|
|
@@ -1339,7 +1443,7 @@ declare namespace sharp {
|
|
|
1339
1443
|
|
|
1340
1444
|
interface RotateOptions {
|
|
1341
1445
|
/** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
|
|
1342
|
-
background?: Color | undefined;
|
|
1446
|
+
background?: Colour | Color | undefined;
|
|
1343
1447
|
}
|
|
1344
1448
|
|
|
1345
1449
|
type Precision = 'integer' | 'float' | 'approximate';
|
|
@@ -1355,7 +1459,7 @@ declare namespace sharp {
|
|
|
1355
1459
|
|
|
1356
1460
|
interface FlattenOptions {
|
|
1357
1461
|
/** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
|
|
1358
|
-
background?: Color | undefined;
|
|
1462
|
+
background?: Colour | Color | undefined;
|
|
1359
1463
|
}
|
|
1360
1464
|
|
|
1361
1465
|
interface NegateOptions {
|
|
@@ -1380,7 +1484,7 @@ declare namespace sharp {
|
|
|
1380
1484
|
/** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
|
|
1381
1485
|
position?: number | string | undefined;
|
|
1382
1486
|
/** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
|
1383
|
-
background?: Color | undefined;
|
|
1487
|
+
background?: Colour | Color | undefined;
|
|
1384
1488
|
/** The kernel to use for image reduction. (optional, default 'lanczos3') */
|
|
1385
1489
|
kernel?: keyof KernelEnum | undefined;
|
|
1386
1490
|
/** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
|
|
@@ -1423,14 +1527,14 @@ declare namespace sharp {
|
|
|
1423
1527
|
/** single pixel count to right edge (optional, default 0) */
|
|
1424
1528
|
right?: number | undefined;
|
|
1425
1529
|
/** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
|
1426
|
-
background?: Color | undefined;
|
|
1530
|
+
background?: Colour | Color | undefined;
|
|
1427
1531
|
/** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
|
|
1428
1532
|
extendWith?: ExtendWith | undefined;
|
|
1429
1533
|
}
|
|
1430
1534
|
|
|
1431
1535
|
interface TrimOptions {
|
|
1432
1536
|
/** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
|
|
1433
|
-
background?: Color | undefined;
|
|
1537
|
+
background?: Colour | Color | undefined;
|
|
1434
1538
|
/** Allowed difference from the above colour, a positive number. (optional, default 10) */
|
|
1435
1539
|
threshold?: number | undefined;
|
|
1436
1540
|
/** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
|
|
@@ -1441,8 +1545,8 @@ declare namespace sharp {
|
|
|
1441
1545
|
depth?: 'char' | 'uchar' | 'short' | 'ushort' | 'int' | 'uint' | 'float' | 'complex' | 'double' | 'dpcomplex';
|
|
1442
1546
|
}
|
|
1443
1547
|
|
|
1444
|
-
/** 3 for sRGB, 4 for CMYK */
|
|
1445
|
-
type Channels = 3 | 4;
|
|
1548
|
+
/** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
|
|
1549
|
+
type Channels = 1 | 2 | 3 | 4;
|
|
1446
1550
|
|
|
1447
1551
|
interface RGBA {
|
|
1448
1552
|
r?: number | undefined;
|
|
@@ -1451,7 +1555,8 @@ declare namespace sharp {
|
|
|
1451
1555
|
alpha?: number | undefined;
|
|
1452
1556
|
}
|
|
1453
1557
|
|
|
1454
|
-
type
|
|
1558
|
+
type Colour = string | RGBA;
|
|
1559
|
+
type Color = Colour;
|
|
1455
1560
|
|
|
1456
1561
|
interface Kernel {
|
|
1457
1562
|
/** width of the kernel in pixels. */
|
|
@@ -1505,6 +1610,8 @@ declare namespace sharp {
|
|
|
1505
1610
|
failOn?: FailOnOptions | undefined;
|
|
1506
1611
|
/** see sharp() constructor, (optional, default 268402689) */
|
|
1507
1612
|
limitInputPixels?: number | boolean | undefined;
|
|
1613
|
+
/** see sharp() constructor, (optional, default false) */
|
|
1614
|
+
autoOrient?: boolean | undefined;
|
|
1508
1615
|
}
|
|
1509
1616
|
|
|
1510
1617
|
interface TileOptions {
|
|
@@ -1576,7 +1683,7 @@ declare namespace sharp {
|
|
|
1576
1683
|
size: number;
|
|
1577
1684
|
width: number;
|
|
1578
1685
|
height: number;
|
|
1579
|
-
channels:
|
|
1686
|
+
channels: Channels;
|
|
1580
1687
|
/** indicating if premultiplication was used */
|
|
1581
1688
|
premultiplied: boolean;
|
|
1582
1689
|
/** Only defined when using a crop strategy */
|
|
@@ -1645,6 +1752,10 @@ declare namespace sharp {
|
|
|
1645
1752
|
|
|
1646
1753
|
type TextWrap = 'word' | 'char' | 'word-char' | 'none';
|
|
1647
1754
|
|
|
1755
|
+
type HorizontalAlignment = 'left' | 'centre' | 'center' | 'right';
|
|
1756
|
+
|
|
1757
|
+
type VerticalAlignment = 'top' | 'centre' | 'center' | 'bottom';
|
|
1758
|
+
|
|
1648
1759
|
type TileContainer = 'fs' | 'zip';
|
|
1649
1760
|
|
|
1650
1761
|
type TileLayout = 'dz' | 'iiif' | 'iiif3' | 'zoomify' | 'google';
|