sharp 0.35.0-rc.0 → 0.35.0-rc.3

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/README.md CHANGED
@@ -38,31 +38,27 @@ npm install sharp
38
38
  ```
39
39
 
40
40
  ```javascript
41
+ // ESM
42
+ import sharp from 'sharp';
43
+
44
+ // CJS
41
45
  const sharp = require('sharp');
42
46
  ```
43
47
 
44
- ### Callback
45
-
46
48
  ```javascript
47
- sharp(inputBuffer)
48
- .resize(320, 240)
49
+ await sharp(inputBuffer)
50
+ .resize({ width: 320, height: 240 })
49
51
  .toFile('output.webp', (err, info) => { ... });
50
52
  ```
51
53
 
52
- ### Promise
53
-
54
54
  ```javascript
55
- sharp('input.jpg')
56
- .rotate()
57
- .resize(200)
55
+ const output = await sharp('input.jpg')
56
+ .autoOrient()
57
+ .resize({ width: 200 })
58
58
  .jpeg({ mozjpeg: true })
59
- .toBuffer()
60
- .then( data => { ... })
61
- .catch( err => { ... });
59
+ .toBuffer();
62
60
  ```
63
61
 
64
- ### Async/await
65
-
66
62
  ```javascript
67
63
  const semiTransparentRedPng = await sharp({
68
64
  create: {
@@ -76,8 +72,6 @@ const semiTransparentRedPng = await sharp({
76
72
  .toBuffer();
77
73
  ```
78
74
 
79
- ### Stream
80
-
81
75
  ```javascript
82
76
  const roundedCorners = Buffer.from(
83
77
  '<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
package/install/build.js CHANGED
@@ -8,7 +8,7 @@ const {
8
8
  globalLibvipsVersion,
9
9
  log,
10
10
  spawnRebuild,
11
- } = require('../lib/libvips');
11
+ } = require('../dist/libvips.cjs');
12
12
 
13
13
  log('Building from source');
14
14
  log('See https://sharp.pixelplumbing.com/install#building-from-source');
package/lib/index.d.ts CHANGED
@@ -28,6 +28,7 @@
28
28
  /// <reference types="node" />
29
29
 
30
30
  import type { Duplex } from 'node:stream';
31
+ import { ColorLike } from '@img/colour';
31
32
 
32
33
  //#region Constructor functions
33
34
 
@@ -234,7 +235,7 @@ declare namespace sharp {
234
235
  * @param tint Parsed by the color module.
235
236
  * @returns A sharp instance that can be used to chain operations
236
237
  */
237
- tint(tint: Colour | Color): Sharp;
238
+ tint(tint: ColorLike): Sharp;
238
239
 
239
240
  /**
240
241
  * Convert to 8-bit greyscale; 256 shades of grey.
@@ -684,6 +685,14 @@ declare namespace sharp {
684
685
  */
685
686
  toUint8Array(): Promise<{ data: Uint8Array; info: OutputInfo }>;
686
687
 
688
+ /**
689
+ * Set output density (DPI) in EXIF metadata.
690
+ * @param density Density in dots per inch (DPI).
691
+ * @returns A sharp instance that can be used to chain operations
692
+ * @throws {Error} Invalid parameters
693
+ */
694
+ withDensity(density: number): Sharp;
695
+
687
696
  /**
688
697
  * Keep all EXIF metadata from the input image in the output image.
689
698
  * EXIF metadata is unsupported for TIFF output.
@@ -993,7 +1002,7 @@ declare namespace sharp {
993
1002
  unlimited?: boolean | undefined;
994
1003
  /** Set this to false to use random access rather than sequential read. Some operations will do this automatically. */
995
1004
  sequentialRead?: boolean | undefined;
996
- /** Number representing the DPI for vector images in the range 1 to 100000. (optional, default 72) */
1005
+ /** The DPI at which to render SVG and PDF images, in the range 1 to 100000. (optional, default 72) */
997
1006
  density?: number | undefined;
998
1007
  /** Should the embedded ICC profile, if any, be ignored. */
999
1008
  ignoreIcc?: boolean | undefined;
@@ -1014,7 +1023,7 @@ declare namespace sharp {
1014
1023
  /** @deprecated Use {@link SharpOptions.tiff} instead */
1015
1024
  subifd?: number | undefined;
1016
1025
  /** @deprecated Use {@link SharpOptions.pdf} instead */
1017
- pdfBackground?: Colour | Color | undefined;
1026
+ pdfBackground?: ColorLike | undefined;
1018
1027
  /** @deprecated Use {@link SharpOptions.openSlide} instead */
1019
1028
  level?: number | undefined;
1020
1029
  /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
@@ -1073,7 +1082,7 @@ declare namespace sharp {
1073
1082
  /** Number of bands, 3 for RGB, 4 for RGBA */
1074
1083
  channels: CreateChannels;
1075
1084
  /** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
1076
- background: Colour | Color;
1085
+ background: ColorLike;
1077
1086
  /** Describes a noise to be created. */
1078
1087
  noise?: Noise | undefined;
1079
1088
  /** The height of each page/frame for animated images, must be an integral factor of the overall image height. */
@@ -1120,7 +1129,7 @@ declare namespace sharp {
1120
1129
  /** Space between images, in pixels. */
1121
1130
  shim?: number | undefined;
1122
1131
  /** Background colour. */
1123
- background?: Colour | Color | undefined;
1132
+ background?: ColorLike | undefined;
1124
1133
  /** Horizontal alignment. */
1125
1134
  halign?: HorizontalAlignment | undefined;
1126
1135
  /** Vertical alignment. */
@@ -1141,7 +1150,7 @@ declare namespace sharp {
1141
1150
 
1142
1151
  interface PdfInputOptions {
1143
1152
  /** 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. */
1144
- background?: Colour | Color | undefined;
1153
+ background?: ColorLike | undefined;
1145
1154
  }
1146
1155
 
1147
1156
  interface OpenSlideInputOptions {
@@ -1479,8 +1488,8 @@ declare namespace sharp {
1479
1488
  xres?: number | undefined;
1480
1489
  /** Vertical resolution in pixels/mm (optional, default 1.0) */
1481
1490
  yres?: number | undefined;
1482
- /** Reduce bitdepth to 1, 2 or 4 bit (optional, default 8) */
1483
- bitdepth?: 1 | 2 | 4 | 8 | undefined;
1491
+ /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1492
+ bitdepth?: 1 | 2 | 4 | undefined;
1484
1493
  /** Write 1-bit images as miniswhite (optional, default false) */
1485
1494
  miniswhite?: boolean | undefined;
1486
1495
  /** Resolution unit options: inch, cm (optional, default 'inch') */
@@ -1510,7 +1519,7 @@ declare namespace sharp {
1510
1519
 
1511
1520
  interface RotateOptions {
1512
1521
  /** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
1513
- background?: Colour | Color | undefined;
1522
+ background?: ColorLike | undefined;
1514
1523
  }
1515
1524
 
1516
1525
  type Precision = 'integer' | 'float' | 'approximate';
@@ -1526,7 +1535,7 @@ declare namespace sharp {
1526
1535
 
1527
1536
  interface FlattenOptions {
1528
1537
  /** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
1529
- background?: Colour | Color | undefined;
1538
+ background?: ColorLike | undefined;
1530
1539
  }
1531
1540
 
1532
1541
  interface NegateOptions {
@@ -1551,7 +1560,7 @@ declare namespace sharp {
1551
1560
  /** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
1552
1561
  position?: number | string | undefined;
1553
1562
  /** 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}) */
1554
- background?: Colour | Color | undefined;
1563
+ background?: ColorLike | undefined;
1555
1564
  /** The kernel to use for image reduction. (optional, default 'lanczos3') */
1556
1565
  kernel?: keyof KernelEnum | undefined;
1557
1566
  /** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
@@ -1594,14 +1603,14 @@ declare namespace sharp {
1594
1603
  /** single pixel count to right edge (optional, default 0) */
1595
1604
  right?: number | undefined;
1596
1605
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1597
- background?: Colour | Color | undefined;
1606
+ background?: ColorLike | undefined;
1598
1607
  /** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
1599
1608
  extendWith?: ExtendWith | undefined;
1600
1609
  }
1601
1610
 
1602
1611
  interface TrimOptions {
1603
1612
  /** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
1604
- background?: Colour | Color | undefined;
1613
+ background?: ColorLike | undefined;
1605
1614
  /** Allowed difference from the above colour, a positive number. (optional, default 10) */
1606
1615
  threshold?: number | undefined;
1607
1616
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
@@ -1617,15 +1626,8 @@ declare namespace sharp {
1617
1626
  /** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
1618
1627
  type Channels = 1 | 2 | 3 | 4;
1619
1628
 
1620
- interface RGBA {
1621
- r?: number | undefined;
1622
- g?: number | undefined;
1623
- b?: number | undefined;
1624
- alpha?: number | undefined;
1625
- }
1626
-
1627
- type Colour = string | RGBA;
1628
- type Color = Colour;
1629
+ type Colour = ColorLike;
1630
+ type Color = ColorLike;
1629
1631
 
1630
1632
  interface Kernel {
1631
1633
  /** width of the kernel in pixels. */
@@ -1691,7 +1693,7 @@ declare namespace sharp {
1691
1693
  /** Tile angle of rotation, must be a multiple of 90. (optional, default 0) */
1692
1694
  angle?: number | undefined;
1693
1695
  /** background colour, parsed by the color module, defaults to white without transparency. (optional, default {r:255,g:255,b:255,alpha:1}) */
1694
- background?: string | RGBA | undefined;
1696
+ background?: ColorLike | undefined;
1695
1697
  /** How deep to make the pyramid, possible values are "onepixel", "onetile" or "one" (default based on layout) */
1696
1698
  depth?: string | undefined;
1697
1699
  /** Threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images */
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.35.0-rc.0",
4
+ "version": "0.35.0-rc.3",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -90,10 +90,12 @@
90
90
  "Dennis Beatty <dennis@dcbeatty.com>",
91
91
  "Ingvar Stepanyan <me@rreverser.com>",
92
92
  "Don Denton <don@happycollision.com>",
93
- "Dmytro Tiapukhin <cool.gegeg@gmail.com>"
93
+ "Dmytro Tiapukhin <cool.gegeg@gmail.com>",
94
+ "Florian Lefebvre <contact@florian-lefebvre.dev>"
94
95
  ],
95
96
  "scripts": {
96
97
  "build": "node install/build.js",
98
+ "build:dist": "node scripts/build.mjs",
97
99
  "clean": "rm -rf src/build/ test/fixtures/output.*",
98
100
  "test": "npm run lint && npm run test-unit",
99
101
  "lint": "npm run lint-cpp && npm run lint-js && npm run lint-types",
@@ -103,19 +105,28 @@
103
105
  "test-leak": "./test/leak/leak.sh",
104
106
  "test-unit": "node --experimental-test-coverage test/unit.mjs",
105
107
  "package-from-local-build": "node npm/from-local-build.js",
108
+ "package-wasm-wrappers": "node npm/wasm-wrappers.js",
106
109
  "package-release-notes": "node npm/release-notes.js",
107
110
  "docs-build": "node docs/build.mjs",
108
111
  "docs-serve": "cd docs && npm start",
109
112
  "docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
110
113
  },
111
114
  "type": "commonjs",
112
- "main": "lib/index.js",
113
- "types": "lib/index.d.ts",
114
115
  "files": [
116
+ "dist",
115
117
  "install",
116
- "lib",
118
+ "lib/index.d.ts",
117
119
  "src/*.{cc,h,gyp}"
118
120
  ],
121
+ "main": "./dist/index.cjs",
122
+ "module": "./dist/index.mjs",
123
+ "types": "./lib/index.d.ts",
124
+ "exports": {
125
+ ".": {
126
+ "import": "./dist/index.mjs",
127
+ "require": "./dist/index.cjs"
128
+ }
129
+ },
119
130
  "repository": {
120
131
  "type": "git",
121
132
  "url": "git://github.com/lovell/sharp.git"
@@ -139,53 +150,54 @@
139
150
  "vips"
140
151
  ],
141
152
  "dependencies": {
142
- "@img/colour": "^1.0.0",
153
+ "@img/colour": "^1.1.0",
143
154
  "detect-libc": "^2.1.2",
144
- "semver": "^7.7.3"
155
+ "semver": "^7.7.4"
145
156
  },
146
157
  "optionalDependencies": {
147
- "@img/sharp-darwin-arm64": "0.35.0-rc.0",
148
- "@img/sharp-darwin-x64": "0.35.0-rc.0",
149
- "@img/sharp-libvips-darwin-arm64": "1.3.0-rc.2",
150
- "@img/sharp-libvips-darwin-x64": "1.3.0-rc.2",
151
- "@img/sharp-libvips-linux-arm": "1.3.0-rc.2",
152
- "@img/sharp-libvips-linux-arm64": "1.3.0-rc.2",
153
- "@img/sharp-libvips-linux-ppc64": "1.3.0-rc.2",
154
- "@img/sharp-libvips-linux-riscv64": "1.3.0-rc.2",
155
- "@img/sharp-libvips-linux-s390x": "1.3.0-rc.2",
156
- "@img/sharp-libvips-linux-x64": "1.3.0-rc.2",
157
- "@img/sharp-libvips-linuxmusl-arm64": "1.3.0-rc.2",
158
- "@img/sharp-libvips-linuxmusl-x64": "1.3.0-rc.2",
159
- "@img/sharp-linux-arm": "0.35.0-rc.0",
160
- "@img/sharp-linux-arm64": "0.35.0-rc.0",
161
- "@img/sharp-linux-ppc64": "0.35.0-rc.0",
162
- "@img/sharp-linux-riscv64": "0.35.0-rc.0",
163
- "@img/sharp-linux-s390x": "0.35.0-rc.0",
164
- "@img/sharp-linux-x64": "0.35.0-rc.0",
165
- "@img/sharp-linuxmusl-arm64": "0.35.0-rc.0",
166
- "@img/sharp-linuxmusl-x64": "0.35.0-rc.0",
167
- "@img/sharp-wasm32": "0.35.0-rc.0",
168
- "@img/sharp-win32-arm64": "0.35.0-rc.0",
169
- "@img/sharp-win32-ia32": "0.35.0-rc.0",
170
- "@img/sharp-win32-x64": "0.35.0-rc.0"
158
+ "@img/sharp-darwin-arm64": "0.35.0-rc.3",
159
+ "@img/sharp-darwin-x64": "0.35.0-rc.3",
160
+ "@img/sharp-freebsd-wasm32": "0.35.0-rc.3",
161
+ "@img/sharp-libvips-darwin-arm64": "1.3.0-rc.5",
162
+ "@img/sharp-libvips-darwin-x64": "1.3.0-rc.5",
163
+ "@img/sharp-libvips-linux-arm": "1.3.0-rc.5",
164
+ "@img/sharp-libvips-linux-arm64": "1.3.0-rc.5",
165
+ "@img/sharp-libvips-linux-ppc64": "1.3.0-rc.5",
166
+ "@img/sharp-libvips-linux-riscv64": "1.3.0-rc.5",
167
+ "@img/sharp-libvips-linux-s390x": "1.3.0-rc.5",
168
+ "@img/sharp-libvips-linux-x64": "1.3.0-rc.5",
169
+ "@img/sharp-libvips-linuxmusl-arm64": "1.3.0-rc.5",
170
+ "@img/sharp-libvips-linuxmusl-x64": "1.3.0-rc.5",
171
+ "@img/sharp-linux-arm": "0.35.0-rc.3",
172
+ "@img/sharp-linux-arm64": "0.35.0-rc.3",
173
+ "@img/sharp-linux-ppc64": "0.35.0-rc.3",
174
+ "@img/sharp-linux-riscv64": "0.35.0-rc.3",
175
+ "@img/sharp-linux-s390x": "0.35.0-rc.3",
176
+ "@img/sharp-linux-x64": "0.35.0-rc.3",
177
+ "@img/sharp-linuxmusl-arm64": "0.35.0-rc.3",
178
+ "@img/sharp-linuxmusl-x64": "0.35.0-rc.3",
179
+ "@img/sharp-webcontainers-wasm32": "0.35.0-rc.3",
180
+ "@img/sharp-win32-arm64": "0.35.0-rc.3",
181
+ "@img/sharp-win32-ia32": "0.35.0-rc.3",
182
+ "@img/sharp-win32-x64": "0.35.0-rc.3"
171
183
  },
172
184
  "devDependencies": {
173
- "@biomejs/biome": "^2.3.10",
185
+ "@biomejs/biome": "^2.4.12",
174
186
  "@cpplint/cli": "^0.1.0",
175
- "@emnapi/runtime": "^1.7.1",
176
- "@img/sharp-libvips-dev": "1.3.0-rc.2",
177
- "@img/sharp-libvips-dev-wasm32": "1.3.0-rc.2",
178
- "@img/sharp-libvips-win32-arm64": "1.3.0-rc.2",
179
- "@img/sharp-libvips-win32-ia32": "1.3.0-rc.2",
180
- "@img/sharp-libvips-win32-x64": "1.3.0-rc.2",
187
+ "@emnapi/runtime": "^1.10.0",
188
+ "@img/sharp-libvips-dev": "1.3.0-rc.5",
189
+ "@img/sharp-libvips-dev-wasm32": "1.3.0-rc.5",
190
+ "@img/sharp-libvips-win32-arm64": "1.3.0-rc.5",
191
+ "@img/sharp-libvips-win32-ia32": "1.3.0-rc.5",
192
+ "@img/sharp-libvips-win32-x64": "1.3.0-rc.5",
181
193
  "@types/node": "*",
182
- "emnapi": "^1.7.1",
194
+ "emnapi": "^1.10.0",
183
195
  "exif-reader": "^2.0.3",
184
196
  "extract-zip": "^2.0.1",
185
197
  "icc": "^3.0.0",
186
- "node-addon-api": "^8.5.0",
187
- "node-gyp": "^12.1.0",
188
- "tar-fs": "^3.1.1",
198
+ "node-addon-api": "^8.7.0",
199
+ "node-gyp": "^12.2.0",
200
+ "tar-fs": "^3.1.2",
189
201
  "tsd": "^0.33.0"
190
202
  },
191
203
  "license": "Apache-2.0",
@@ -193,7 +205,7 @@
193
205
  "node": ">=20.9.0"
194
206
  },
195
207
  "config": {
196
- "libvips": ">=8.18.0"
208
+ "libvips": ">=8.18.2"
197
209
  },
198
210
  "funding": {
199
211
  "url": "https://opencollective.com/libvips"
package/src/binding.gyp CHANGED
@@ -3,14 +3,14 @@
3
3
 
4
4
  {
5
5
  'variables': {
6
- 'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
7
- 'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
6
+ 'vips_version': '<!(node -p "require(\'../dist/libvips.cjs\').minimumLibvipsVersion")',
7
+ 'platform_and_arch': '<!(node -p "require(\'../dist/libvips.cjs\').buildPlatformArch()")',
8
8
  'sharp_version': '<!(node -p "require(\'../package.json\').version")',
9
9
  'sharp_libvips_version': '<!(node -p "require(\'../package.json\').optionalDependencies[\'@img/sharp-libvips-<(platform_and_arch)\']")',
10
- 'sharp_libvips_yarn_locator': '<!(node -p "require(\'../lib/libvips\').yarnLocator()")',
11
- 'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
12
- 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
13
- 'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
10
+ 'sharp_libvips_yarn_locator': '<!(node -p "require(\'../dist/libvips.cjs\').yarnLocator()")',
11
+ 'sharp_libvips_include_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsIncludeDir()")',
12
+ 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsCPlusPlusDir()")',
13
+ 'sharp_libvips_lib_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsLibDir()")'
14
14
  },
15
15
  'targets': [{
16
16
  'target_name': 'libvips-cpp-<(vips_version)',
@@ -21,6 +21,7 @@
21
21
  'defines': [
22
22
  '_VIPS_PUBLIC=__declspec(dllexport)',
23
23
  '_ALLOW_KEYWORD_MACROS',
24
+ '_HAS_EXCEPTIONS=1',
24
25
  'G_DISABLE_ASSERT',
25
26
  'G_DISABLE_CAST_CHECKS',
26
27
  'G_DISABLE_CHECKS'
@@ -98,8 +99,8 @@
98
99
  'variables': {
99
100
  'conditions': [
100
101
  ['OS != "win"', {
101
- 'pkg_config_path': '<!(node -p "require(\'../lib/libvips\').pkgConfigPath()")',
102
- 'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips()).toString()")'
102
+ 'pkg_config_path': '<!(node -p "require(\'../dist/libvips.cjs\').pkgConfigPath()")',
103
+ 'use_global_libvips': '<!(node -p "Boolean(require(\'../dist/libvips.cjs\').useGlobalLibvips()).toString()")'
103
104
  }, {
104
105
  'pkg_config_path': '',
105
106
  'use_global_libvips': ''
@@ -148,7 +149,8 @@
148
149
  ['OS == "win"', {
149
150
  'defines': [
150
151
  '_ALLOW_KEYWORD_MACROS',
151
- '_FILE_OFFSET_BITS=64'
152
+ '_FILE_OFFSET_BITS=64',
153
+ '_HAS_EXCEPTIONS=1'
152
154
  ],
153
155
  'link_settings': {
154
156
  'libraries': [
@@ -203,14 +205,16 @@
203
205
  }],
204
206
  ['OS == "emscripten"', {
205
207
  'product_extension': 'node.js',
208
+ 'cflags_cc': [
209
+ '-fwasm-exceptions'
210
+ ],
206
211
  'link_settings': {
207
212
  'ldflags': [
208
- '-fexceptions',
213
+ '-fwasm-exceptions',
209
214
  '--pre-js=<!(node -p "require.resolve(\'./emscripten/pre.js\')")',
210
215
  '-Oz',
211
216
  '-sALLOW_MEMORY_GROWTH',
212
217
  '-sENVIRONMENT=node',
213
- '-sEXPORTED_FUNCTIONS=emnapiInit,_vips_shutdown,_uv_library_shutdown',
214
218
  '-sNODERAWFS',
215
219
  '-sWASM_ASYNC_COMPILATION=0'
216
220
  ],
package/src/common.cc CHANGED
@@ -426,7 +426,7 @@ namespace sharp {
426
426
  }
427
427
  if (ImageTypeSupportsPage(imageType)) {
428
428
  option->set("n", descriptor->pages);
429
- option->set("page", descriptor->page);
429
+ option->set("page", std::max(0, descriptor->page));
430
430
  }
431
431
  switch (imageType) {
432
432
  case ImageType::SVG:
@@ -456,6 +456,22 @@ namespace sharp {
456
456
  return option;
457
457
  }
458
458
 
459
+ /*
460
+ Should HEIF image be re-opened using the primary item?
461
+ */
462
+ static bool HeifPrimaryPageReopen(VImage image, InputDescriptor *descriptor) {
463
+ if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT && image.get_typeof("heif-primary") == G_TYPE_INT) {
464
+ if (image.get_int(VIPS_META_N_PAGES) > 1 && descriptor->pages == 1 && descriptor->page == -1) {
465
+ int const pagePrimary = image.get_int("heif-primary");
466
+ if (pagePrimary != 0) {
467
+ descriptor->page = pagePrimary;
468
+ return true;
469
+ }
470
+ }
471
+ }
472
+ return false;
473
+ }
474
+
459
475
  /*
460
476
  Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
461
477
  */
@@ -490,12 +506,15 @@ namespace sharp {
490
506
  image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
491
507
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
492
508
  image = SetDensity(image, descriptor->density);
509
+ } else if (imageType == ImageType::HEIF && HeifPrimaryPageReopen(image, descriptor)) {
510
+ option = GetOptionsForImageType(imageType, descriptor);
511
+ image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
493
512
  }
494
- } catch (vips::VError const &err) {
495
- throw vips::VError(std::string("Input buffer has corrupt header: ") + err.what());
513
+ } catch (std::runtime_error const &err) {
514
+ throw std::runtime_error(std::string("Input buffer has corrupt header: ") + err.what());
496
515
  }
497
516
  } else {
498
- throw vips::VError("Input buffer contains unsupported image format");
517
+ throw std::runtime_error("Input buffer contains unsupported image format");
499
518
  }
500
519
  }
501
520
  } else {
@@ -566,10 +585,10 @@ namespace sharp {
566
585
  imageType = DetermineImageType(descriptor->file.data());
567
586
  if (imageType == ImageType::MISSING) {
568
587
  if (descriptor->file.find("<svg") != std::string::npos) {
569
- throw vips::VError("Input file is missing, did you mean "
588
+ throw std::runtime_error("Input file is missing, did you mean "
570
589
  "sharp(Buffer.from('" + descriptor->file.substr(0, 8) + "...')?");
571
590
  }
572
- throw vips::VError("Input file is missing: " + descriptor->file);
591
+ throw std::runtime_error("Input file is missing: " + descriptor->file);
573
592
  }
574
593
  if (imageType != ImageType::UNKNOWN) {
575
594
  try {
@@ -577,12 +596,15 @@ namespace sharp {
577
596
  image = VImage::new_from_file(descriptor->file.data(), option);
578
597
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
579
598
  image = SetDensity(image, descriptor->density);
599
+ } else if (imageType == ImageType::HEIF && HeifPrimaryPageReopen(image, descriptor)) {
600
+ option = GetOptionsForImageType(imageType, descriptor);
601
+ image = VImage::new_from_file(descriptor->file.data(), option);
580
602
  }
581
- } catch (vips::VError const &err) {
582
- throw vips::VError(std::string("Input file has corrupt header: ") + err.what());
603
+ } catch (std::runtime_error const &err) {
604
+ throw std::runtime_error(std::string("Input file has corrupt header: ") + err.what());
583
605
  }
584
606
  } else {
585
- throw vips::VError("Input file contains unsupported image format");
607
+ throw std::runtime_error("Input file contains unsupported image format");
586
608
  }
587
609
  }
588
610
  }
@@ -590,7 +612,7 @@ namespace sharp {
590
612
  // Limit input images to a given number of pixels, where pixels = width * height
591
613
  if (descriptor->limitInputPixels > 0 &&
592
614
  static_cast<uint64_t>(image.width()) * image.height() > descriptor->limitInputPixels) {
593
- throw vips::VError("Input image exceeds pixel limit");
615
+ throw std::runtime_error("Input image exceeds pixel limit");
594
616
  }
595
617
  return std::make_tuple(image, imageType);
596
618
  }
@@ -610,7 +632,7 @@ namespace sharp {
610
632
  if (HasProfile(image)) {
611
633
  size_t length;
612
634
  const void *data = image.get_blob(VIPS_META_ICC_NAME, &length);
613
- icc.first = static_cast<char*>(g_malloc(length));
635
+ icc.first = static_cast<char*>(vips_malloc(reinterpret_cast<VipsObject*>(image.get_image()), length));
614
636
  icc.second = length;
615
637
  memcpy(icc.first, data, length);
616
638
  }
@@ -623,7 +645,7 @@ namespace sharp {
623
645
  VImage SetProfile(VImage image, std::pair<char*, size_t> icc) {
624
646
  if (icc.first != nullptr) {
625
647
  image = image.copy();
626
- image.set(VIPS_META_ICC_NAME, reinterpret_cast<VipsCallbackFn>(vips_area_free_cb), icc.first, icc.second);
648
+ image.set(VIPS_META_ICC_NAME, nullptr, icc.first, icc.second);
627
649
  }
628
650
  return image;
629
651
  }
@@ -766,19 +788,19 @@ namespace sharp {
766
788
  : image.height();
767
789
  if (imageType == ImageType::JPEG) {
768
790
  if (image.width() > 65535 || height > 65535) {
769
- throw vips::VError("Processed image is too large for the JPEG format");
791
+ throw std::runtime_error("Processed image is too large for the JPEG format");
770
792
  }
771
793
  } else if (imageType == ImageType::WEBP) {
772
794
  if (image.width() > 16383 || height > 16383) {
773
- throw vips::VError("Processed image is too large for the WebP format");
795
+ throw std::runtime_error("Processed image is too large for the WebP format");
774
796
  }
775
797
  } else if (imageType == ImageType::GIF) {
776
798
  if (image.width() > 65535 || height > 65535) {
777
- throw vips::VError("Processed image is too large for the GIF format");
799
+ throw std::runtime_error("Processed image is too large for the GIF format");
778
800
  }
779
801
  } else if (imageType == ImageType::HEIF) {
780
802
  if (image.width() > 16384 || height > 16384) {
781
- throw vips::VError("Processed image is too large for the HEIF format");
803
+ throw std::runtime_error("Processed image is too large for the HEIF format");
782
804
  }
783
805
  }
784
806
  }
@@ -1142,7 +1164,8 @@ namespace sharp {
1142
1164
  Does this image have a gain map?
1143
1165
  */
1144
1166
  bool HasGainMap(VImage image) {
1145
- return image.get_typeof("gainmap-data") == VIPS_TYPE_BLOB;
1167
+ return image.get_typeof("gainmap") == VIPS_TYPE_BLOB ||
1168
+ image.get_typeof("gainmap-data") == VIPS_TYPE_BLOB;
1146
1169
  }
1147
1170
 
1148
1171
  /*
@@ -1150,6 +1173,7 @@ namespace sharp {
1150
1173
  */
1151
1174
  VImage RemoveGainMap(VImage image) {
1152
1175
  VImage copy = image.copy();
1176
+ copy.remove("gainmap");
1153
1177
  copy.remove("gainmap-data");
1154
1178
  return copy;
1155
1179
  }
package/src/common.h CHANGED
@@ -19,8 +19,8 @@
19
19
 
20
20
  #if (VIPS_MAJOR_VERSION < 8) || \
21
21
  (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 18) || \
22
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 0)
23
- #error "libvips version 8.18.0+ is required - please see https://sharp.pixelplumbing.com/install"
22
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 2)
23
+ #error "libvips version 8.18.2+ is required - please see https://sharp.pixelplumbing.com/install"
24
24
  #endif
25
25
 
26
26
  #if defined(__has_include)
@@ -29,6 +29,12 @@
29
29
  #endif
30
30
  #endif
31
31
 
32
+ #ifdef __EMSCRIPTEN__
33
+ #define SHARP_CALLBACK_FN_NAME Call
34
+ #else
35
+ #define SHARP_CALLBACK_FN_NAME MakeCallback
36
+ #endif
37
+
32
38
  using vips::VImage;
33
39
 
34
40
  namespace sharp {
@@ -105,7 +111,7 @@ namespace sharp {
105
111
  rawPremultiplied(false),
106
112
  rawPageHeight(0),
107
113
  pages(1),
108
- page(0),
114
+ page(-1),
109
115
  createChannels(0),
110
116
  createWidth(0),
111
117
  createHeight(0),