@revizly/sharp 0.35.0-revizly4 → 0.35.0-revizly41

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.
Files changed (46) hide show
  1. package/README.md +12 -18
  2. package/{lib/channel.js → dist/channel.cjs} +1 -1
  3. package/dist/channel.mjs +177 -0
  4. package/{lib/colour.js → dist/colour.cjs} +11 -7
  5. package/dist/colour.mjs +199 -0
  6. package/{lib/composite.js → dist/composite.cjs} +2 -1
  7. package/dist/composite.mjs +213 -0
  8. package/{lib/constructor.js → dist/constructor.cjs} +42 -29
  9. package/dist/constructor.mjs +512 -0
  10. package/dist/index.cjs +25 -0
  11. package/dist/index.d.cts +2001 -0
  12. package/dist/index.d.mts +2048 -0
  13. package/dist/index.mjs +25 -0
  14. package/{lib/input.js → dist/input.cjs} +26 -21
  15. package/dist/input.mjs +814 -0
  16. package/{lib/is.js → dist/is.cjs} +1 -1
  17. package/dist/is.mjs +143 -0
  18. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  19. package/dist/libvips.mjs +212 -0
  20. package/{lib/operation.js → dist/operation.cjs} +33 -51
  21. package/dist/operation.mjs +998 -0
  22. package/{lib/output.js → dist/output.cjs} +161 -28
  23. package/dist/output.mjs +1799 -0
  24. package/{lib/resize.js → dist/resize.cjs} +46 -24
  25. package/dist/resize.mjs +617 -0
  26. package/dist/sharp.cjs +125 -0
  27. package/dist/sharp.mjs +125 -0
  28. package/{lib/utility.js → dist/utility.cjs} +18 -8
  29. package/dist/utility.mjs +301 -0
  30. package/install/build.js +3 -3
  31. package/lib/index.d.ts +105 -75
  32. package/package.json +46 -27
  33. package/src/binding.gyp +18 -13
  34. package/src/common.cc +70 -17
  35. package/src/common.h +22 -3
  36. package/src/metadata.cc +66 -8
  37. package/src/metadata.h +6 -1
  38. package/src/operations.cc +25 -8
  39. package/src/operations.h +1 -1
  40. package/src/pipeline.cc +206 -69
  41. package/src/pipeline.h +16 -1
  42. package/src/stats.cc +6 -6
  43. package/src/utilities.cc +7 -6
  44. package/install/check.js +0 -14
  45. package/lib/index.js +0 -16
  46. package/lib/sharp.js +0 -121
@@ -0,0 +1,512 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import util from 'node:util';
7
+ import stream from 'node:stream';
8
+ import is from './is.mjs';
9
+
10
+ import './sharp.mjs';
11
+
12
+ // Use NODE_DEBUG=sharp to enable libvips warnings
13
+ const debuglog = util.debuglog('sharp');
14
+
15
+ const queueListener = (queueLength) => {
16
+ Sharp.queue.emit('change', queueLength);
17
+ };
18
+
19
+ /**
20
+ * Constructor factory to create an instance of `sharp`, to which further methods are chained.
21
+ *
22
+ * JPEG, PNG, WebP, GIF, AVIF or TIFF format image data can be streamed out from this object.
23
+ * When using Stream based output, derived attributes are available from the `info` event.
24
+ *
25
+ * Non-critical problems encountered during processing are emitted as `warning` events.
26
+ *
27
+ * Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
28
+ *
29
+ * When loading more than one page/frame of an animated image,
30
+ * these are combined as a vertically-stacked "toilet roll" image
31
+ * where the overall height is the `pageHeight` multiplied by the number of `pages`.
32
+ *
33
+ * @constructs Sharp
34
+ *
35
+ * @emits Sharp#info
36
+ * @emits Sharp#warning
37
+ *
38
+ * @example
39
+ * sharp('input.jpg')
40
+ * .resize(300, 200)
41
+ * .toFile('output.jpg', function(err) {
42
+ * // output.jpg is a 300 pixels wide and 200 pixels high image
43
+ * // containing a scaled and cropped version of input.jpg
44
+ * });
45
+ *
46
+ * @example
47
+ * // Read image data from remote URL,
48
+ * // resize to 300 pixels wide,
49
+ * // emit an 'info' event with calculated dimensions
50
+ * // and finally write image data to writableStream
51
+ * const { body } = await fetch('https://...');
52
+ * const readableStream = Readable.fromWeb(body);
53
+ * const transformer = sharp()
54
+ * .resize(300)
55
+ * .on('info', ({ height }) => {
56
+ * console.log(`Image height is ${height}`);
57
+ * });
58
+ * readableStream.pipe(transformer).pipe(writableStream);
59
+ *
60
+ * @example
61
+ * // Web Streams API, requires Node.js >= 24.15.0
62
+ * import { Duplex } from 'node:stream';
63
+ *
64
+ * const { body } = await fetch('https://...');
65
+ * const transformer = Duplex.toWeb(
66
+ * sharp().resize(300),
67
+ * { readableType: 'bytes' }
68
+ * );
69
+ * body.pipeThrough(transformer).pipeTo(writable);
70
+ *
71
+ * @example
72
+ * // Create a blank 300x200 PNG image of semi-translucent red pixels
73
+ * sharp({
74
+ * create: {
75
+ * width: 300,
76
+ * height: 200,
77
+ * channels: 4,
78
+ * background: { r: 255, g: 0, b: 0, alpha: 0.5 }
79
+ * }
80
+ * })
81
+ * .png()
82
+ * .toBuffer()
83
+ * .then( ... );
84
+ *
85
+ * @example
86
+ * // Convert an animated GIF to an animated WebP
87
+ * await sharp('in.gif', { animated: true }).toFile('out.webp');
88
+ *
89
+ * @example
90
+ * // Read a raw array of pixels and save it to a png
91
+ * const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
92
+ * const image = sharp(input, {
93
+ * // because the input does not contain its dimensions or how many channels it has
94
+ * // we need to specify it in the constructor options
95
+ * raw: {
96
+ * width: 2,
97
+ * height: 1,
98
+ * channels: 3
99
+ * }
100
+ * });
101
+ * await image.toFile('my-two-pixels.png');
102
+ *
103
+ * @example
104
+ * // Generate RGB Gaussian noise
105
+ * await sharp({
106
+ * create: {
107
+ * width: 300,
108
+ * height: 200,
109
+ * channels: 3,
110
+ * noise: {
111
+ * type: 'gaussian',
112
+ * mean: 128,
113
+ * sigma: 30
114
+ * }
115
+ * }
116
+ * }).toFile('noise.png');
117
+ *
118
+ * @example
119
+ * // Generate an image from text
120
+ * await sharp({
121
+ * text: {
122
+ * text: 'Hello, world!',
123
+ * width: 400, // max width
124
+ * height: 300 // max height
125
+ * }
126
+ * }).toFile('text_bw.png');
127
+ *
128
+ * @example
129
+ * // Generate an rgba image from text using pango markup and font
130
+ * await sharp({
131
+ * text: {
132
+ * text: '<span foreground="red">Red!</span><span background="cyan">blue</span>',
133
+ * font: 'sans',
134
+ * rgba: true,
135
+ * dpi: 300
136
+ * }
137
+ * }).toFile('text_rgba.png');
138
+ *
139
+ * @example
140
+ * // Join four input images as a 2x2 grid with a 4 pixel gutter
141
+ * const data = await sharp(
142
+ * [image1, image2, image3, image4],
143
+ * { join: { across: 2, shim: 4 } }
144
+ * ).toBuffer();
145
+ *
146
+ * @example
147
+ * // Generate a two-frame animated image from emoji
148
+ * const images = ['😀', '😛'].map(text => ({
149
+ * text: { text, width: 64, height: 64, channels: 4, rgba: true }
150
+ * }));
151
+ * await sharp(images, { join: { animated: true } }).toFile('out.gif');
152
+ *
153
+ * @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string|Array)} [input] - if present, can be
154
+ * a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
155
+ * a TypedArray containing raw pixel image data, or
156
+ * a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
157
+ * An array of inputs can be provided, and these will be joined together.
158
+ * JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
159
+ * @param {Object} [options] - if present, is an Object with optional attributes.
160
+ * @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. Use the default 'warning' level with untrusted input.
161
+ * @param {number|boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
162
+ * (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
163
+ * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
164
+ * @param {number|boolean} [options.limitInputChannels=5] - Do not process input images where the number of channels exceeds this limit. Assumes image metadata can be trusted.
165
+ * An integral Number of channels, zero or false to remove limit, true to use default limit of 5.
166
+ * @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
167
+ * @param {boolean} [options.autoOrient=false] - Set this to `true` to rotate/flip the image to match EXIF `Orientation`, if any.
168
+ * @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
169
+ * @param {number} [options.density=72] - The DPI at which to render SVG and PDF images, in the range 1 to 100000.
170
+ * @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
171
+ * @param {number} [options.pages=1] - Number of pages to extract for multi-page input (GIF, WebP, TIFF), use -1 for all pages.
172
+ * @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
173
+ * @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`.
174
+ * @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
175
+ * @param {number} [options.raw.width] - integral number of pixels wide.
176
+ * @param {number} [options.raw.height] - integral number of pixels high.
177
+ * @param {number} [options.raw.channels] - integral number of channels, between 1 and 4.
178
+ * @param {boolean} [options.raw.premultiplied] - specifies that the raw input has already been premultiplied, set to `true`
179
+ * to avoid sharp premultiplying the image. (optional, default `false`)
180
+ * @param {number} [options.raw.pageHeight] - The pixel height of each page/frame for animated images, must be an integral factor of `raw.height`.
181
+ * @param {Object} [options.create] - describes a new image to be created.
182
+ * @param {number} [options.create.width] - integral number of pixels wide.
183
+ * @param {number} [options.create.height] - integral number of pixels high.
184
+ * @param {number} [options.create.channels] - integral number of channels, either 3 (RGB) or 4 (RGBA).
185
+ * @param {string|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
186
+ * @param {number} [options.create.pageHeight] - The pixel height of each page/frame for animated images, must be an integral factor of `create.height`.
187
+ * @param {Object} [options.create.noise] - describes a noise to be created.
188
+ * @param {string} [options.create.noise.type] - type of generated noise, currently only `gaussian` is supported.
189
+ * @param {number} [options.create.noise.mean=128] - Mean value of pixels in the generated noise.
190
+ * @param {number} [options.create.noise.sigma=30] - Standard deviation of pixel values in the generated noise.
191
+ * @param {Object} [options.text] - describes a new text image to be created.
192
+ * @param {string} [options.text.text] - text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
193
+ * @param {string} [options.text.font] - font name to render with.
194
+ * @param {string} [options.text.fontfile] - absolute filesystem path to a font file that can be used by `font`.
195
+ * @param {number} [options.text.width=0] - Integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries.
196
+ * @param {number} [options.text.height=0] - Maximum integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0.
197
+ * @param {string} [options.text.align='left'] - Alignment style for multi-line text (`'left'`, `'centre'`, `'center'`, `'right'`).
198
+ * @param {boolean} [options.text.justify=false] - set this to true to apply justification to the text.
199
+ * @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
200
+ * @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>`.
201
+ * @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
202
+ * @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'.
203
+ * @param {Object} [options.join] - describes how an array of input images should be joined.
204
+ * @param {number} [options.join.across=1] - number of images to join horizontally.
205
+ * @param {boolean} [options.join.animated=false] - set this to `true` to join the images as an animated image.
206
+ * @param {number} [options.join.shim=0] - number of pixels to insert between joined images.
207
+ * @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.
208
+ * @param {string} [options.join.halign='left'] - horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`).
209
+ * @param {string} [options.join.valign='top'] - vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`).
210
+ * @param {Object} [options.tiff] - Describes TIFF specific options.
211
+ * @param {number} [options.tiff.subifd=-1] - Sub Image File Directory to extract for OME-TIFF, defaults to main image.
212
+ * @param {Object} [options.svg] - Describes SVG specific options.
213
+ * @param {string} [options.svg.stylesheet] - Custom CSS for SVG input, applied with a User Origin during the CSS cascade.
214
+ * @param {boolean} [options.svg.highBitdepth=false] - Set to `true` to render SVG input at 32-bits per channel (128-bit) instead of 8-bits per channel (32-bit) RGBA.
215
+ * @param {Object} [options.pdf] - Describes PDF specific options. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
216
+ * @param {string|Object} [options.pdf.background] - 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.
217
+ * @param {Object} [options.openSlide] - Describes OpenSlide specific options. Requires the use of a globally-installed libvips compiled with support for OpenSlide.
218
+ * @param {number} [options.openSlide.level=0] - Level to extract from a multi-level input, zero based.
219
+ * @param {Object} [options.jp2] - Describes JPEG 2000 specific options. Requires the use of a globally-installed libvips compiled with support for OpenJPEG.
220
+ * @param {boolean} [options.jp2.oneshot=false] - Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility.
221
+ * @returns {Sharp}
222
+ * @throws {Error} Invalid parameters
223
+ */
224
+ const Sharp = function (input, options) {
225
+ // biome-ignore lint/complexity/noArguments: constructor factory
226
+ if (arguments.length === 1 && !is.defined(input)) {
227
+ throw new Error('Invalid input');
228
+ }
229
+ if (!(this instanceof Sharp)) {
230
+ return new Sharp(input, options);
231
+ }
232
+ stream.Duplex.call(this);
233
+ this.options = {
234
+ // resize options
235
+ topOffsetPre: -1,
236
+ leftOffsetPre: -1,
237
+ widthPre: -1,
238
+ heightPre: -1,
239
+ topOffsetPost: -1,
240
+ leftOffsetPost: -1,
241
+ widthPost: -1,
242
+ heightPost: -1,
243
+ width: -1,
244
+ height: -1,
245
+ canvas: 'crop',
246
+ position: 0,
247
+ resizeBackground: [0, 0, 0, 255],
248
+ angle: 0,
249
+ rotationAngle: 0,
250
+ rotationBackground: [0, 0, 0, 255],
251
+ rotateBefore: false,
252
+ orientBefore: false,
253
+ flip: false,
254
+ flop: false,
255
+ extendTop: 0,
256
+ extendBottom: 0,
257
+ extendLeft: 0,
258
+ extendRight: 0,
259
+ extendBackground: [0, 0, 0, 255],
260
+ extendWith: 'background',
261
+ withoutEnlargement: false,
262
+ withoutReduction: false,
263
+ affineMatrix: [],
264
+ affineBackground: [0, 0, 0, 255],
265
+ affineIdx: 0,
266
+ affineIdy: 0,
267
+ affineOdx: 0,
268
+ affineOdy: 0,
269
+ affineInterpolator: this.constructor.interpolators.bilinear,
270
+ kernel: 'lanczos3',
271
+ fastShrinkOnLoad: true,
272
+ // operations
273
+ tint: [-1, 0, 0, 0],
274
+ flatten: false,
275
+ flattenBackground: [0, 0, 0],
276
+ unflatten: false,
277
+ negate: false,
278
+ negateAlpha: true,
279
+ medianSize: 0,
280
+ blurSigma: 0,
281
+ precision: 'integer',
282
+ minAmpl: 0.2,
283
+ sharpenSigma: 0,
284
+ sharpenM1: 1,
285
+ sharpenM2: 2,
286
+ sharpenX1: 2,
287
+ sharpenY2: 10,
288
+ sharpenY3: 20,
289
+ threshold: 0,
290
+ thresholdGrayscale: true,
291
+ trimBackground: [],
292
+ trimThreshold: -1,
293
+ trimLineArt: false,
294
+ trimMargin: 0,
295
+ dilateWidth: 0,
296
+ erodeWidth: 0,
297
+ gamma: 0,
298
+ gammaOut: 0,
299
+ greyscale: false,
300
+ normalise: false,
301
+ normaliseLower: 1,
302
+ normaliseUpper: 99,
303
+ claheWidth: 0,
304
+ claheHeight: 0,
305
+ claheMaxSlope: 3,
306
+ brightness: 1,
307
+ saturation: 1,
308
+ hue: 0,
309
+ lightness: 0,
310
+ booleanBufferIn: null,
311
+ booleanFileIn: '',
312
+ joinChannelIn: [],
313
+ extractChannel: -1,
314
+ removeAlpha: false,
315
+ ensureAlpha: -1,
316
+ colourspace: 'srgb',
317
+ colourspacePipeline: 'last',
318
+ composite: [],
319
+ // output
320
+ fileOut: '',
321
+ formatOut: 'input',
322
+ streamOut: false,
323
+ typedArrayOut: false,
324
+ keepMetadata: 0,
325
+ withMetadataOrientation: -1,
326
+ withMetadataDensity: 0,
327
+ withIccProfile: '',
328
+ withExif: {},
329
+ withExifMerge: true,
330
+ withXmp: '',
331
+ keepGainMap: false,
332
+ withGainMap: false,
333
+ resolveWithObject: false,
334
+ loop: -1,
335
+ delay: [],
336
+ // output format
337
+ jpegQuality: 80,
338
+ jpegProgressive: false,
339
+ jpegChromaSubsampling: '4:2:0',
340
+ jpegTrellisQuantisation: false,
341
+ jpegOvershootDeringing: false,
342
+ jpegOptimiseScans: false,
343
+ jpegOptimiseCoding: true,
344
+ jpegQuantisationTable: 0,
345
+ pngProgressive: false,
346
+ pngCompressionLevel: 6,
347
+ pngAdaptiveFiltering: false,
348
+ pngPalette: false,
349
+ pngQuality: 100,
350
+ pngEffort: 7,
351
+ pngBitdepth: 8,
352
+ pngDither: 1,
353
+ jp2Quality: 80,
354
+ jp2TileHeight: 512,
355
+ jp2TileWidth: 512,
356
+ jp2Lossless: false,
357
+ jp2ChromaSubsampling: '4:4:4',
358
+ webpQuality: 80,
359
+ webpAlphaQuality: 100,
360
+ webpLossless: false,
361
+ webpNearLossless: false,
362
+ webpSmartSubsample: false,
363
+ webpSmartDeblock: false,
364
+ webpPreset: 'default',
365
+ webpEffort: 4,
366
+ webpMinSize: false,
367
+ webpMixed: false,
368
+ webpExact: false,
369
+ gifBitdepth: 8,
370
+ gifEffort: 7,
371
+ gifDither: 1,
372
+ gifInterFrameMaxError: 0,
373
+ gifInterPaletteMaxError: 3,
374
+ gifKeepDuplicateFrames: false,
375
+ gifReuse: true,
376
+ gifProgressive: false,
377
+ tiffQuality: 80,
378
+ tiffCompression: 'jpeg',
379
+ tiffBigtiff: false,
380
+ tiffPredictor: 'horizontal',
381
+ tiffPyramid: false,
382
+ tiffMiniswhite: false,
383
+ tiffBitdepth: 0,
384
+ tiffTile: false,
385
+ tiffTileHeight: 256,
386
+ tiffTileWidth: 256,
387
+ tiffXres: 1.0,
388
+ tiffYres: 1.0,
389
+ tiffResolutionUnit: 'inch',
390
+ heifQuality: 50,
391
+ heifLossless: false,
392
+ heifCompression: 'av1',
393
+ heifEffort: 4,
394
+ heifChromaSubsampling: '4:4:4',
395
+ heifBitdepth: 8,
396
+ heifTune: 'auto',
397
+ heifEncoder: 'auto',
398
+ jxlDistance: 1,
399
+ jxlDecodingTier: 0,
400
+ jxlEffort: 7,
401
+ jxlLossless: false,
402
+ rawDepth: 'uchar',
403
+ tileSize: 256,
404
+ tileOverlap: 0,
405
+ tileContainer: 'fs',
406
+ tileLayout: 'dz',
407
+ tileFormat: 'last',
408
+ tileDepth: 'last',
409
+ tileAngle: 0,
410
+ tileSkipBlanks: -1,
411
+ tileBackground: [255, 255, 255, 255],
412
+ tileCentre: false,
413
+ tileId: 'https://example.com/iiif',
414
+ tileBasename: '',
415
+ timeoutSeconds: 0,
416
+ linearA: [],
417
+ linearB: [],
418
+ pdfBackground: [255, 255, 255, 255],
419
+ // Function to notify of libvips warnings
420
+ debuglog: warning => {
421
+ this.emit('warning', warning);
422
+ debuglog(warning);
423
+ },
424
+ // Function to notify of queue length changes
425
+ queueListener
426
+ };
427
+ this.options.input = this._createInputDescriptor(input, options, { allowStream: true });
428
+ return this;
429
+ };
430
+ Object.setPrototypeOf(Sharp.prototype, stream.Duplex.prototype);
431
+ Object.setPrototypeOf(Sharp, stream.Duplex);
432
+
433
+ /**
434
+ * Take a "snapshot" of the Sharp instance, returning a new instance.
435
+ * Cloned instances inherit the input of their parent instance.
436
+ * This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
437
+ *
438
+ * @example
439
+ * // firstWritableStream receives auto-rotated, resized readableStream
440
+ * // secondWritableStream receives auto-rotated, extracted region of readableStream
441
+ *
442
+ * const pipeline = sharp().rotate();
443
+ * pipeline
444
+ * .clone()
445
+ * .resize(800, 600)
446
+ * .pipe(firstWritableStream);
447
+ * pipeline
448
+ * .clone()
449
+ * .extract({ left: 20, top: 20, width: 100, height: 100 })
450
+ * .pipe(secondWritableStream);
451
+ * readableStream.pipe(pipeline);
452
+ *
453
+ * @example
454
+ * // Create a pipeline that will download an image, resize it and format it to different files
455
+ * // Using Promises to know when the pipeline is complete
456
+ *
457
+ * const sharpStream = sharp();
458
+ *
459
+ * const promises = [];
460
+ * promises.push(
461
+ * sharpStream
462
+ * .clone()
463
+ * .jpeg({ quality: 100 })
464
+ * .toFile("originalFile.jpg")
465
+ * );
466
+ * promises.push(
467
+ * sharpStream
468
+ * .clone()
469
+ * .resize({ width: 500 })
470
+ * .jpeg({ quality: 80 })
471
+ * .toFile("optimized-500.jpg")
472
+ * );
473
+ * promises.push(
474
+ * sharpStream
475
+ * .clone()
476
+ * .resize({ width: 500 })
477
+ * .webp({ quality: 80 })
478
+ * .toFile("optimized-500.webp")
479
+ * );
480
+ *
481
+ * const res = await fetch("https://www.example.com/some-file.jpg")
482
+ * Readable.fromWeb(res.body).pipe(sharpStream);
483
+ * await Promise.all(promises);
484
+ *
485
+ * @returns {Sharp}
486
+ */
487
+ function clone () {
488
+ // Clone existing options
489
+ const clone = this.constructor.call();
490
+ const { debuglog, queueListener, ...options } = this.options;
491
+ clone.options = structuredClone(options);
492
+ clone.options.debuglog = debuglog;
493
+ clone.options.queueListener = queueListener;
494
+ // Pass 'finish' event to clone for Stream-based input
495
+ if (this._isStreamInput()) {
496
+ this.on('finish', () => {
497
+ // Clone inherits input data
498
+ this._flattenBufferIn();
499
+ clone.options.input.buffer = this.options.input.buffer;
500
+ clone.emit('finish');
501
+ });
502
+ }
503
+ return clone;
504
+ }
505
+ Object.assign(Sharp.prototype, { clone });
506
+
507
+ /**
508
+ * Export constructor.
509
+ * @module Sharp
510
+ * @private
511
+ */
512
+ export default Sharp;
package/dist/index.cjs ADDED
@@ -0,0 +1,25 @@
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ const Sharp = require('./constructor.cjs');
7
+ const input = require('./input.cjs');
8
+ const resize = require('./resize.cjs');
9
+ const composite = require('./composite.cjs');
10
+ const operation = require('./operation.cjs');
11
+ const colour = require('./colour.cjs');
12
+ const channel = require('./channel.cjs');
13
+ const output = require('./output.cjs');
14
+ const utility = require('./utility.cjs');
15
+
16
+ input(Sharp);
17
+ resize(Sharp);
18
+ composite(Sharp);
19
+ operation(Sharp);
20
+ colour(Sharp);
21
+ channel(Sharp);
22
+ output(Sharp);
23
+ utility(Sharp);
24
+
25
+ module.exports = Sharp;