@revizly/sharp 0.33.2-revizly3

Sign up to get free protection for your applications and to get access to all the features.
package/lib/utility.js ADDED
@@ -0,0 +1,286 @@
1
+ // Copyright 2013 Lovell Fuller and others.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ const events = require('node:events');
7
+ const detectLibc = require('detect-libc');
8
+
9
+ const is = require('./is');
10
+ const { runtimePlatformArch } = require('./libvips');
11
+ const sharp = require('./sharp');
12
+
13
+ const runtimePlatform = runtimePlatformArch();
14
+ const libvipsVersion = sharp.libvipsVersion();
15
+
16
+ /**
17
+ * An Object containing nested boolean values representing the available input and output formats/methods.
18
+ * @member
19
+ * @example
20
+ * console.log(sharp.format);
21
+ * @returns {Object}
22
+ */
23
+ const format = sharp.format();
24
+ format.heif.output.alias = ['avif', 'heic'];
25
+ format.jpeg.output.alias = ['jpe', 'jpg'];
26
+ format.tiff.output.alias = ['tif'];
27
+ format.jp2k.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
28
+
29
+ /**
30
+ * An Object containing the available interpolators and their proper values
31
+ * @readonly
32
+ * @enum {string}
33
+ */
34
+ const interpolators = {
35
+ /** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
36
+ nearest: 'nearest',
37
+ /** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
38
+ bilinear: 'bilinear',
39
+ /** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
40
+ bicubic: 'bicubic',
41
+ /** [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. */
42
+ locallyBoundedBicubic: 'lbb',
43
+ /** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
44
+ nohalo: 'nohalo',
45
+ /** [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
46
+ vertexSplitQuadraticBasisSpline: 'vsqbs'
47
+ };
48
+
49
+ /**
50
+ * An Object containing the version numbers of sharp, libvips
51
+ * and (when using prebuilt binaries) its dependencies.
52
+ *
53
+ * @member
54
+ * @example
55
+ * console.log(sharp.versions);
56
+ */
57
+ let versions = {
58
+ vips: libvipsVersion.semver
59
+ };
60
+ /* istanbul ignore next */
61
+ if (!libvipsVersion.isGlobal) {
62
+ if (!libvipsVersion.isWasm) {
63
+ try {
64
+ versions = require(`@revizly/sharp-${runtimePlatform}/versions`);
65
+ } catch (_) {
66
+ try {
67
+ versions = require(`@revizly/sharp-libvips-${runtimePlatform}/versions`);
68
+ } catch (_) {}
69
+ }
70
+ } else {
71
+ try {
72
+ versions = require('@revizly/sharp-wasm32/versions');
73
+ } catch (_) {}
74
+ }
75
+ }
76
+ versions.sharp = require('../package.json').version;
77
+
78
+ /**
79
+ * Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
80
+ * Existing entries in the cache will be trimmed after any change in limits.
81
+ * This method always returns cache statistics,
82
+ * useful for determining how much working memory is required for a particular task.
83
+ *
84
+ * @example
85
+ * const stats = sharp.cache();
86
+ * @example
87
+ * sharp.cache( { items: 200 } );
88
+ * sharp.cache( { files: 0 } );
89
+ * sharp.cache(false);
90
+ *
91
+ * @param {Object|boolean} [options=true] - Object with the following attributes, or boolean where true uses default cache settings and false removes all caching
92
+ * @param {number} [options.memory=50] - is the maximum memory in MB to use for this cache
93
+ * @param {number} [options.files=20] - is the maximum number of files to hold open
94
+ * @param {number} [options.items=100] - is the maximum number of operations to cache
95
+ * @returns {Object}
96
+ */
97
+ function cache (options) {
98
+ if (is.bool(options)) {
99
+ if (options) {
100
+ // Default cache settings of 50MB, 20 files, 100 items
101
+ return sharp.cache(50, 20, 100);
102
+ } else {
103
+ return sharp.cache(0, 0, 0);
104
+ }
105
+ } else if (is.object(options)) {
106
+ return sharp.cache(options.memory, options.files, options.items);
107
+ } else {
108
+ return sharp.cache();
109
+ }
110
+ }
111
+ cache(true);
112
+
113
+ /**
114
+ * Gets or, when a concurrency is provided, sets
115
+ * the maximum number of threads _libvips_ should use to process _each image_.
116
+ * These are from a thread pool managed by glib,
117
+ * which helps avoid the overhead of creating new threads.
118
+ *
119
+ * This method always returns the current concurrency.
120
+ *
121
+ * The default value is the number of CPU cores,
122
+ * except when using glibc-based Linux without jemalloc,
123
+ * where the default is `1` to help reduce memory fragmentation.
124
+ *
125
+ * A value of `0` will reset this to the number of CPU cores.
126
+ *
127
+ * Some image format libraries spawn additional threads,
128
+ * e.g. libaom manages its own 4 threads when encoding AVIF images,
129
+ * and these are independent of the value set here.
130
+ *
131
+ * The maximum number of images that sharp can process in parallel
132
+ * is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
133
+ * which defaults to 4.
134
+ *
135
+ * https://nodejs.org/api/cli.html#uv_threadpool_sizesize
136
+ *
137
+ * For example, by default, a machine with 8 CPU cores will process
138
+ * 4 images in parallel and use up to 8 threads per image,
139
+ * so there will be up to 32 concurrent threads.
140
+ *
141
+ * @example
142
+ * const threads = sharp.concurrency(); // 4
143
+ * sharp.concurrency(2); // 2
144
+ * sharp.concurrency(0); // 4
145
+ *
146
+ * @param {number} [concurrency]
147
+ * @returns {number} concurrency
148
+ */
149
+ function concurrency (concurrency) {
150
+ return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
151
+ }
152
+ /* istanbul ignore next */
153
+ if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
154
+ // Reduce default concurrency to 1 when using glibc memory allocator
155
+ sharp.concurrency(1);
156
+ }
157
+
158
+ /**
159
+ * An EventEmitter that emits a `change` event when a task is either:
160
+ * - queued, waiting for _libuv_ to provide a worker thread
161
+ * - complete
162
+ * @member
163
+ * @example
164
+ * sharp.queue.on('change', function(queueLength) {
165
+ * console.log('Queue contains ' + queueLength + ' task(s)');
166
+ * });
167
+ */
168
+ const queue = new events.EventEmitter();
169
+
170
+ /**
171
+ * Provides access to internal task counters.
172
+ * - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
173
+ * - process is the number of resize tasks currently being processed.
174
+ *
175
+ * @example
176
+ * const counters = sharp.counters(); // { queue: 2, process: 4 }
177
+ *
178
+ * @returns {Object}
179
+ */
180
+ function counters () {
181
+ return sharp.counters();
182
+ }
183
+
184
+ /**
185
+ * Get and set use of SIMD vector unit instructions.
186
+ * Requires libvips to have been compiled with highway support.
187
+ *
188
+ * Improves the performance of `resize`, `blur` and `sharpen` operations
189
+ * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
190
+ *
191
+ * @example
192
+ * const simd = sharp.simd();
193
+ * // simd is `true` if the runtime use of highway is currently enabled
194
+ * @example
195
+ * const simd = sharp.simd(false);
196
+ * // prevent libvips from using highway at runtime
197
+ *
198
+ * @param {boolean} [simd=true]
199
+ * @returns {boolean}
200
+ */
201
+ function simd (simd) {
202
+ return sharp.simd(is.bool(simd) ? simd : null);
203
+ }
204
+
205
+ /**
206
+ * Block libvips operations at runtime.
207
+ *
208
+ * This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
209
+ * which when set will block all "untrusted" operations.
210
+ *
211
+ * @since 0.32.4
212
+ *
213
+ * @example <caption>Block all TIFF input.</caption>
214
+ * sharp.block({
215
+ * operation: ['VipsForeignLoadTiff']
216
+ * });
217
+ *
218
+ * @param {Object} options
219
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to block.
220
+ */
221
+ function block (options) {
222
+ if (is.object(options)) {
223
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
224
+ sharp.block(options.operation, true);
225
+ } else {
226
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
227
+ }
228
+ } else {
229
+ throw is.invalidParameterError('options', 'object', options);
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Unblock libvips operations at runtime.
235
+ *
236
+ * This is useful for defining a list of allowed operations.
237
+ *
238
+ * @since 0.32.4
239
+ *
240
+ * @example <caption>Block all input except WebP from the filesystem.</caption>
241
+ * sharp.block({
242
+ * operation: ['VipsForeignLoad']
243
+ * });
244
+ * sharp.unblock({
245
+ * operation: ['VipsForeignLoadWebpFile']
246
+ * });
247
+ *
248
+ * @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
249
+ * sharp.block({
250
+ * operation: ['VipsForeignLoad']
251
+ * });
252
+ * sharp.unblock({
253
+ * operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
254
+ * });
255
+ *
256
+ * @param {Object} options
257
+ * @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
258
+ */
259
+ function unblock (options) {
260
+ if (is.object(options)) {
261
+ if (Array.isArray(options.operation) && options.operation.every(is.string)) {
262
+ sharp.block(options.operation, false);
263
+ } else {
264
+ throw is.invalidParameterError('operation', 'Array<string>', options.operation);
265
+ }
266
+ } else {
267
+ throw is.invalidParameterError('options', 'object', options);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Decorate the Sharp class with utility-related functions.
273
+ * @private
274
+ */
275
+ module.exports = function (Sharp) {
276
+ Sharp.cache = cache;
277
+ Sharp.concurrency = concurrency;
278
+ Sharp.counters = counters;
279
+ Sharp.simd = simd;
280
+ Sharp.format = format;
281
+ Sharp.interpolators = interpolators;
282
+ Sharp.versions = versions;
283
+ Sharp.queue = queue;
284
+ Sharp.block = block;
285
+ Sharp.unblock = unblock;
286
+ };
package/package.json ADDED
@@ -0,0 +1,218 @@
1
+ {
2
+ "name": "@revizly/sharp",
3
+ "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
4
+ "version": "0.33.2-revizly3",
5
+ "author": "Lovell Fuller <npm@lovell.info>",
6
+ "homepage": "https://sharp.pixelplumbing.com",
7
+ "contributors": [
8
+ "Pierre Inglebert <pierre.inglebert@gmail.com>",
9
+ "Jonathan Ong <jonathanrichardong@gmail.com>",
10
+ "Chanon Sajjamanochai <chanon.s@gmail.com>",
11
+ "Juliano Julio <julianojulio@gmail.com>",
12
+ "Daniel Gasienica <daniel@gasienica.ch>",
13
+ "Julian Walker <julian@fiftythree.com>",
14
+ "Amit Pitaru <pitaru.amit@gmail.com>",
15
+ "Brandon Aaron <hello.brandon@aaron.sh>",
16
+ "Andreas Lind <andreas@one.com>",
17
+ "Maurus Cuelenaere <mcuelenaere@gmail.com>",
18
+ "Linus Unnebäck <linus@folkdatorn.se>",
19
+ "Victor Mateevitsi <mvictoras@gmail.com>",
20
+ "Alaric Holloway <alaric.holloway@gmail.com>",
21
+ "Bernhard K. Weisshuhn <bkw@codingforce.com>",
22
+ "Chris Riley <criley@primedia.com>",
23
+ "David Carley <dacarley@gmail.com>",
24
+ "John Tobin <john@limelightmobileinc.com>",
25
+ "Kenton Gray <kentongray@gmail.com>",
26
+ "Felix Bünemann <Felix.Buenemann@gmail.com>",
27
+ "Samy Al Zahrani <samyalzahrany@gmail.com>",
28
+ "Chintan Thakkar <lemnisk8@gmail.com>",
29
+ "F. Orlando Galashan <frulo@gmx.de>",
30
+ "Kleis Auke Wolthuizen <info@kleisauke.nl>",
31
+ "Matt Hirsch <mhirsch@media.mit.edu>",
32
+ "Matthias Thoemmes <thoemmes@gmail.com>",
33
+ "Patrick Paskaris <patrick@paskaris.gr>",
34
+ "Jérémy Lal <kapouer@melix.org>",
35
+ "Rahul Nanwani <r.nanwani@gmail.com>",
36
+ "Alice Monday <alice0meta@gmail.com>",
37
+ "Kristo Jorgenson <kristo.jorgenson@gmail.com>",
38
+ "YvesBos <yves_bos@outlook.com>",
39
+ "Guy Maliar <guy@tailorbrands.com>",
40
+ "Nicolas Coden <nicolas@ncoden.fr>",
41
+ "Matt Parrish <matt.r.parrish@gmail.com>",
42
+ "Marcel Bretschneider <marcel.bretschneider@gmail.com>",
43
+ "Matthew McEachen <matthew+github@mceachen.org>",
44
+ "Jarda Kotěšovec <jarda.kotesovec@gmail.com>",
45
+ "Kenric D'Souza <kenric.dsouza@gmail.com>",
46
+ "Oleh Aleinyk <oleg.aleynik@gmail.com>",
47
+ "Marcel Bretschneider <marcel.bretschneider@gmail.com>",
48
+ "Andrea Bianco <andrea.bianco@unibas.ch>",
49
+ "Rik Heywood <rik@rik.org>",
50
+ "Thomas Parisot <hi@oncletom.io>",
51
+ "Nathan Graves <nathanrgraves+github@gmail.com>",
52
+ "Tom Lokhorst <tom@lokhorst.eu>",
53
+ "Espen Hovlandsdal <espen@hovlandsdal.com>",
54
+ "Sylvain Dumont <sylvain.dumont35@gmail.com>",
55
+ "Alun Davies <alun.owain.davies@googlemail.com>",
56
+ "Aidan Hoolachan <ajhoolachan21@gmail.com>",
57
+ "Axel Eirola <axel.eirola@iki.fi>",
58
+ "Freezy <freezy@xbmc.org>",
59
+ "Daiz <taneli.vatanen@gmail.com>",
60
+ "Julian Aubourg <j@ubourg.net>",
61
+ "Keith Belovay <keith@picthrive.com>",
62
+ "Michael B. Klein <mbklein@gmail.com>",
63
+ "Jordan Prudhomme <jordan@raboland.fr>",
64
+ "Ilya Ovdin <iovdin@gmail.com>",
65
+ "Andargor <andargor@yahoo.com>",
66
+ "Paul Neave <paul.neave@gmail.com>",
67
+ "Brendan Kennedy <brenwken@gmail.com>",
68
+ "Brychan Bennett-Odlum <git@brychan.io>",
69
+ "Edward Silverton <e.silverton@gmail.com>",
70
+ "Roman Malieiev <aromaleev@gmail.com>",
71
+ "Tomas Szabo <tomas.szabo@deftomat.com>",
72
+ "Robert O'Rourke <robert@o-rourke.org>",
73
+ "Guillermo Alfonso Varela Chouciño <guillevch@gmail.com>",
74
+ "Christian Flintrup <chr@gigahost.dk>",
75
+ "Manan Jadhav <manan@motionden.com>",
76
+ "Leon Radley <leon@radley.se>",
77
+ "alza54 <alza54@thiocod.in>",
78
+ "Jacob Smith <jacob@frende.me>",
79
+ "Michael Nutt <michael@nutt.im>",
80
+ "Brad Parham <baparham@gmail.com>",
81
+ "Taneli Vatanen <taneli.vatanen@gmail.com>",
82
+ "Joris Dugué <zaruike10@gmail.com>",
83
+ "Chris Banks <christopher.bradley.banks@gmail.com>",
84
+ "Ompal Singh <ompal.hitm09@gmail.com>",
85
+ "Brodan <christopher.hranj@gmail.com",
86
+ "Ankur Parihar <ankur.github@gmail.com>",
87
+ "Brahim Ait elhaj <brahima@gmail.com>",
88
+ "Mart Jansink <m.jansink@gmail.com>",
89
+ "Lachlan Newman <lachnewman007@gmail.com>",
90
+ "Dennis Beatty <dennis@dcbeatty.com>",
91
+ "Ingvar Stepanyan <me@rreverser.com>"
92
+ ],
93
+ "scripts": {
94
+ "install": "node install/check",
95
+ "clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
96
+ "test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
97
+ "test-lint": "semistandard && cpplint",
98
+ "test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
99
+ "test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
100
+ "test-leak": "./test/leak/leak.sh",
101
+ "test-types": "tsd",
102
+ "package-from-local-build": "node npm/from-local-build",
103
+ "package-from-github-release": "node npm/from-github-release",
104
+ "docs-build": "node docs/build && node docs/search-index/build",
105
+ "docs-serve": "cd docs && npx serve",
106
+ "docs-publish": ""
107
+ },
108
+ "type": "commonjs",
109
+ "main": "lib/index.js",
110
+ "types": "lib/index.d.ts",
111
+ "files": [
112
+ "install",
113
+ "lib",
114
+ "src/*.{cc,h,gyp}"
115
+ ],
116
+ "repository": {
117
+ "type": "git",
118
+ "url": "git://github.com/lovell/sharp.git"
119
+ },
120
+ "keywords": [
121
+ "jpeg",
122
+ "png",
123
+ "webp",
124
+ "avif",
125
+ "tiff",
126
+ "gif",
127
+ "svg",
128
+ "jp2",
129
+ "dzi",
130
+ "image",
131
+ "resize",
132
+ "thumbnail",
133
+ "crop",
134
+ "embed",
135
+ "libvips",
136
+ "vips"
137
+ ],
138
+ "dependencies": {
139
+ "color": "^4.2.3",
140
+ "detect-libc": "^2.0.2",
141
+ "semver": "^7.5.4"
142
+ },
143
+ "optionalDependencies": {
144
+ "@revizly/sharp-darwin-arm64": "0.33.2",
145
+ "@revizly/sharp-darwin-x64": "0.33.2",
146
+ "@revizly/sharp-libvips-darwin-arm64": "1.0.1",
147
+ "@revizly/sharp-libvips-darwin-x64": "1.0.1",
148
+ "@revizly/sharp-libvips-linux-arm": "1.0.1",
149
+ "@revizly/sharp-libvips-linux-arm64": "1.0.2",
150
+ "@revizly/sharp-libvips-linux-s390x": "1.0.1",
151
+ "@revizly/sharp-libvips-linux-x64": "1.0.2",
152
+ "@revizly/sharp-libvips-linuxmusl-arm64": "1.0.1",
153
+ "@revizly/sharp-libvips-linuxmusl-x64": "1.0.1",
154
+ "@revizly/sharp-linux-arm": "0.33.2",
155
+ "@revizly/sharp-linux-arm64": "0.33.2",
156
+ "@revizly/sharp-linux-s390x": "0.33.2",
157
+ "@revizly/sharp-linux-x64": "0.33.2",
158
+ "@revizly/sharp-linuxmusl-arm64": "0.33.2",
159
+ "@revizly/sharp-linuxmusl-x64": "0.33.2",
160
+ "@revizly/sharp-wasm32": "0.33.2",
161
+ "@revizly/sharp-win32-ia32": "0.33.2",
162
+ "@revizly/sharp-win32-x64": "0.33.2"
163
+ },
164
+ "devDependencies": {
165
+ "@emnapi/runtime": "^0.45.0",
166
+ "@revizly/sharp-libvips-dev": "1.0.2",
167
+ "@revizly/sharp-libvips-win32-ia32": "1.0.1",
168
+ "@revizly/sharp-libvips-win32-x64": "1.0.1",
169
+ "@types/node": "*",
170
+ "async": "^3.2.5",
171
+ "cc": "^3.0.1",
172
+ "emnapi": "^0.45.0",
173
+ "exif-reader": "^2.0.1",
174
+ "extract-zip": "^2.0.1",
175
+ "icc": "^3.0.0",
176
+ "jsdoc-to-markdown": "^8.0.1",
177
+ "license-checker": "^25.0.1",
178
+ "mocha": "^10.2.0",
179
+ "node-addon-api": "^7.1.0",
180
+ "nyc": "^15.1.0",
181
+ "prebuild": "^13.0.0",
182
+ "semistandard": "^17.0.0",
183
+ "tar-fs": "^3.0.4",
184
+ "tsd": "^0.30.4"
185
+ },
186
+ "license": "Apache-2.0",
187
+ "engines": {
188
+ "node": "^18.17.0 || ^20.3.0 || >=21.0.0",
189
+ "libvips": ">=8.15.1"
190
+ },
191
+ "funding": {
192
+ "url": "https://opencollective.com/libvips"
193
+ },
194
+ "binary": {
195
+ "napi_versions": [
196
+ 9
197
+ ]
198
+ },
199
+ "semistandard": {
200
+ "env": [
201
+ "mocha"
202
+ ]
203
+ },
204
+ "cc": {
205
+ "linelength": "120",
206
+ "filter": [
207
+ "build/include"
208
+ ]
209
+ },
210
+ "nyc": {
211
+ "include": [
212
+ "lib"
213
+ ]
214
+ },
215
+ "tsd": {
216
+ "directory": "test/types/"
217
+ }
218
+ }