sharp 0.32.5 → 0.33.0-alpha.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 +1 -1
- package/binding.gyp +54 -26
- package/install/check.js +27 -0
- package/lib/constructor.js +2 -3
- package/lib/index.d.ts +46 -7
- package/lib/is.js +14 -14
- package/lib/libvips.js +70 -57
- package/lib/operation.js +1 -5
- package/lib/output.js +14 -16
- package/lib/resize.js +4 -1
- package/lib/sharp.js +48 -26
- package/lib/utility.js +8 -22
- package/package.json +42 -39
- package/src/common.cc +5 -4
- package/src/common.h +5 -4
- package/src/metadata.cc +2 -2
- package/src/pipeline.cc +9 -8
- package/src/sharp.cc +6 -7
- package/src/stats.cc +2 -2
- package/src/utilities.cc +2 -2
- package/install/can-compile.js +0 -14
- package/install/dll-copy.js +0 -40
- package/install/libvips.js +0 -222
- package/lib/agent.js +0 -44
- package/lib/platform.js +0 -30
- package/src/libvips/cplusplus/VConnection.cpp +0 -151
- package/src/libvips/cplusplus/VError.cpp +0 -49
- package/src/libvips/cplusplus/VImage.cpp +0 -1548
- package/src/libvips/cplusplus/VInterpolate.cpp +0 -62
- package/src/libvips/cplusplus/VRegion.cpp +0 -27
- package/src/libvips/cplusplus/vips-operators.cpp +0 -3760
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|
|
16
16
|
As well as image resizing, operations such as
|
|
17
17
|
rotation, extraction, compositing and gamma correction are available.
|
|
18
18
|
|
|
19
|
-
Most modern macOS, Windows and Linux systems running Node.js >=
|
|
19
|
+
Most modern macOS, Windows and Linux systems running Node.js >= 18.17.0
|
|
20
20
|
do not require any additional install or runtime dependencies.
|
|
21
21
|
|
|
22
22
|
## Documentation
|
package/binding.gyp
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
# Copyright 2013 Lovell Fuller and others.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
1
4
|
{
|
|
2
5
|
'variables': {
|
|
3
6
|
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
|
|
4
|
-
'platform_and_arch': '<!(node -p "require(\'./lib/
|
|
5
|
-
'
|
|
7
|
+
'platform_and_arch': '<!(node -p "require(\'./lib/libvips\').buildPlatformArch()")',
|
|
8
|
+
'sharp_libvips_include_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsIncludeDir()")',
|
|
9
|
+
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
|
|
10
|
+
'sharp_libvips_lib_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsLibDir()")'
|
|
6
11
|
},
|
|
7
12
|
'targets': [{
|
|
8
13
|
'target_name': 'libvips-cpp',
|
|
@@ -15,19 +20,19 @@
|
|
|
15
20
|
'_ALLOW_KEYWORD_MACROS'
|
|
16
21
|
],
|
|
17
22
|
'sources': [
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
+
'<(sharp_libvips_cplusplus_dir)/VConnection.cpp',
|
|
24
|
+
'<(sharp_libvips_cplusplus_dir)/VError.cpp',
|
|
25
|
+
'<(sharp_libvips_cplusplus_dir)/VImage.cpp',
|
|
26
|
+
'<(sharp_libvips_cplusplus_dir)/VInterpolate.cpp',
|
|
27
|
+
'<(sharp_libvips_cplusplus_dir)/VRegion.cpp'
|
|
23
28
|
],
|
|
24
29
|
'include_dirs': [
|
|
25
|
-
'<(
|
|
26
|
-
'<(
|
|
27
|
-
'<(
|
|
30
|
+
'<(sharp_libvips_include_dir)',
|
|
31
|
+
'<(sharp_libvips_include_dir)/glib-2.0',
|
|
32
|
+
'<(sharp_libvips_lib_dir)/glib-2.0/include'
|
|
28
33
|
],
|
|
29
34
|
'link_settings': {
|
|
30
|
-
'library_dirs': ['<(
|
|
35
|
+
'library_dirs': ['<(sharp_libvips_lib_dir)'],
|
|
31
36
|
'libraries': [
|
|
32
37
|
'libvips.lib',
|
|
33
38
|
'libglib-2.0.lib',
|
|
@@ -70,7 +75,7 @@
|
|
|
70
75
|
}, {
|
|
71
76
|
'target_name': 'sharp-<(platform_and_arch)',
|
|
72
77
|
'defines': [
|
|
73
|
-
'NAPI_VERSION=
|
|
78
|
+
'NAPI_VERSION=9',
|
|
74
79
|
'NODE_ADDON_API_DISABLE_DEPRECATED',
|
|
75
80
|
'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'
|
|
76
81
|
],
|
|
@@ -79,7 +84,6 @@
|
|
|
79
84
|
'libvips-cpp'
|
|
80
85
|
],
|
|
81
86
|
'variables': {
|
|
82
|
-
'runtime_link%': 'shared',
|
|
83
87
|
'conditions': [
|
|
84
88
|
['OS != "win"', {
|
|
85
89
|
'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
|
|
@@ -106,12 +110,8 @@
|
|
|
106
110
|
['use_global_libvips == "true"', {
|
|
107
111
|
# Use pkg-config for include and lib
|
|
108
112
|
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
|
|
113
|
+
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
|
|
109
114
|
'conditions': [
|
|
110
|
-
['runtime_link == "static"', {
|
|
111
|
-
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs --static vips-cpp)']
|
|
112
|
-
}, {
|
|
113
|
-
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)']
|
|
114
|
-
}],
|
|
115
115
|
['OS == "linux"', {
|
|
116
116
|
'defines': [
|
|
117
117
|
# Inspect libvips-cpp.so to determine which C++11 ABI version was used and set _GLIBCXX_USE_CXX11_ABI accordingly. This is quite horrible.
|
|
@@ -122,9 +122,9 @@
|
|
|
122
122
|
}, {
|
|
123
123
|
# Use pre-built libvips stored locally within node_modules
|
|
124
124
|
'include_dirs': [
|
|
125
|
-
'<(
|
|
126
|
-
'<(
|
|
127
|
-
'<(
|
|
125
|
+
'<(sharp_libvips_include_dir)',
|
|
126
|
+
'<(sharp_libvips_include_dir)/glib-2.0',
|
|
127
|
+
'<(sharp_libvips_lib_dir)/glib-2.0/include'
|
|
128
128
|
],
|
|
129
129
|
'conditions': [
|
|
130
130
|
['OS == "win"', {
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
'_FILE_OFFSET_BITS=64'
|
|
134
134
|
],
|
|
135
135
|
'link_settings': {
|
|
136
|
-
'library_dirs': ['<(
|
|
136
|
+
'library_dirs': ['<(sharp_libvips_lib_dir)'],
|
|
137
137
|
'libraries': [
|
|
138
138
|
'libvips.lib',
|
|
139
139
|
'libglib-2.0.lib',
|
|
@@ -143,7 +143,9 @@
|
|
|
143
143
|
}],
|
|
144
144
|
['OS == "mac"', {
|
|
145
145
|
'link_settings': {
|
|
146
|
-
'library_dirs': [
|
|
146
|
+
'library_dirs': [
|
|
147
|
+
'<(sharp_libvips_lib_dir)'
|
|
148
|
+
],
|
|
147
149
|
'libraries': [
|
|
148
150
|
'libvips-cpp.42.dylib'
|
|
149
151
|
]
|
|
@@ -151,7 +153,9 @@
|
|
|
151
153
|
'xcode_settings': {
|
|
152
154
|
'OTHER_LDFLAGS': [
|
|
153
155
|
# Ensure runtime linking is relative to sharp.node
|
|
154
|
-
'-Wl,-rpath,\'@loader_path
|
|
156
|
+
'-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
|
157
|
+
'-Wl,-rpath,\'@loader_path/../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\'',
|
|
158
|
+
'-Wl,-rpath,\'@loader_path/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
|
|
155
159
|
]
|
|
156
160
|
}
|
|
157
161
|
}],
|
|
@@ -160,13 +164,19 @@
|
|
|
160
164
|
'_GLIBCXX_USE_CXX11_ABI=1'
|
|
161
165
|
],
|
|
162
166
|
'link_settings': {
|
|
163
|
-
'library_dirs': [
|
|
167
|
+
'library_dirs': [
|
|
168
|
+
'<(sharp_libvips_lib_dir)'
|
|
169
|
+
],
|
|
164
170
|
'libraries': [
|
|
165
171
|
'-l:libvips-cpp.so.42'
|
|
166
172
|
],
|
|
167
173
|
'ldflags': [
|
|
168
174
|
# Ensure runtime linking is relative to sharp.node
|
|
169
|
-
'-Wl,-s
|
|
175
|
+
'-Wl,-s',
|
|
176
|
+
'-Wl,--disable-new-dtags',
|
|
177
|
+
'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
|
178
|
+
'-Wl,-rpath=\'$$ORIGIN/../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\'',
|
|
179
|
+
'-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
|
|
170
180
|
]
|
|
171
181
|
}
|
|
172
182
|
}]
|
|
@@ -232,5 +242,23 @@
|
|
|
232
242
|
]
|
|
233
243
|
}
|
|
234
244
|
},
|
|
245
|
+
}, {
|
|
246
|
+
'target_name': 'copy-dll',
|
|
247
|
+
'type': 'none',
|
|
248
|
+
'dependencies': [
|
|
249
|
+
'sharp-<(platform_and_arch)'
|
|
250
|
+
],
|
|
251
|
+
'conditions': [
|
|
252
|
+
['OS == "win"', {
|
|
253
|
+
'copies': [{
|
|
254
|
+
'destination': 'build/Release',
|
|
255
|
+
'files': [
|
|
256
|
+
'<(sharp_libvips_lib_dir)/libvips-42.dll',
|
|
257
|
+
'<(sharp_libvips_lib_dir)/libglib-2.0-0.dll',
|
|
258
|
+
'<(sharp_libvips_lib_dir)/libgobject-2.0-0.dll'
|
|
259
|
+
]
|
|
260
|
+
}]
|
|
261
|
+
}]
|
|
262
|
+
]
|
|
235
263
|
}]
|
|
236
264
|
}
|
package/install/check.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2013 Lovell Fuller and others.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const { useGlobalLibvips, globalLibvipsVersion, log, gypRebuild } = require('../lib/libvips');
|
|
7
|
+
|
|
8
|
+
const buildFromSource = (msg) => {
|
|
9
|
+
log(msg);
|
|
10
|
+
log('Attempting to build from source via node-gyp');
|
|
11
|
+
try {
|
|
12
|
+
require('node-gyp');
|
|
13
|
+
} catch (err) {
|
|
14
|
+
log('You might need to install node-gyp');
|
|
15
|
+
}
|
|
16
|
+
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
|
17
|
+
const status = gypRebuild();
|
|
18
|
+
if (status !== 0) {
|
|
19
|
+
process.exit(status);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (useGlobalLibvips()) {
|
|
24
|
+
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
|
|
25
|
+
} else if (process.env.npm_config_build_from_source) {
|
|
26
|
+
buildFromSource('Detected --build-from-source flag');
|
|
27
|
+
}
|
package/lib/constructor.js
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const util = require('util');
|
|
7
|
-
const stream = require('stream');
|
|
6
|
+
const util = require('node:util');
|
|
7
|
+
const stream = require('node:stream');
|
|
8
8
|
const is = require('./is');
|
|
9
9
|
|
|
10
|
-
require('./libvips').hasVendoredLibvips();
|
|
11
10
|
require('./sharp');
|
|
12
11
|
|
|
13
12
|
// Use NODE_DEBUG=sharp to enable libvips warnings
|
package/lib/index.d.ts
CHANGED
|
@@ -91,12 +91,6 @@ declare namespace sharp {
|
|
|
91
91
|
zlib?: string | undefined;
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
-
/** An Object containing the platform and architecture of the current and installed vendored binaries. */
|
|
95
|
-
const vendor: {
|
|
96
|
-
current: string;
|
|
97
|
-
installed: string[];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
94
|
/** An Object containing the available interpolators and their proper values */
|
|
101
95
|
const interpolators: Interpolators;
|
|
102
96
|
|
|
@@ -139,6 +133,52 @@ declare namespace sharp {
|
|
|
139
133
|
*/
|
|
140
134
|
function simd(enable?: boolean): boolean;
|
|
141
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Block libvips operations at runtime.
|
|
138
|
+
*
|
|
139
|
+
* This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
|
|
140
|
+
* which when set will block all "untrusted" operations.
|
|
141
|
+
*
|
|
142
|
+
* @since 0.32.4
|
|
143
|
+
*
|
|
144
|
+
* @example <caption>Block all TIFF input.</caption>
|
|
145
|
+
* sharp.block({
|
|
146
|
+
* operation: ['VipsForeignLoadTiff']
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* @param {Object} options
|
|
150
|
+
* @param {Array<string>} options.operation - List of libvips low-level operation names to block.
|
|
151
|
+
*/
|
|
152
|
+
function block(options: { operation: string[] }): void;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Unblock libvips operations at runtime.
|
|
156
|
+
*
|
|
157
|
+
* This is useful for defining a list of allowed operations.
|
|
158
|
+
*
|
|
159
|
+
* @since 0.32.4
|
|
160
|
+
*
|
|
161
|
+
* @example <caption>Block all input except WebP from the filesystem.</caption>
|
|
162
|
+
* sharp.block({
|
|
163
|
+
* operation: ['VipsForeignLoad']
|
|
164
|
+
* });
|
|
165
|
+
* sharp.unblock({
|
|
166
|
+
* operation: ['VipsForeignLoadWebpFile']
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
|
|
170
|
+
* sharp.block({
|
|
171
|
+
* operation: ['VipsForeignLoad']
|
|
172
|
+
* });
|
|
173
|
+
* sharp.unblock({
|
|
174
|
+
* operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* @param {Object} options
|
|
178
|
+
* @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
|
|
179
|
+
*/
|
|
180
|
+
function unblock(options: { operation: string[] }): void;
|
|
181
|
+
|
|
142
182
|
//#endregion
|
|
143
183
|
|
|
144
184
|
const gravity: GravityEnum;
|
|
@@ -659,7 +699,6 @@ declare namespace sharp {
|
|
|
659
699
|
|
|
660
700
|
/**
|
|
661
701
|
* Use these AVIF options for output image.
|
|
662
|
-
* Whilst it is possible to create AVIF images smaller than 16x16 pixels, most web browsers do not display these properly.
|
|
663
702
|
* @param options Output options.
|
|
664
703
|
* @throws {Error} Invalid options
|
|
665
704
|
* @returns A sharp instance that can be used to chain operations
|
package/lib/is.js
CHANGED
|
@@ -138,18 +138,18 @@ const invalidParameterError = function (name, expected, actual) {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
module.exports = {
|
|
141
|
-
defined
|
|
142
|
-
object
|
|
143
|
-
plainObject
|
|
144
|
-
fn
|
|
145
|
-
bool
|
|
146
|
-
buffer
|
|
147
|
-
typedArray
|
|
148
|
-
arrayBuffer
|
|
149
|
-
string
|
|
150
|
-
number
|
|
151
|
-
integer
|
|
152
|
-
inRange
|
|
153
|
-
inArray
|
|
154
|
-
invalidParameterError
|
|
141
|
+
defined,
|
|
142
|
+
object,
|
|
143
|
+
plainObject,
|
|
144
|
+
fn,
|
|
145
|
+
bool,
|
|
146
|
+
buffer,
|
|
147
|
+
typedArray,
|
|
148
|
+
arrayBuffer,
|
|
149
|
+
string,
|
|
150
|
+
number,
|
|
151
|
+
integer,
|
|
152
|
+
inRange,
|
|
153
|
+
inArray,
|
|
154
|
+
invalidParameterError
|
|
155
155
|
};
|
package/lib/libvips.js
CHANGED
|
@@ -3,61 +3,74 @@
|
|
|
3
3
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const os = require('os');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const spawnSync = require('child_process').spawnSync;
|
|
6
|
+
const { spawnSync } = require('node:child_process');
|
|
10
7
|
const semverCoerce = require('semver/functions/coerce');
|
|
11
8
|
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
|
9
|
+
const detectLibc = require('detect-libc');
|
|
12
10
|
|
|
13
|
-
const
|
|
14
|
-
const { config } = require('../package.json');
|
|
11
|
+
const { engines } = require('../package.json');
|
|
15
12
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
config.libvips;
|
|
13
|
+
const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || /* istanbul ignore next */
|
|
14
|
+
engines.libvips;
|
|
19
15
|
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
|
20
16
|
|
|
17
|
+
const prebuiltPlatforms = [
|
|
18
|
+
'darwin-arm64', 'darwin-x64',
|
|
19
|
+
'linux-arm', 'linux-arm64', 'linux-x64',
|
|
20
|
+
'linuxmusl-arm64', 'linuxmusl-x64',
|
|
21
|
+
'win32-ia32', 'win32-x64'
|
|
22
|
+
];
|
|
23
|
+
|
|
21
24
|
const spawnSyncOptions = {
|
|
22
25
|
encoding: 'utf8',
|
|
23
26
|
shell: true
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} catch (err) {
|
|
32
|
-
/* istanbul ignore next */
|
|
33
|
-
if (err.code !== 'EEXIST') {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
29
|
+
const log = (item) => {
|
|
30
|
+
if (item instanceof Error) {
|
|
31
|
+
console.error(`sharp: Installation error: ${item.message}`);
|
|
32
|
+
} else {
|
|
33
|
+
console.log(`sharp: ${item}`);
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
|
|
39
|
+
|
|
40
|
+
const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
|
|
41
|
+
|
|
42
|
+
/* istanbul ignore next */
|
|
43
|
+
const buildPlatformArch = () => {
|
|
44
|
+
/* eslint camelcase: ["error", { allow: ["^npm_config_"] }] */
|
|
45
|
+
const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
|
|
46
|
+
return `${npm_config_platform || process.platform}${npm_config_libc || runtimeLibc()}-${npm_config_arch || process.arch}`;
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
-
|
|
49
|
+
const buildSharpLibvipsIncludeDir = () => {
|
|
50
|
+
try {
|
|
51
|
+
return require('@sharpen/sharp-libvips-dev/include');
|
|
52
|
+
} catch {}
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
return '';
|
|
50
55
|
};
|
|
51
56
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
const buildSharpLibvipsCPlusPlusDir = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('@sharpen/sharp-libvips-dev/cplusplus');
|
|
60
|
+
} catch {}
|
|
61
|
+
/* istanbul ignore next */
|
|
62
|
+
return '';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const buildSharpLibvipsLibDir = () => {
|
|
66
|
+
try {
|
|
67
|
+
return require(`@sharpen/sharp-libvips-${buildPlatformArch()}/lib`);
|
|
68
|
+
} catch {}
|
|
69
|
+
/* istanbul ignore next */
|
|
70
|
+
return '';
|
|
58
71
|
};
|
|
59
72
|
|
|
60
|
-
const isRosetta =
|
|
73
|
+
const isRosetta = () => {
|
|
61
74
|
/* istanbul ignore next */
|
|
62
75
|
if (process.platform === 'darwin' && process.arch === 'x64') {
|
|
63
76
|
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
|
|
@@ -66,12 +79,19 @@ const isRosetta = function () {
|
|
|
66
79
|
return false;
|
|
67
80
|
};
|
|
68
81
|
|
|
69
|
-
|
|
82
|
+
/* istanbul ignore next */
|
|
83
|
+
const gypRebuild = () =>
|
|
84
|
+
spawnSync('node-gyp rebuild', {
|
|
85
|
+
...spawnSyncOptions,
|
|
86
|
+
stdio: 'inherit'
|
|
87
|
+
}).status;
|
|
88
|
+
|
|
89
|
+
const globalLibvipsVersion = () => {
|
|
70
90
|
if (process.platform !== 'win32') {
|
|
71
91
|
const globalLibvipsVersion = spawnSync('pkg-config --modversion vips-cpp', {
|
|
72
92
|
...spawnSyncOptions,
|
|
73
93
|
env: {
|
|
74
|
-
...env,
|
|
94
|
+
...process.env,
|
|
75
95
|
PKG_CONFIG_PATH: pkgConfigPath()
|
|
76
96
|
}
|
|
77
97
|
}).stdout;
|
|
@@ -82,17 +102,8 @@ const globalLibvipsVersion = function () {
|
|
|
82
102
|
}
|
|
83
103
|
};
|
|
84
104
|
|
|
85
|
-
const hasVendoredLibvips = function () {
|
|
86
|
-
return fs.existsSync(vendorPath);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/* istanbul ignore next */
|
|
90
|
-
const removeVendoredLibvips = function () {
|
|
91
|
-
fs.rmSync(vendorPath, { recursive: true, maxRetries: 3, force: true });
|
|
92
|
-
};
|
|
93
|
-
|
|
94
105
|
/* istanbul ignore next */
|
|
95
|
-
const pkgConfigPath =
|
|
106
|
+
const pkgConfigPath = () => {
|
|
96
107
|
if (process.platform !== 'win32') {
|
|
97
108
|
const brewPkgConfigPath = spawnSync(
|
|
98
109
|
'which brew >/dev/null 2>&1 && brew environment --plain | grep PKG_CONFIG_LIBDIR | cut -d" " -f2',
|
|
@@ -100,7 +111,7 @@ const pkgConfigPath = function () {
|
|
|
100
111
|
).stdout || '';
|
|
101
112
|
return [
|
|
102
113
|
brewPkgConfigPath.trim(),
|
|
103
|
-
env.PKG_CONFIG_PATH,
|
|
114
|
+
process.env.PKG_CONFIG_PATH,
|
|
104
115
|
'/usr/local/lib/pkgconfig',
|
|
105
116
|
'/usr/lib/pkgconfig',
|
|
106
117
|
'/usr/local/libdata/pkgconfig',
|
|
@@ -111,8 +122,9 @@ const pkgConfigPath = function () {
|
|
|
111
122
|
}
|
|
112
123
|
};
|
|
113
124
|
|
|
114
|
-
const useGlobalLibvips =
|
|
115
|
-
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
|
125
|
+
const useGlobalLibvips = () => {
|
|
126
|
+
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
|
127
|
+
log('Detected SHARP_IGNORE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips');
|
|
116
128
|
return false;
|
|
117
129
|
}
|
|
118
130
|
/* istanbul ignore next */
|
|
@@ -127,14 +139,15 @@ const useGlobalLibvips = function () {
|
|
|
127
139
|
|
|
128
140
|
module.exports = {
|
|
129
141
|
minimumLibvipsVersion,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
prebuiltPlatforms,
|
|
143
|
+
buildPlatformArch,
|
|
144
|
+
buildSharpLibvipsIncludeDir,
|
|
145
|
+
buildSharpLibvipsCPlusPlusDir,
|
|
146
|
+
buildSharpLibvipsLibDir,
|
|
147
|
+
runtimePlatformArch,
|
|
133
148
|
log,
|
|
149
|
+
gypRebuild,
|
|
134
150
|
globalLibvipsVersion,
|
|
135
|
-
hasVendoredLibvips,
|
|
136
|
-
removeVendoredLibvips,
|
|
137
151
|
pkgConfigPath,
|
|
138
|
-
useGlobalLibvips
|
|
139
|
-
mkdirSync
|
|
152
|
+
useGlobalLibvips
|
|
140
153
|
};
|
package/lib/operation.js
CHANGED
|
@@ -19,7 +19,7 @@ const is = require('./is');
|
|
|
19
19
|
* If no angle is provided, it is determined from the EXIF data.
|
|
20
20
|
* Mirroring is supported and may infer the use of a flip operation.
|
|
21
21
|
*
|
|
22
|
-
* The use of `rotate`
|
|
22
|
+
* The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
|
23
23
|
*
|
|
24
24
|
* Only one rotation can occur per pipeline.
|
|
25
25
|
* Previous calls to `rotate` in the same pipeline will be ignored.
|
|
@@ -83,8 +83,6 @@ function rotate (angle, options) {
|
|
|
83
83
|
* Mirror the image vertically (up-down) about the x-axis.
|
|
84
84
|
* This always occurs before rotation, if any.
|
|
85
85
|
*
|
|
86
|
-
* The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
|
87
|
-
*
|
|
88
86
|
* This operation does not work correctly with multi-page images.
|
|
89
87
|
*
|
|
90
88
|
* @example
|
|
@@ -102,8 +100,6 @@ function flip (flip) {
|
|
|
102
100
|
* Mirror the image horizontally (left-right) about the y-axis.
|
|
103
101
|
* This always occurs before rotation, if any.
|
|
104
102
|
*
|
|
105
|
-
* The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
|
106
|
-
*
|
|
107
103
|
* @example
|
|
108
104
|
* const output = await sharp(input).flop().toBuffer();
|
|
109
105
|
*
|
package/lib/output.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const path = require('path');
|
|
6
|
+
const path = require('node:path');
|
|
7
7
|
const is = require('./is');
|
|
8
8
|
const sharp = require('./sharp');
|
|
9
9
|
|
|
@@ -162,8 +162,8 @@ function toBuffer (options, callback) {
|
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
|
165
|
-
* This will also convert to and add a web-friendly sRGB ICC profile
|
|
166
|
-
* output profile is provided.
|
|
165
|
+
* This will also convert to and add a web-friendly sRGB ICC profile if appropriate,
|
|
166
|
+
* unless a custom output profile is provided.
|
|
167
167
|
*
|
|
168
168
|
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
|
|
169
169
|
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
|
@@ -867,9 +867,6 @@ function tiff (options) {
|
|
|
867
867
|
/**
|
|
868
868
|
* Use these AVIF options for output image.
|
|
869
869
|
*
|
|
870
|
-
* Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
|
871
|
-
* most web browsers do not display these properly.
|
|
872
|
-
*
|
|
873
870
|
* AVIF image sequences are not supported.
|
|
874
871
|
*
|
|
875
872
|
* @example
|
|
@@ -909,9 +906,9 @@ function avif (options) {
|
|
|
909
906
|
*
|
|
910
907
|
* @since 0.23.0
|
|
911
908
|
*
|
|
912
|
-
* @param {Object}
|
|
909
|
+
* @param {Object} options - output options
|
|
910
|
+
* @param {string} options.compression - compression format: av1, hevc
|
|
913
911
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
|
914
|
-
* @param {string} [options.compression='av1'] - compression format: av1, hevc
|
|
915
912
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
916
913
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
|
917
914
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
@@ -920,6 +917,11 @@ function avif (options) {
|
|
|
920
917
|
*/
|
|
921
918
|
function heif (options) {
|
|
922
919
|
if (is.object(options)) {
|
|
920
|
+
if (is.string(options.compression) && is.inArray(options.compression, ['av1', 'hevc'])) {
|
|
921
|
+
this.options.heifCompression = options.compression;
|
|
922
|
+
} else {
|
|
923
|
+
throw is.invalidParameterError('compression', 'one of: av1, hevc', options.compression);
|
|
924
|
+
}
|
|
923
925
|
if (is.defined(options.quality)) {
|
|
924
926
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
|
925
927
|
this.options.heifQuality = options.quality;
|
|
@@ -934,13 +936,6 @@ function heif (options) {
|
|
|
934
936
|
throw is.invalidParameterError('lossless', 'boolean', options.lossless);
|
|
935
937
|
}
|
|
936
938
|
}
|
|
937
|
-
if (is.defined(options.compression)) {
|
|
938
|
-
if (is.string(options.compression) && is.inArray(options.compression, ['av1', 'hevc'])) {
|
|
939
|
-
this.options.heifCompression = options.compression;
|
|
940
|
-
} else {
|
|
941
|
-
throw is.invalidParameterError('compression', 'one of: av1, hevc', options.compression);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
939
|
if (is.defined(options.effort)) {
|
|
945
940
|
if (is.integer(options.effort) && is.inRange(options.effort, 0, 9)) {
|
|
946
941
|
this.options.heifEffort = options.effort;
|
|
@@ -955,6 +950,8 @@ function heif (options) {
|
|
|
955
950
|
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
|
956
951
|
}
|
|
957
952
|
}
|
|
953
|
+
} else {
|
|
954
|
+
throw is.invalidParameterError('options', 'Object', options);
|
|
958
955
|
}
|
|
959
956
|
return this._updateFormatOut('heif', options);
|
|
960
957
|
}
|
|
@@ -1046,6 +1043,7 @@ function jxl (options) {
|
|
|
1046
1043
|
*
|
|
1047
1044
|
* @param {Object} [options] - output options
|
|
1048
1045
|
* @param {string} [options.depth='uchar'] - bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex
|
|
1046
|
+
* @returns {Sharp}
|
|
1049
1047
|
* @throws {Error} Invalid options
|
|
1050
1048
|
*/
|
|
1051
1049
|
function raw (options) {
|
|
@@ -1369,7 +1367,7 @@ function _pipeline (callback) {
|
|
|
1369
1367
|
reject(err);
|
|
1370
1368
|
} else {
|
|
1371
1369
|
if (this.options.resolveWithObject) {
|
|
1372
|
-
resolve({ data
|
|
1370
|
+
resolve({ data, info });
|
|
1373
1371
|
} else {
|
|
1374
1372
|
resolve(data);
|
|
1375
1373
|
}
|
package/lib/resize.js
CHANGED
|
@@ -250,6 +250,9 @@ function resize (widthOrOptions, height, options) {
|
|
|
250
250
|
if (isResizeExpected(this.options)) {
|
|
251
251
|
this.options.debuglog('ignoring previous resize options');
|
|
252
252
|
}
|
|
253
|
+
if (this.options.widthPost !== -1) {
|
|
254
|
+
this.options.debuglog('operation order will be: extract, resize, extract');
|
|
255
|
+
}
|
|
253
256
|
if (is.defined(widthOrOptions)) {
|
|
254
257
|
if (is.object(widthOrOptions) && !is.defined(options)) {
|
|
255
258
|
options = widthOrOptions;
|
|
@@ -437,7 +440,7 @@ function extend (extend) {
|
|
|
437
440
|
*
|
|
438
441
|
* - Use `extract` before `resize` for pre-resize extraction.
|
|
439
442
|
* - Use `extract` after `resize` for post-resize extraction.
|
|
440
|
-
* - Use `extract`
|
|
443
|
+
* - Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order.
|
|
441
444
|
*
|
|
442
445
|
* @example
|
|
443
446
|
* sharp(input)
|