@revizly/sharp 0.33.5-revizly2 → 0.33.6-revizly2

Sign up to get free protection for your applications and to get access to all the features.
package/lib/channel.js CHANGED
@@ -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) color channels.
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 color channel.
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
@@ -202,6 +202,7 @@ function composite (images) {
202
202
 
203
203
  /**
204
204
  * Decorate the Sharp prototype with composite-related functions.
205
+ * @module Sharp
205
206
  * @private
206
207
  */
207
208
  module.exports = function (Sharp) {
@@ -139,6 +139,7 @@ const debuglog = util.debuglog('sharp');
139
139
  * @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
140
140
  * @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
141
141
  * @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
142
+ * @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
143
  * @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
144
  * @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
144
145
  * @param {number} [options.raw.width] - integral number of pixels wide.
@@ -348,6 +349,7 @@ const Sharp = function (input, options) {
348
349
  timeoutSeconds: 0,
349
350
  linearA: [],
350
351
  linearB: [],
352
+ pdfBackground: [255, 255, 255, 255],
351
353
  // Function to notify of libvips warnings
352
354
  debuglog: warning => {
353
355
  this.emit('warning', warning);
@@ -447,6 +449,7 @@ Object.assign(Sharp.prototype, { clone });
447
449
 
448
450
  /**
449
451
  * Export constructor.
452
+ * @module Sharp
450
453
  * @private
451
454
  */
452
455
  module.exports = Sharp;
package/lib/index.d.ts CHANGED
@@ -244,14 +244,14 @@ declare namespace sharp {
244
244
  * @param tint Parsed by the color module.
245
245
  * @returns A sharp instance that can be used to chain operations
246
246
  */
247
- tint(tint: Color): Sharp;
247
+ tint(tint: Colour | Color): Sharp;
248
248
 
249
249
  /**
250
250
  * Convert to 8-bit greyscale; 256 shades of grey.
251
251
  * This is a linear operation.
252
252
  * 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) color channels.
254
- * This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
253
+ * By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
254
+ * This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel.
255
255
  * An alpha channel may be present, and will be unchanged by the operation.
256
256
  * @param greyscale true to enable and false to disable (defaults to true)
257
257
  * @returns A sharp instance that can be used to chain operations
@@ -401,7 +401,7 @@ declare namespace sharp {
401
401
  /**
402
402
  * Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
403
403
  * 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 color with the `background` option.
404
+ * By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
405
405
  * 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
406
  *
407
407
  * In the case of a 2x2 matrix, the transform is:
@@ -935,6 +935,8 @@ declare namespace sharp {
935
935
  subifd?: number | undefined;
936
936
  /** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
937
937
  level?: number | undefined;
938
+ /** 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. */
939
+ pdfBackground?: Colour | Color | undefined;
938
940
  /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
939
941
  animated?: boolean | undefined;
940
942
  /** Describes raw pixel input image data. See raw() for pixel ordering. */
@@ -969,7 +971,7 @@ declare namespace sharp {
969
971
  interface Raw {
970
972
  width: number;
971
973
  height: number;
972
- channels: 1 | 2 | 3 | 4;
974
+ channels: Channels;
973
975
  }
974
976
 
975
977
  interface CreateRaw extends Raw {
@@ -977,15 +979,17 @@ declare namespace sharp {
977
979
  premultiplied?: boolean | undefined;
978
980
  }
979
981
 
982
+ type CreateChannels = 3 | 4;
983
+
980
984
  interface Create {
981
985
  /** Number of pixels wide. */
982
986
  width: number;
983
987
  /** Number of pixels high. */
984
988
  height: number;
985
- /** Number of bands e.g. 3 for RGB, 4 for RGBA */
986
- channels: Channels;
989
+ /** Number of bands, 3 for RGB, 4 for RGBA */
990
+ channels: CreateChannels;
987
991
  /** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
988
- background: Color;
992
+ background: Colour | Color;
989
993
  /** Describes a noise to be created. */
990
994
  noise?: Noise | undefined;
991
995
  }
@@ -1339,7 +1343,7 @@ declare namespace sharp {
1339
1343
 
1340
1344
  interface RotateOptions {
1341
1345
  /** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
1342
- background?: Color | undefined;
1346
+ background?: Colour | Color | undefined;
1343
1347
  }
1344
1348
 
1345
1349
  type Precision = 'integer' | 'float' | 'approximate';
@@ -1355,7 +1359,7 @@ declare namespace sharp {
1355
1359
 
1356
1360
  interface FlattenOptions {
1357
1361
  /** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
1358
- background?: Color | undefined;
1362
+ background?: Colour | Color | undefined;
1359
1363
  }
1360
1364
 
1361
1365
  interface NegateOptions {
@@ -1380,7 +1384,7 @@ declare namespace sharp {
1380
1384
  /** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
1381
1385
  position?: number | string | undefined;
1382
1386
  /** 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;
1387
+ background?: Colour | Color | undefined;
1384
1388
  /** The kernel to use for image reduction. (optional, default 'lanczos3') */
1385
1389
  kernel?: keyof KernelEnum | undefined;
1386
1390
  /** 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 +1427,14 @@ declare namespace sharp {
1423
1427
  /** single pixel count to right edge (optional, default 0) */
1424
1428
  right?: number | undefined;
1425
1429
  /** 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;
1430
+ background?: Colour | Color | undefined;
1427
1431
  /** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
1428
1432
  extendWith?: ExtendWith | undefined;
1429
1433
  }
1430
1434
 
1431
1435
  interface TrimOptions {
1432
1436
  /** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
1433
- background?: Color | undefined;
1437
+ background?: Colour | Color | undefined;
1434
1438
  /** Allowed difference from the above colour, a positive number. (optional, default 10) */
1435
1439
  threshold?: number | undefined;
1436
1440
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
@@ -1441,8 +1445,8 @@ declare namespace sharp {
1441
1445
  depth?: 'char' | 'uchar' | 'short' | 'ushort' | 'int' | 'uint' | 'float' | 'complex' | 'double' | 'dpcomplex';
1442
1446
  }
1443
1447
 
1444
- /** 3 for sRGB, 4 for CMYK */
1445
- type Channels = 3 | 4;
1448
+ /** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
1449
+ type Channels = 1 | 2 | 3 | 4;
1446
1450
 
1447
1451
  interface RGBA {
1448
1452
  r?: number | undefined;
@@ -1451,7 +1455,8 @@ declare namespace sharp {
1451
1455
  alpha?: number | undefined;
1452
1456
  }
1453
1457
 
1454
- type Color = string | RGBA;
1458
+ type Colour = string | RGBA;
1459
+ type Color = Colour;
1455
1460
 
1456
1461
  interface Kernel {
1457
1462
  /** width of the kernel in pixels. */
@@ -1576,7 +1581,7 @@ declare namespace sharp {
1576
1581
  size: number;
1577
1582
  width: number;
1578
1583
  height: number;
1579
- channels: 1 | 2 | 3 | 4;
1584
+ channels: Channels;
1580
1585
  /** indicating if premultiplication was used */
1581
1586
  premultiplied: boolean;
1582
1587
  /** Only defined when using a crop strategy */
package/lib/input.js CHANGED
@@ -8,7 +8,7 @@ const is = require('./is');
8
8
  const sharp = require('./sharp');
9
9
 
10
10
  /**
11
- * Justication alignment
11
+ * Justification alignment
12
12
  * @member
13
13
  * @private
14
14
  */
@@ -24,9 +24,9 @@ const align = {
24
24
  * @private
25
25
  */
26
26
  function _inputOptionsFromObject (obj) {
27
- const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd } = obj;
28
- return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd].some(is.defined)
29
- ? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd }
27
+ const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground } = obj;
28
+ return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground].some(is.defined)
29
+ ? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground }
30
30
  : undefined;
31
31
  }
32
32
 
@@ -222,6 +222,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
222
222
  throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
223
223
  }
224
224
  }
225
+ // PDF background colour
226
+ if (is.defined(inputOptions.pdfBackground)) {
227
+ this._setBackgroundColourOption('pdfBackground', inputOptions.pdfBackground);
228
+ }
225
229
  // Create new image
226
230
  if (is.defined(inputOptions.create)) {
227
231
  if (
@@ -639,6 +643,7 @@ function stats (callback) {
639
643
 
640
644
  /**
641
645
  * Decorate the Sharp prototype with input-related functions.
646
+ * @module Sharp
642
647
  * @private
643
648
  */
644
649
  module.exports = function (Sharp) {
package/lib/operation.js CHANGED
@@ -128,7 +128,7 @@ function flop (flop) {
128
128
  * Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
129
129
  *
130
130
  * You must provide an array of length 4 or a 2x2 affine transformation matrix.
131
- * By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
131
+ * By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
132
132
  * A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
133
133
  *
134
134
  * In the case of a 2x2 matrix, the transform is:
@@ -930,6 +930,7 @@ function modulate (options) {
930
930
 
931
931
  /**
932
932
  * Decorate the Sharp prototype with operation-related functions.
933
+ * @module Sharp
933
934
  * @private
934
935
  */
935
936
  module.exports = function (Sharp) {
package/lib/output.js CHANGED
@@ -1551,6 +1551,7 @@ function _pipeline (callback, stack) {
1551
1551
 
1552
1552
  /**
1553
1553
  * Decorate the Sharp prototype with output-related functions.
1554
+ * @module Sharp
1554
1555
  * @private
1555
1556
  */
1556
1557
  module.exports = function (Sharp) {
package/lib/resize.js CHANGED
@@ -569,6 +569,7 @@ function trim (options) {
569
569
 
570
570
  /**
571
571
  * Decorate the Sharp prototype with resize-related functions.
572
+ * @module Sharp
572
573
  * @private
573
574
  */
574
575
  module.exports = function (Sharp) {
package/lib/utility.js CHANGED
@@ -280,6 +280,7 @@ function unblock (options) {
280
280
 
281
281
  /**
282
282
  * Decorate the Sharp class with utility-related functions.
283
+ * @module Sharp
283
284
  * @private
284
285
  */
285
286
  module.exports = function (Sharp) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revizly/sharp",
3
3
  "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
4
- "version": "0.33.5-revizly2",
4
+ "version": "0.33.6-revizly2",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -142,22 +142,21 @@
142
142
  "semver": "^7.6.3"
143
143
  },
144
144
  "optionalDependencies": {
145
- "@revizly/sharp-libvips-linux-arm64": "1.0.8",
146
- "@revizly/sharp-libvips-linux-x64": "1.0.8",
147
- "@revizly/sharp-linux-arm64": "0.33.5-revizly1",
148
- "@revizly/sharp-linux-x64": "0.33.5-revizly1"
145
+ "@revizly/sharp-libvips-linux-arm64": "1.0.9",
146
+ "@revizly/sharp-libvips-linux-x64": "1.0.9",
147
+ "@revizly/sharp-linux-arm64": "0.33.6-revizly1",
148
+ "@revizly/sharp-linux-x64": "0.33.6-revizly1"
149
149
  },
150
150
  "devDependencies": {
151
151
  "@emnapi/runtime": "^1.2.0",
152
- "@revizly/sharp-libvips-dev": "1.0.8",
152
+ "@revizly/sharp-libvips-dev": "1.0.9",
153
153
  "@types/node": "*",
154
- "async": "^3.2.5",
155
154
  "cc": "^3.0.1",
156
155
  "emnapi": "^1.2.0",
157
156
  "exif-reader": "^2.0.1",
158
157
  "extract-zip": "^2.0.1",
159
158
  "icc": "^3.0.0",
160
- "jsdoc-to-markdown": "^8.0.3",
159
+ "jsdoc-to-markdown": "^9.0.0",
161
160
  "license-checker": "^25.0.1",
162
161
  "mocha": "^10.7.3",
163
162
  "node-addon-api": "^8.1.0",
@@ -165,14 +164,14 @@
165
164
  "prebuild": "^13.0.1",
166
165
  "semistandard": "^17.0.0",
167
166
  "tar-fs": "^3.0.6",
168
- "tsd": "^0.31.1"
167
+ "tsd": "^0.31.2"
169
168
  },
170
169
  "license": "Apache-2.0",
171
170
  "engines": {
172
171
  "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
173
172
  },
174
173
  "config": {
175
- "libvips": ">=8.15.3"
174
+ "libvips": ">=8.16.0"
176
175
  },
177
176
  "funding": {
178
177
  "url": "https://opencollective.com/libvips"
package/src/binding.gyp CHANGED
@@ -12,7 +12,7 @@
12
12
  'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
13
13
  },
14
14
  'targets': [{
15
- 'target_name': 'libvips-cpp',
15
+ 'target_name': 'libvips-cpp-<(vips_version)',
16
16
  'conditions': [
17
17
  ['OS == "win"', {
18
18
  # Build libvips C++ binding for Windows due to MSVC std library ABI changes
@@ -83,7 +83,7 @@
83
83
  ],
84
84
  'dependencies': [
85
85
  '<!(node -p "require(\'node-addon-api\').gyp")',
86
- 'libvips-cpp'
86
+ 'libvips-cpp-<(vips_version)'
87
87
  ],
88
88
  'variables': {
89
89
  'conditions': [
@@ -149,7 +149,7 @@
149
149
  ['OS == "mac"', {
150
150
  'link_settings': {
151
151
  'libraries': [
152
- 'libvips-cpp.42.dylib'
152
+ 'libvips-cpp.<(vips_version).dylib'
153
153
  ]
154
154
  },
155
155
  'xcode_settings': {
@@ -169,7 +169,7 @@
169
169
  ],
170
170
  'link_settings': {
171
171
  'libraries': [
172
- '-l:libvips-cpp.so.42'
172
+ '-l:libvips-cpp.so.<(vips_version)'
173
173
  ],
174
174
  'ldflags': [
175
175
  '-Wl,-s',
package/src/common.cc CHANGED
@@ -109,6 +109,10 @@ namespace sharp {
109
109
  if (HasAttr(input, "subifd")) {
110
110
  descriptor->subifd = AttrAsInt32(input, "subifd");
111
111
  }
112
+ // // PDF background color
113
+ if (HasAttr(input, "pdfBackground")) {
114
+ descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
115
+ }
112
116
  // Create new image
113
117
  if (HasAttr(input, "createChannels")) {
114
118
  descriptor->createChannels = AttrAsUint32(input, "createChannels");
@@ -402,6 +406,9 @@ namespace sharp {
402
406
  if (imageType == ImageType::TIFF) {
403
407
  option->set("subifd", descriptor->subifd);
404
408
  }
409
+ if (imageType == ImageType::PDF) {
410
+ option->set("background", descriptor->pdfBackground);
411
+ }
405
412
  image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
406
413
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
407
414
  image = SetDensity(image, descriptor->density);
@@ -506,6 +513,9 @@ namespace sharp {
506
513
  if (imageType == ImageType::TIFF) {
507
514
  option->set("subifd", descriptor->subifd);
508
515
  }
516
+ if (imageType == ImageType::PDF) {
517
+ option->set("background", descriptor->pdfBackground);
518
+ }
509
519
  image = VImage::new_from_file(descriptor->file.data(), option);
510
520
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
511
521
  image = SetDensity(image, descriptor->density);
package/src/common.h CHANGED
@@ -15,9 +15,9 @@
15
15
  // Verify platform and compiler compatibility
16
16
 
17
17
  #if (VIPS_MAJOR_VERSION < 8) || \
18
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 15) || \
19
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 15 && VIPS_MICRO_VERSION < 3)
20
- #error "libvips version 8.15.3+ is required - please see https://sharp.pixelplumbing.com/install"
18
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 16) || \
19
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 16 && VIPS_MICRO_VERSION < 0)
20
+ #error "libvips version 8.16.0+ is required - please see https://sharp.pixelplumbing.com/install"
21
21
  #endif
22
22
 
23
23
  #if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
@@ -74,6 +74,7 @@ namespace sharp {
74
74
  int textSpacing;
75
75
  VipsTextWrap textWrap;
76
76
  int textAutofitDpi;
77
+ std::vector<double> pdfBackground;
77
78
 
78
79
  InputDescriptor():
79
80
  buffer(nullptr),
@@ -108,7 +109,8 @@ namespace sharp {
108
109
  textRgba(false),
109
110
  textSpacing(0),
110
111
  textWrap(VIPS_TEXT_WRAP_WORD),
111
- textAutofitDpi(0) {}
112
+ textAutofitDpi(0),
113
+ pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
112
114
  };
113
115
 
114
116
  // Convenience methods to access the attributes of a Napi::Object