sharp 0.32.3 → 0.32.5

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/index.d.ts CHANGED
@@ -1124,9 +1124,11 @@ declare namespace sharp {
1124
1124
  /** Level of CPU effort to reduce file size, integer 0-6 (optional, default 4) */
1125
1125
  effort?: number | undefined;
1126
1126
  /** Prevent use of animation key frames to minimise file size (slow) (optional, default false) */
1127
- minSize?: number;
1127
+ minSize?: boolean;
1128
1128
  /** Allow mixture of lossy and lossless animation frames (slow) (optional, default false) */
1129
1129
  mixed?: boolean;
1130
+ /** Preset options: one of default, photo, picture, drawing, icon, text (optional, default 'default') */
1131
+ preset?: keyof PresetEnum | undefined;
1130
1132
  }
1131
1133
 
1132
1134
  interface AvifOptions extends OutputOptions {
@@ -1476,6 +1478,15 @@ declare namespace sharp {
1476
1478
  lanczos3: 'lanczos3';
1477
1479
  }
1478
1480
 
1481
+ interface PresetEnum {
1482
+ default: 'default';
1483
+ picture: 'picture';
1484
+ photo: 'photo';
1485
+ drawing: 'drawing';
1486
+ icon: 'icon';
1487
+ text: 'text';
1488
+ }
1489
+
1479
1490
  interface BoolEnum {
1480
1491
  and: 'and';
1481
1492
  or: 'or';
package/lib/input.js CHANGED
@@ -432,6 +432,7 @@ function _isStreamInput () {
432
432
  * - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
433
433
  * - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
434
434
  * - `pageHeight`: Number of pixels high each page in a multi-page image will be.
435
+ * - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
435
436
  * - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
436
437
  * - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
437
438
  * - `pagePrimary`: Number of the primary page in a HEIF image
package/lib/resize.js CHANGED
@@ -126,7 +126,7 @@ function isResizeExpected (options) {
126
126
  *
127
127
  * Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
128
128
  *
129
- * <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.png">
129
+ * <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.svg">
130
130
  *
131
131
  * When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
132
132
  * - `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
package/lib/utility.js CHANGED
@@ -202,6 +202,72 @@ function simd (simd) {
202
202
  }
203
203
  simd(true);
204
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
+
205
271
  /**
206
272
  * Decorate the Sharp class with utility-related functions.
207
273
  * @private
@@ -216,4 +282,6 @@ module.exports = function (Sharp) {
216
282
  Sharp.versions = versions;
217
283
  Sharp.vendor = vendor;
218
284
  Sharp.queue = queue;
285
+ Sharp.block = block;
286
+ Sharp.unblock = unblock;
219
287
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "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.32.3",
4
+ "version": "0.32.5",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://github.com/lovell/sharp",
7
7
  "contributors": [
@@ -133,7 +133,7 @@
133
133
  ],
134
134
  "dependencies": {
135
135
  "color": "^4.2.3",
136
- "detect-libc": "^2.0.1",
136
+ "detect-libc": "^2.0.2",
137
137
  "node-addon-api": "^6.1.0",
138
138
  "prebuild-install": "^7.1.1",
139
139
  "semver": "^7.5.4",
@@ -159,19 +159,19 @@
159
159
  },
160
160
  "license": "Apache-2.0",
161
161
  "config": {
162
- "libvips": "8.14.2",
162
+ "libvips": "8.14.4",
163
163
  "integrity": {
164
- "darwin-arm64v8": "sha512-eUuxg6H0tXgX4z2lsaGtZ4cbPAm7yoFgkvPDd4csxoiVt+QUB25pEJwiXw7oB53VlBFIp3O8lbydSFS5zH8MQQ==",
165
- "darwin-x64": "sha512-cMT4v76IgzSR0VoXqLk/yftRyzMEZ+SBVMLzXCgqP/lmnYisrpmHHNqrWnoZbUUBXbPXLn6KMultYOJHe/c9ZQ==",
166
- "linux-arm64v8": "sha512-OcDJ/ly80pxwaKnw0W91sSvZczPtWsjmzrY/+6NMiQZT84LkmeaRuwErbHhorKDxnl7iZuNn9Uj5V25Xmj+LDQ==",
167
- "linux-armv6": "sha512-hk2ohSOYTJEtVQxEQFyQ+tuayKpYqx6NiXa7AE+8MF+yscxt+g+mLJ7TjDqtmb4ttFGH4IVfsEfU2YXIqWqkpg==",
168
- "linux-armv7": "sha512-/5Ci2Cd+yLZmTaEt9lVJ89elxX3RMJpps0ESjj43X40yrwka51QfXeg1QV38uNzZpCDIZkrbXZK0lyKldjpLuA==",
169
- "linux-x64": "sha512-wjCKmWfBb0uz1UB7rPDLvO0s+VWuoAY/Vv/YGCRFEQUkdSLQUgHExrOMMbOM3FleuYfQqznDYCXXphkl7X44+w==",
170
- "linuxmusl-arm64v8": "sha512-QtD2n90yi+rLE65C0gksFUU5uMUFPICI/pS3A0bgthpIcoCejAOYs3ZjVWpZbHQuV/lWahIUYO78MB9CzY860A==",
171
- "linuxmusl-x64": "sha512-TokQ/ETCJAsPYuxIMOPYDp25rlcwtpmIMtRUR9PB75TmZEJe7abRfCEInIPYeD8F/HxxnJSLiEdlbn1z1Jfzng==",
172
- "win32-arm64v8": "sha512-IIuj4EAgLqEVAoOuYH79C61a7TcJXlU/RBwk+5JsGWc2mr4J/Ar5J01e6XBvU4Lu3eqcU+3GPaACZEa1511buA==",
173
- "win32-ia32": "sha512-CsZi7lrReX3B6tmYgOGJ0IiAfcN5APDC6l+3gdosxfTfwpLLO+jXaSmyNwIGeMqrdgckG/gwwc+IrUZmkmjJ/A==",
174
- "win32-x64": "sha512-J7znmNKUK4ZKo6SnSnEtzT1xRAwvkGXxIx9/QihAadu1TFdS06yNhcENmwC4973+KZBlAdVpWbZ8sLrEoWkdCA=="
164
+ "darwin-arm64v8": "sha512-jZt5+ZBQzdloop9z/XlOAy8jHxD+ZGt3J8YUm1g3njjjKmZ/RmM9r6QAeLLILe67ATHaaAtmCil37fDc400OrQ==",
165
+ "darwin-x64": "sha512-Mhpr8n8CjrU+u5K9YLucmkCgwtJGexECLOZejPfqM8CiOMerowR0wJTuSt9WTOtb9qGOL/ndybfrymsw+YH8PA==",
166
+ "linux-arm64v8": "sha512-k2PiOOv8amzS4m5jc4Vceozv8h041IoyHL/1s0Rj290jg3w6BUJL3V+TLwKUPM35i7rV5rm14gtnGZ7qKENdmA==",
167
+ "linux-armv6": "sha512-CuPTo50owR8P+BCCcWk1tF4qB3XSAaHeaIzSanJM/v9zBZfUfMGI0OLv+ByyHCL3BE2CbGXaSXhuEVw2JQ08Sw==",
168
+ "linux-armv7": "sha512-CvD6fMy9PkZk1m2UPTWDcFfcD4qFA3RALyAWIih8ftOY9ksI3Y4uz6c0ML+ixBl0hqQK3WEg6+ac5TGDjZbbYA==",
169
+ "linux-x64": "sha512-vqoV61ka2hBYQ5582nQlyUcVPtItu927mng9RUU9nyO4Wt50z9nNT/pfcYEfF2jkBNW9JaiMaj6bENHgxA6mMg==",
170
+ "linuxmusl-arm64v8": "sha512-iCyl0y/qxdvgGidsYn11R8d4TEcU92uYHtYI8FSHyUobZw/9i2y3189PUTQ/fw44oqaBzTR3p9NF2eP6aLT9gQ==",
171
+ "linuxmusl-x64": "sha512-qj7IUqWUqCtxECpgNp4E1NcIbsNe1ujzBuJcnnQot7GZOuPUhI5N6ZUhozmh6LfbGFdBZpPc/JFh1eDZ0IEpbQ==",
172
+ "win32-arm64v8": "sha512-VRi7fpE9Kb3xQGcNmPPTJnWGAEUMq+YOq9abpaIIB2r3Ax327/7wHS7o2ezD6zQKdxIX6gODC5io/hReIJ9Jnw==",
173
+ "win32-ia32": "sha512-EnvtU7Q6+pjl5/Y1/UngCFDM2CSqpYWVDwY03ilUKSuqTeDKTJYyus0rJ+n6p4nmdjJlVdhYlkvpy8kkEAtDHg==",
174
+ "win32-x64": "sha512-fCl/KQuSijVYC8hULWbff8Mfuh3vjjdz4j5p73VgdLP6aZUrHctbhBvEIe0aQ8HpmcGdBnATX5pXUQ4GDl3mwQ=="
175
175
  },
176
176
  "runtime": "napi",
177
177
  "target": 7
package/src/common.cc CHANGED
@@ -964,12 +964,7 @@ namespace sharp {
964
964
  }
965
965
 
966
966
  std::pair<double, double> ResolveShrink(int width, int height, int targetWidth, int targetHeight,
967
- Canvas canvas, bool swap, bool withoutEnlargement, bool withoutReduction) {
968
- if (swap && canvas != Canvas::IGNORE_ASPECT) {
969
- // Swap input width and height when requested.
970
- std::swap(width, height);
971
- }
972
-
967
+ Canvas canvas, bool withoutEnlargement, bool withoutReduction) {
973
968
  double hshrink = 1.0;
974
969
  double vshrink = 1.0;
975
970
 
package/src/common.h CHANGED
@@ -15,8 +15,8 @@
15
15
 
16
16
  #if (VIPS_MAJOR_VERSION < 8) || \
17
17
  (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 14) || \
18
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 14 && VIPS_MICRO_VERSION < 2)
19
- #error "libvips version 8.14.2+ is required - please see https://sharp.pixelplumbing.com/install"
18
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 14 && VIPS_MICRO_VERSION < 4)
19
+ #error "libvips version 8.14.4+ is required - please see https://sharp.pixelplumbing.com/install"
20
20
  #endif
21
21
 
22
22
  #if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
@@ -362,13 +362,10 @@ namespace sharp {
362
362
  VImage EnsureAlpha(VImage image, double const value);
363
363
 
364
364
  /*
365
- Calculate the shrink factor, taking into account auto-rotate, the canvas
366
- mode, and so on. The hshrink/vshrink are the amount to shrink the input
367
- image axes by in order for the output axes (ie. after rotation) to match
368
- the required thumbnail width/height and canvas mode.
365
+ Calculate the horizontal and vertical shrink factors, taking the canvas mode into account.
369
366
  */
370
367
  std::pair<double, double> ResolveShrink(int width, int height, int targetWidth, int targetHeight,
371
- Canvas canvas, bool swap, bool withoutEnlargement, bool withoutReduction);
368
+ Canvas canvas, bool withoutEnlargement, bool withoutReduction);
372
369
 
373
370
  /*
374
371
  Ensure decoding remains sequential.
package/src/pipeline.cc CHANGED
@@ -20,18 +20,15 @@
20
20
  #include "operations.h"
21
21
  #include "pipeline.h"
22
22
 
23
- #if defined(WIN32)
23
+ #ifdef _WIN32
24
24
  #define STAT64_STRUCT __stat64
25
25
  #define STAT64_FUNCTION _stat64
26
- #elif defined(__APPLE__)
27
- #define STAT64_STRUCT stat
28
- #define STAT64_FUNCTION stat
29
- #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
30
- #define STAT64_STRUCT stat
31
- #define STAT64_FUNCTION stat
32
- #else
26
+ #elif defined(_LARGEFILE64_SOURCE)
33
27
  #define STAT64_STRUCT stat64
34
28
  #define STAT64_FUNCTION stat64
29
+ #else
30
+ #define STAT64_STRUCT stat
31
+ #define STAT64_FUNCTION stat
35
32
  #endif
36
33
 
37
34
  class PipelineWorker : public Napi::AsyncWorker {
@@ -160,15 +157,18 @@ class PipelineWorker : public Napi::AsyncWorker {
160
157
  int targetResizeWidth = baton->width;
161
158
  int targetResizeHeight = baton->height;
162
159
 
163
- // Swap input output width and height when rotating by 90 or 270 degrees
164
- bool swap = !baton->rotateBeforePreExtract &&
165
- (rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270 ||
166
- autoRotation == VIPS_ANGLE_D90 || autoRotation == VIPS_ANGLE_D270);
160
+ // When auto-rotating by 90 or 270 degrees, swap the target width and
161
+ // height to ensure the behavior aligns with how it would have been if
162
+ // the rotation had taken place *before* resizing.
163
+ if (!baton->rotateBeforePreExtract &&
164
+ (autoRotation == VIPS_ANGLE_D90 || autoRotation == VIPS_ANGLE_D270)) {
165
+ std::swap(targetResizeWidth, targetResizeHeight);
166
+ }
167
167
 
168
168
  // Shrink to pageHeight, so we work for multi-page images
169
169
  std::tie(hshrink, vshrink) = sharp::ResolveShrink(
170
170
  inputWidth, pageHeight, targetResizeWidth, targetResizeHeight,
171
- baton->canvas, swap, baton->withoutEnlargement, baton->withoutReduction);
171
+ baton->canvas, baton->withoutEnlargement, baton->withoutReduction);
172
172
 
173
173
  // The jpeg preload shrink.
174
174
  int jpegShrinkOnLoad = 1;
@@ -302,7 +302,7 @@ class PipelineWorker : public Napi::AsyncWorker {
302
302
  // Shrink to pageHeight, so we work for multi-page images
303
303
  std::tie(hshrink, vshrink) = sharp::ResolveShrink(
304
304
  inputWidth, pageHeight, targetResizeWidth, targetResizeHeight,
305
- baton->canvas, swap, baton->withoutEnlargement, baton->withoutReduction);
305
+ baton->canvas, baton->withoutEnlargement, baton->withoutReduction);
306
306
 
307
307
  int targetHeight = static_cast<int>(std::rint(static_cast<double>(pageHeight) / vshrink));
308
308
  int targetPageHeight = targetHeight;
@@ -788,9 +788,9 @@ class PipelineWorker : public Napi::AsyncWorker {
788
788
  }
789
789
 
790
790
  // Apply output ICC profile
791
- if (!baton->withMetadataIcc.empty()) {
791
+ if (baton->withMetadata) {
792
792
  image = image.icc_transform(
793
- const_cast<char*>(baton->withMetadataIcc.data()),
793
+ baton->withMetadataIcc.empty() ? "srgb" : const_cast<char*>(baton->withMetadataIcc.data()),
794
794
  VImage::option()
795
795
  ->set("input_profile", processingProfile)
796
796
  ->set("embedded", TRUE)
package/src/sharp.cc CHANGED
@@ -31,6 +31,7 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
31
31
  exports.Set("simd", Napi::Function::New(env, simd));
32
32
  exports.Set("libvipsVersion", Napi::Function::New(env, libvipsVersion));
33
33
  exports.Set("format", Napi::Function::New(env, format));
34
+ exports.Set("block", Napi::Function::New(env, block));
34
35
  exports.Set("_maxColourDistance", Napi::Function::New(env, _maxColourDistance));
35
36
  exports.Set("_isUsingJemalloc", Napi::Function::New(env, _isUsingJemalloc));
36
37
  exports.Set("stats", Napi::Function::New(env, stats));
package/src/utilities.cc CHANGED
@@ -164,6 +164,17 @@ Napi::Value format(const Napi::CallbackInfo& info) {
164
164
  return format;
165
165
  }
166
166
 
167
+ /*
168
+ (Un)block libvips operations at runtime.
169
+ */
170
+ void block(const Napi::CallbackInfo& info) {
171
+ Napi::Array ops = info[size_t(0)].As<Napi::Array>();
172
+ bool const state = info[size_t(1)].As<Napi::Boolean>().Value();
173
+ for (unsigned int i = 0; i < ops.Length(); i++) {
174
+ vips_operation_block_set(ops.Get(i).As<Napi::String>().Utf8Value().c_str(), state);
175
+ }
176
+ }
177
+
167
178
  /*
168
179
  Synchronous, internal-only method used by some of the functional tests.
169
180
  Calculates the maximum colour distance using the DE2000 algorithm
package/src/utilities.h CHANGED
@@ -12,6 +12,7 @@ Napi::Value counters(const Napi::CallbackInfo& info);
12
12
  Napi::Value simd(const Napi::CallbackInfo& info);
13
13
  Napi::Value libvipsVersion(const Napi::CallbackInfo& info);
14
14
  Napi::Value format(const Napi::CallbackInfo& info);
15
+ void block(const Napi::CallbackInfo& info);
15
16
  Napi::Value _maxColourDistance(const Napi::CallbackInfo& info);
16
17
  Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info);
17
18