Compare commits

...

38 Commits

Author SHA1 Message Date
Lovell Fuller
4919bc5134 Release v0.33.1 2023-12-17 20:10:30 +00:00
Lovell Fuller
a4e64eb01f Prerelease v0.33.1-rc.3 2023-12-17 19:32:36 +00:00
Lovell Fuller
328b18df88 CI: Split yarn pnp package tests into separate jobs 2023-12-17 19:00:14 +00:00
Lovell Fuller
5e7bf32e5e Docs: refresh index and homepage link 2023-12-17 18:51:49 +00:00
Lovell Fuller
04403f4e5f Prerelease v0.33.1-rc.2 2023-12-17 17:13:34 +00:00
Lovell Fuller
420e0822b4 CI: Pin Node.js 18 to avoid npm 10 on 32-bit Windows
npm 10 seems to be opening thousands of network connections,
leading to resource starvation in Node.js 18. This does not
appear to impact Node.js 20.
2023-12-17 16:53:12 +00:00
Lovell Fuller
f7a3ea6415 Prerelease v0.33.1-rc.1 2023-12-17 10:35:27 +00:00
Lovell Fuller
f28e79ef4f Improve resilience of installation check 2023-12-17 09:46:28 +00:00
Lovell Fuller
5cd787bf85 CI: Upgrade to latest FreeBSD, improve test resilience 2023-12-17 09:39:05 +00:00
Lovell Fuller
021d637fd6 Docs: changelog and credit for #3897 2023-12-15 19:08:14 +00:00
Tamás András Horváth
2e14096af7 Ensure VIPS_NOVECTOR env var is respected (#3897) 2023-12-15 18:51:32 +00:00
Lovell Fuller
fe2b298a2f Emit warning for invalid ICC profile #3895 2023-12-15 12:13:57 +00:00
Lovell Fuller
c9e3996007 Tests: attempt to reduce chance of race condition 2023-12-13 13:22:59 +00:00
Lovell Fuller
3a0c375692 Docs: improve cross-platform help messaging
tldr; don't use npm for multi-platform installs
2023-12-13 12:59:14 +00:00
Lovell Fuller
c5eaeb2ddb Add help when possibly using an unsupported libc 2023-12-12 21:01:09 +00:00
Lovell Fuller
19fa4cd1d3 Docs: update liborc references to highway 2023-12-12 12:01:41 +00:00
Lovell Fuller
0adf7ef16f CI: Ensure Yarn pnp linker uses ESM 2023-12-12 12:01:11 +00:00
Lovell Fuller
8f7fb96a44 Prerelease v0.33.1-rc.0 2023-12-12 09:12:57 +00:00
Lovell Fuller
9e3b021b1a Add help text for Node.js snap failures
The official Node.js Snap as distributed via the Ubuntu Snap Store
does not provide support for native modules.

Sometimes, if the version of the core matches the version of the
underlying OS, then it will appear to work.

There are quite a few open issues relating to this in the
nodejs/snap repo.
2023-12-11 22:56:51 +00:00
Lovell Fuller
25164d4cef Tests: tighten yarn locator test for multi-platform 2023-12-11 21:51:20 +00:00
Lovell Fuller
516b1ec332 Improve help text displayed on failure of require 2023-12-11 21:28:09 +00:00
Lovell Fuller
95ba045a69 Tests: improve yarn locator coverage 2023-12-11 21:14:40 +00:00
Lovell Fuller
6e02f9288e CI: Add package test for Yarn Plug'n'Play 2023-12-10 20:02:17 +00:00
Lovell Fuller
a584ae093e Allow yarn locator hash calc to fail e.g. Windows 2023-12-10 19:51:21 +00:00
Lovell Fuller
1592f96b7b Add support for Yarn Plug'n'Play filesystem layout #3888 2023-12-10 19:38:03 +00:00
Lovell Fuller
004fff975f Docs: clarify yarn v1 vs yarn v3+ installation #3871 2023-12-04 08:46:48 +00:00
Lovell Fuller
4d049ee8f5 Docs: make use of optional dependencies even clearer 2023-12-02 09:20:42 +00:00
Lovell Fuller
c80e92fa16 Docs: highlight that optional deps must be allowed 2023-11-30 12:11:07 +00:00
Lovell Fuller
545e09fad2 Release v0.33.0 2023-11-29 11:55:31 +00:00
Lovell Fuller
133dc56ff4 Docs: note lack of native text rendering with Wasm 2023-11-28 09:08:52 +00:00
Lovell Fuller
9c877d93fa Docs: info about how animated images are loaded 2023-11-27 20:35:53 +00:00
Lovell Fuller
7ad86fed03 Docs: package-manager howto for cross-platform install 2023-11-27 09:30:21 +00:00
Lovell Fuller
31cf07f0ba Docs: update perf results for next release
Switch from orc to highway is ~25% faster
2023-11-26 14:41:44 +00:00
Lovell Fuller
4ffb48711a Tests: update benchmark deps/env to latest 2023-11-24 13:22:11 +00:00
Lovell Fuller
3da96a86e6 Docs: clarify that Wasm requires Node.js compatible runtime 2023-11-24 12:00:14 +00:00
Lovell Fuller
45ed9ea9bf Tests: update leak config/suppressions 2023-11-24 11:59:29 +00:00
Lovell Fuller
61057f25bc Prerelease v0.33.0-rc.2 2023-11-22 12:17:25 +00:00
Lovell Fuller
68ef72cb61 CI: allow failure when attempting to rm native binary 2023-11-22 12:00:10 +00:00
40 changed files with 484 additions and 212 deletions

View File

@@ -1,5 +1,5 @@
freebsd_instance: freebsd_instance:
image_family: freebsd-13-2 image_family: freebsd-14-0-snap
task: task:
name: FreeBSD name: FreeBSD
@@ -10,7 +10,8 @@ task:
- pkg update -f - pkg update -f
- pkg upgrade -y - pkg upgrade -y
- pkg install -y devel/git devel/pkgconf graphics/vips www/node20 www/npm - pkg install -y devel/git devel/pkgconf graphics/vips www/node20 www/npm
- pkg-config --modversion vips-cpp
install_script: install_script:
- npm install --build-from-source - npm install --build-from-source
test_script: test_script:
- npm test - npx mocha --no-config --spec=test/unit/io.js --timeout=30000

View File

@@ -11,7 +11,10 @@ labels: installation
<!-- Please place an [x] in the box to confirm. --> <!-- Please place an [x] in the box to confirm. -->
- [ ] I have read the [documentation relating to installation](https://sharp.pixelplumbing.com/install). - [ ] I have read and understood all of the [documentation relating to installation](https://sharp.pixelplumbing.com/install).
- [ ] I have searched for known bugs relating to this problem in my choice of package manager.
You must confirm both of these before continuing.
### Are you using the latest version of sharp? ### Are you using the latest version of sharp?
@@ -27,21 +30,28 @@ If you are using another package which depends on a version of `sharp` that is n
<!-- Please place an [x] in the relevant box to confirm. --> <!-- Please place an [x] in the relevant box to confirm. -->
- [ ] I am using Node.js 18 with a version >= 18.17.0 - [ ] I am using Node.js with a version that satisfies `^18.17.0 || ^20.3.0 || >=21.0.0`
- [ ] I am using Node.js 20 with a version >= 20.3.0 - [ ] I am using Deno
- [ ] I am using Node.js 21 or later - [ ] I am using Bun
If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue. If you cannot confirm any of these,
please upgrade to the latest version
and try again before opening an issue.
### Are you using a supported package manager? ### Are you using a supported package manager and installing optional dependencies?
<!-- Please place an [x] in the relevant box to confirm. --> <!-- Please place an [x] in the relevant box to confirm. -->
- [ ] I am using npm >= 9.6.5 - [ ] I am using npm >= 9.6.5 with `--include=optional`
- [ ] I am using yarn >= 3.2.0 - [ ] I am using yarn >= 3.2.0 and I am not using the "Plug'n'Play" linker
- [ ] I am using pnpm >= 7.1.0 - [ ] I am using pnpm >= 7.1.0 with `--no-optional=false`
- [ ] I am using Deno
- [ ] I am using Bun
If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue. If you cannot confirm any of these,
please upgrade to the latest version of your chosen package manager
and ensure you are allowing the installation of optional or multi-platform dependencies
before opening an issue.
### What is the complete output of running `npm install --verbose --foreground-scripts sharp` in an empty directory? ### What is the complete output of running `npm install --verbose --foreground-scripts sharp` in an empty directory?

View File

@@ -47,7 +47,7 @@ jobs:
platform: darwin-x64 platform: darwin-x64
- os: windows-2019 - os: windows-2019
nodejs_arch: x86 nodejs_arch: x86
nodejs_version: "^18.17.0" nodejs_version: "18.18.2" # pinned to avoid 18.19.0 and npm 10
nodejs_version_major: 18 nodejs_version_major: 18
platform: win32-ia32 platform: win32-ia32
prebuild: true prebuild: true
@@ -185,7 +185,7 @@ jobs:
emmake npm run package-from-local-build emmake npm run package-from-local-build
npm pkg set "optionalDependencies.@img/sharp-wasm32=file:./npm/wasm32" npm pkg set "optionalDependencies.@img/sharp-wasm32=file:./npm/wasm32"
npm run clean npm run clean
rm -r node_modules/@img/sharp-linux-x64 rm -rf node_modules/@img/sharp-linux-x64
npm install --cpu=wasm32 npm install --cpu=wasm32
npm test npm test
- name: Prebuild - name: Prebuild

View File

@@ -27,6 +27,10 @@ jobs:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
runtime: node runtime: node
package-manager: yarn package-manager: yarn
- name: linux-x64-node-yarn-pnp
runs-on: ubuntu-22.04
runtime: node
package-manager: yarn-pnp
- name: linux-x64-deno - name: linux-x64-deno
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
runtime: deno runtime: deno
@@ -46,6 +50,10 @@ jobs:
runs-on: macos-11 runs-on: macos-11
runtime: node runtime: node
package-manager: yarn package-manager: yarn
- name: darwin-x64-node-yarn-pnp
runs-on: macos-11
runtime: node
package-manager: yarn-pnp
- name: darwin-x64-deno - name: darwin-x64-deno
runs-on: macos-11 runs-on: macos-11
runtime: deno runtime: deno
@@ -65,6 +73,10 @@ jobs:
runs-on: windows-2019 runs-on: windows-2019
runtime: node runtime: node
package-manager: yarn package-manager: yarn
- name: win32-x64-node-yarn-pnp
runs-on: windows-2019
runtime: node
package-manager: yarn-pnp
- name: win32-x64-deno - name: win32-x64-deno
runs-on: windows-2019 runs-on: windows-2019
runtime: deno runtime: deno
@@ -105,7 +117,8 @@ jobs:
{ {
"dependencies": { "dependencies": {
"sharp": "${{ steps.version.outputs.semver }}" "sharp": "${{ steps.version.outputs.semver }}"
} },
"type": "module"
} }
- name: Create release.mjs - name: Create release.mjs
uses: DamianReeves/write-file-action@v1.2 uses: DamianReeves/write-file-action@v1.2
@@ -117,19 +130,19 @@ jobs:
deepStrictEqual(['.jpg', '.jpeg', '.jpe'], sharp.format.jpeg.input.fileSuffix); deepStrictEqual(['.jpg', '.jpeg', '.jpe'], sharp.format.jpeg.input.fileSuffix);
- name: Run with Node.js + npm - name: Run with Node.js + npm
if: ${{ matrix.runtime == 'node' && matrix.package-manager == 'npm' }} if: ${{ matrix.package-manager == 'npm' }}
run: | run: |
npm install --ignore-scripts npm install --ignore-scripts
node release.mjs node release.mjs
- name: Run with Node.js + pnpm - name: Run with Node.js + pnpm
if: ${{ matrix.runtime == 'node' && matrix.package-manager == 'pnpm' }} if: ${{ matrix.package-manager == 'pnpm' }}
run: | run: |
pnpm install --ignore-scripts pnpm install --ignore-scripts
node release.mjs node release.mjs
- name: Run with Node.js + yarn - name: Run with Node.js + yarn
if: ${{ matrix.runtime == 'node' && matrix.package-manager == 'yarn' }} if: ${{ matrix.package-manager == 'yarn' }}
run: | run: |
corepack enable corepack enable
yarn set version stable yarn set version stable
@@ -139,6 +152,17 @@ jobs:
yarn install yarn install
node release.mjs node release.mjs
- name: Run with Node.js + yarn pnp
if: ${{ matrix.package-manager == 'yarn-pnp' }}
run: |
corepack enable
yarn set version stable
yarn config set enableImmutableInstalls false
yarn config set enableScripts false
yarn config set nodeLinker pnp
yarn install
yarn node release.mjs
- name: Run with Deno - name: Run with Deno
if: ${{ matrix.runtime == 'deno' }} if: ${{ matrix.runtime == 'deno' }}
run: deno run --allow-read --allow-ffi release.mjs run: deno run --allow-read --allow-ffi release.mjs

View File

@@ -17,6 +17,10 @@ Non-critical problems encountered during processing are emitted as `warning` eve
Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class. Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
When loading more than one page/frame of an animated image,
these are combined as a vertically-stacked "toilet roll" image
where the overall height is the `pageHeight` multiplied by the number of `pages`.
**Throws**: **Throws**:
- <code>Error</code> Invalid parameters - <code>Error</code> Invalid parameters

View File

@@ -151,7 +151,7 @@ const counters = sharp.counters(); // { queue: 2, process: 4 }
> simd([simd]) ⇒ <code>boolean</code> > simd([simd]) ⇒ <code>boolean</code>
Get and set use of SIMD vector unit instructions. Get and set use of SIMD vector unit instructions.
Requires libvips to have been compiled with liborc support. Requires libvips to have been compiled with highway support.
Improves the performance of `resize`, `blur` and `sharpen` operations Improves the performance of `resize`, `blur` and `sharpen` operations
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON. by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
@@ -165,12 +165,12 @@ by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM N
**Example** **Example**
```js ```js
const simd = sharp.simd(); const simd = sharp.simd();
// simd is `true` if the runtime use of liborc is currently enabled // simd is `true` if the runtime use of highway is currently enabled
``` ```
**Example** **Example**
```js ```js
const simd = sharp.simd(false); const simd = sharp.simd(false);
// prevent libvips from using liborc at runtime // prevent libvips from using highway at runtime
``` ```

View File

@@ -4,7 +4,19 @@
Requires libvips v8.15.0 Requires libvips v8.15.0
### v0.33.0 - TBD ### v0.33.1 - 17th December 2023
* Add support for Yarn Plug'n'Play filesystem layout.
[#3888](https://github.com/lovell/sharp/issues/3888)
* Emit warning when attempting to use invalid ICC profiles.
[#3895](https://github.com/lovell/sharp/issues/3895)
* Ensure `VIPS_NOVECTOR` environment variable is respected.
[#3897](https://github.com/lovell/sharp/pull/3897)
[@icetee](https://github.com/icetee)
### v0.33.0 - 29th November 2023
* Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0 * Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0

View File

@@ -281,3 +281,6 @@ GitHub: https://github.com/dnsbty
Name: Ingvar Stepanyan Name: Ingvar Stepanyan
GitHub: https://github.com/RReverser GitHub: https://github.com/RReverser
Name: Tamás András Horváth
GitHub: https://github.com/icetee

View File

@@ -2,6 +2,12 @@
Works with your choice of JavaScript package manager. Works with your choice of JavaScript package manager.
> ⚠️ **Please ensure your package manager is configured to install optional dependencies**
If a package manager lockfile must support multiple platforms,
please see the [cross-platform](#cross-platform) section
to help decide which package manager is appropriate.
```sh ```sh
npm install sharp npm install sharp
``` ```
@@ -11,7 +17,12 @@ pnpm add sharp
``` ```
```sh ```sh
yarn add sharp # v3 recommended, Plug'n'Play unsupported yarn add sharp
```
```sh
# yarn v1 (maintenance mode)
yarn add sharp --ignore-engines
``` ```
```sh ```sh
@@ -42,6 +53,40 @@ Ready-compiled sharp and libvips binaries are provided for use on the most commo
This provides support for the This provides support for the
JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats. JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats.
## Cross-platform
At install time, package managers will automatically select prebuilt binaries
for the current OS platform and CPU architecture, where available.
Some package managers support multiple platforms and architectures
within the same installation tree and/or using the same lockfile.
### npm
> ⚠️ **npm `package-lock.json` files can cause installation problems due to [npm bug #4828](https://github.com/npm/cli/issues/4828)**
Provides limited support via `--os`, `--cpu` and `--libc` flags.
Example to support both Intel and ARM CPUs on macOS:
```sh
npm install --cpu=x64 --os=darwin sharp
npm install --cpu=arm64 --os=darwin sharp
```
Example to support both glibc and musl-based Linux:
```sh
npm install --cpu=x64 --os=linux sharp
npm install --cpu=x64 --os=linux --libc=musl sharp
```
### yarn
Use the [supportedArchitectures](https://yarnpkg.com/configuration/yarnrc#supportedArchitectures) configuration.
### pnpm
Use the [supportedArchitectures](https://pnpm.io/package_json#pnpmsupportedarchitectures) configuration.
## Custom libvips ## Custom libvips
To use a custom, globally-installed version of libvips instead of the provided binaries, To use a custom, globally-installed version of libvips instead of the provided binaries,
@@ -83,6 +128,10 @@ can be used to configure the target environment.
Experimental support is provided for runtime environments that provide Experimental support is provided for runtime environments that provide
multi-threaded Wasm via Workers. multi-threaded Wasm via Workers.
Use in web browsers is unsupported.
Native text rendering is unsupported.
```sh ```sh
npm install --cpu=wasm32 sharp npm install --cpu=wasm32 sharp
``` ```

View File

@@ -9,26 +9,26 @@ The I/O limits of the relevant (de)compression library will generally determine
## Contenders ## Contenders
* [jimp](https://www.npmjs.com/package/jimp) v0.22.7 - Image processing in pure JavaScript. * [jimp](https://www.npmjs.com/package/jimp) v0.22.10 - Image processing in pure JavaScript.
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*". * [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
* [gm](https://www.npmjs.com/package/gm) v1.25.0 - Fully featured wrapper around GraphicsMagick's `gm` command line utility. * [gm](https://www.npmjs.com/package/gm) v1.25.0 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
* [@squoosh/lib](https://www.npmjs.com/package/@squoosh/lib) v0.4.0 - Image libraries transpiled to WebAssembly, includes GPLv3 code, but "*Project no longer maintained*". * [@squoosh/lib](https://www.npmjs.com/package/@squoosh/lib) v0.5.3 - Image libraries transpiled to WebAssembly, includes GPLv3 code, but "*Project no longer maintained*".
* [@squoosh/cli](https://www.npmjs.com/package/@squoosh/cli) v0.7.3 - Command line wrapper around `@squoosh/lib`, avoids GPLv3 by spawning process, but "*Project no longer maintained*". * [@squoosh/cli](https://www.npmjs.com/package/@squoosh/cli) v0.7.3 - Command line wrapper around `@squoosh/lib`, avoids GPLv3 by spawning process, but "*Project no longer maintained*".
* sharp v0.32.0 / libvips v8.14.2 - Caching within libvips disabled to ensure a fair comparison. * sharp v0.33.0 / libvips v8.15.0 - Caching within libvips disabled to ensure a fair comparison.
## Environment ## Environment
### AMD64 ### AMD64
* AWS EC2 us-east-2 [c6a.xlarge](https://aws.amazon.com/ec2/instance-types/c6a/) (4x AMD EPYC 7R13) * AWS EC2 us-east-2 [c7a.xlarge](https://aws.amazon.com/ec2/instance-types/c7a/) (4x AMD EPYC 9R14)
* Ubuntu 22.04 20230303 (ami-0122295b0eb922138) * Ubuntu 23.10 [13f233a16be2](https://hub.docker.com/layers/library/ubuntu/23.10/images/sha256-13f233a16be210b57907b98b0d927ceff7571df390701e14fe1f3901b2c4a4d7)
* Node.js 16.19.1 * Node.js 20.10.0
### ARM64 ### ARM64
* AWS EC2 us-east-2 [c7g.xlarge](https://aws.amazon.com/ec2/instance-types/c7g/) (4x ARM Graviton3) * AWS EC2 us-east-2 [c7g.xlarge](https://aws.amazon.com/ec2/instance-types/c7g/) (4x ARM Graviton3)
* Ubuntu 22.04 20230303 (ami-0af198159897e7a29) * Ubuntu 23.10 [7708743264cb](https://hub.docker.com/layers/library/ubuntu/23.10/images/sha256-7708743264cbb7f6cf7fc13e915faece45a6cdda455748bc55e58e8de3d27b63)
* Node.js 16.19.1 * Node.js 20.10.0
## Task: JPEG ## Task: JPEG
@@ -43,28 +43,28 @@ Note: jimp does not support Lanczos 3, bicubic resampling used instead.
| Module | Input | Output | Ops/sec | Speed-up | | Module | Input | Output | Ops/sec | Speed-up |
| :----------------- | :----- | :----- | ------: | -------: | | :----------------- | :----- | :----- | ------: | -------: |
| jimp | buffer | buffer | 0.84 | 1.0 | | jimp | buffer | buffer | 0.84 | 1.0 |
| squoosh-cli | file | file | 1.07 | 1.3 | | squoosh-cli | file | file | 1.54 | 1.8 |
| squoosh-lib | buffer | buffer | 1.82 | 2.2 | | squoosh-lib | buffer | buffer | 2.24 | 2.7 |
| gm | buffer | buffer | 8.41 | 10.0 | | imagemagick | file | file | 11.75 | 14.0 |
| gm | file | file | 8.45 | 10.0 | | gm | buffer | buffer | 12.66 | 15.1 |
| imagemagick | file | file | 8.77 | 10.4 | | gm | file | file | 12.72 | 15.1 |
| sharp | stream | stream | 36.36 | 43.3 | | sharp | stream | stream | 48.31 | 57.5 |
| sharp | file | file | 38.67 | 46.0 | | sharp | file | file | 51.42 | 61.2 |
| sharp | buffer | buffer | 39.44 | 47.0 | | sharp | buffer | buffer | 52.41 | 62.4 |
#### Results: JPEG (ARM64) #### Results: JPEG (ARM64)
| Module | Input | Output | Ops/sec | Speed-up | | Module | Input | Output | Ops/sec | Speed-up |
| :----------------- | :----- | :----- | ------: | -------: | | :----------------- | :----- | :----- | ------: | -------: |
| jimp | buffer | buffer | 1.02 | 1.0 | | jimp | buffer | buffer | 0.88 | 1.0 |
| squoosh-cli | file | file | 1.11 | 1.1 | | squoosh-cli | file | file | 1.18 | 1.3 |
| squoosh-lib | buffer | buffer | 2.08 | 2.0 | | squoosh-lib | buffer | buffer | 1.99 | 2.3 |
| gm | buffer | buffer | 8.80 | 8.6 | | gm | buffer | buffer | 6.06 | 6.9 |
| gm | file | file | 10.05 | 9.9 | | gm | file | file | 10.81 | 12.3 |
| imagemagick | file | file | 10.28 | 10.1 | | imagemagick | file | file | 10.95 | 12.4 |
| sharp | stream | stream | 26.87 | 26.3 | | sharp | stream | stream | 33.15 | 37.7 |
| sharp | file | file | 27.88 | 27.3 | | sharp | file | file | 34.99 | 39.8 |
| sharp | buffer | buffer | 28.40 | 27.8 | | sharp | buffer | buffer | 36.05 | 41.0 |
## Task: PNG ## Task: PNG
@@ -80,25 +80,25 @@ Note: jimp does not support premultiply/unpremultiply.
| Module | Input | Output | Ops/sec | Speed-up | | Module | Input | Output | Ops/sec | Speed-up |
| :----------------- | :----- | :----- | ------: | -------: | | :----------------- | :----- | :----- | ------: | -------: |
| squoosh-cli | file | file | 0.40 | 1.0 | | squoosh-cli | file | file | 0.34 | 1.0 |
| squoosh-lib | buffer | buffer | 0.47 | 1.2 | | squoosh-lib | buffer | buffer | 0.51 | 1.5 |
| gm | file | file | 6.47 | 16.2 | | jimp | buffer | buffer | 3.59 | 10.6 |
| jimp | buffer | buffer | 6.60 | 16.5 | | gm | file | file | 8.54 | 25.1 |
| imagemagick | file | file | 7.08 | 17.7 | | imagemagick | file | file | 9.23 | 27.1 |
| sharp | file | file | 17.80 | 44.5 | | sharp | file | file | 25.43 | 74.8 |
| sharp | buffer | buffer | 18.02 | 45.0 | | sharp | buffer | buffer | 25.70 | 75.6 |
### Results: PNG (ARM64) ### Results: PNG (ARM64)
| Module | Input | Output | Ops/sec | Speed-up | | Module | Input | Output | Ops/sec | Speed-up |
| :----------------- | :----- | :----- | ------: | -------: | | :----------------- | :----- | :----- | ------: | -------: |
| squoosh-cli | file | file | 0.40 | 1.0 | | squoosh-cli | file | file | 0.33 | 1.0 |
| squoosh-lib | buffer | buffer | 0.48 | 1.2 | | squoosh-lib | buffer | buffer | 0.46 | 1.4 |
| gm | file | file | 7.20 | 18.0 | | jimp | buffer | buffer | 3.51 | 10.6 |
| jimp | buffer | buffer | 7.62 | 19.1 | | gm | file | file | 7.47 | 22.6 |
| imagemagick | file | file | 7.96 | 19.9 | | imagemagick | file | file | 8.06 | 24.4 |
| sharp | file | file | 12.97 | 32.4 | | sharp | file | file | 17.31 | 52.5 |
| sharp | buffer | buffer | 13.12 | 32.8 | | sharp | buffer | buffer | 17.66 | 53.5 |
## Running the benchmark test ## Running the benchmark test

File diff suppressed because one or more lines are too long

View File

@@ -3,34 +3,39 @@
'use strict'; 'use strict';
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips'); try {
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
const buildFromSource = (msg) => { const buildFromSource = (msg) => {
log(msg); log(msg);
log('Attempting to build from source via node-gyp'); log('Attempting to build from source via node-gyp');
try { try {
require('node-addon-api'); require('node-addon-api');
log('Found node-addon-api'); log('Found node-addon-api');
} catch (err) { } catch (err) {
log('Please add node-addon-api to your dependencies'); log('Please add node-addon-api to your dependencies');
return; return;
} }
try { try {
const gyp = require('node-gyp'); const gyp = require('node-gyp');
log(`Found node-gyp version ${gyp().version}`); log(`Found node-gyp version ${gyp().version}`);
} catch (err) { } catch (err) {
log('Please add node-gyp to your dependencies'); log('Please add node-gyp to your dependencies');
return; return;
} }
log('See https://sharp.pixelplumbing.com/install#building-from-source'); log('See https://sharp.pixelplumbing.com/install#building-from-source');
const status = spawnRebuild(); const status = spawnRebuild();
if (status !== 0) { if (status !== 0) {
process.exit(status); process.exit(status);
} }
}; };
if (useGlobalLibvips()) { if (useGlobalLibvips()) {
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`); buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
} else if (process.env.npm_config_build_from_source) { } else if (process.env.npm_config_build_from_source) {
buildFromSource('Detected --build-from-source flag'); buildFromSource('Detected --build-from-source flag');
}
} catch (err) {
const summary = err.message.split(/\n/).slice(0, 1);
console.log(`sharp: skipping install check: ${summary}`);
} }

View File

@@ -22,6 +22,10 @@ const debuglog = util.debuglog('sharp');
* *
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class. * Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
* *
* When loading more than one page/frame of an animated image,
* these are combined as a vertically-stacked "toilet roll" image
* where the overall height is the `pageHeight` multiplied by the number of `pages`.
*
* @constructs Sharp * @constructs Sharp
* *
* @emits Sharp#info * @emits Sharp#info

2
lib/index.d.ts vendored
View File

@@ -126,7 +126,7 @@ declare namespace sharp {
function counters(): SharpCounters; function counters(): SharpCounters;
/** /**
* Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support. * Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with highway support.
* Improves the performance of resize, blur and sharpen operations by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON. * Improves the performance of resize, blur and sharpen operations by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
* @param enable enable or disable use of SIMD vector unit instructions * @param enable enable or disable use of SIMD vector unit instructions
* @returns true if usage of SIMD vector unit instructions is enabled * @returns true if usage of SIMD vector unit instructions is enabled

View File

@@ -4,11 +4,12 @@
'use strict'; 'use strict';
const { spawnSync } = require('node:child_process'); const { spawnSync } = require('node:child_process');
const { createHash } = require('node:crypto');
const semverCoerce = require('semver/functions/coerce'); const semverCoerce = require('semver/functions/coerce');
const semverGreaterThanOrEqualTo = require('semver/functions/gte'); const semverGreaterThanOrEqualTo = require('semver/functions/gte');
const detectLibc = require('detect-libc'); const detectLibc = require('detect-libc');
const { engines } = require('../package.json'); const { engines, optionalDependencies } = require('../package.json');
const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || /* istanbul ignore next */ const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || /* istanbul ignore next */
engines.libvips; engines.libvips;
@@ -97,6 +98,17 @@ const isRosetta = () => {
return false; return false;
}; };
const sha512 = (s) => createHash('sha512').update(s).digest('hex');
const yarnLocator = () => {
try {
const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`]).version;
return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
} catch {}
return '';
};
/* istanbul ignore next */ /* istanbul ignore next */
const spawnRebuild = () => const spawnRebuild = () =>
spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, { spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, {
@@ -164,6 +176,7 @@ module.exports = {
buildSharpLibvipsLibDir, buildSharpLibvipsLibDir,
runtimePlatformArch, runtimePlatformArch,
log, log,
yarnLocator,
spawnRebuild, spawnRebuild,
globalLibvipsVersion, globalLibvipsVersion,
pkgConfigPath, pkgConfigPath,

View File

@@ -46,41 +46,63 @@ if (sharp) {
// Common error messages // Common error messages
if (prebuiltPlatforms.includes(runtimePlatform)) { if (prebuiltPlatforms.includes(runtimePlatform)) {
const [os, cpu] = runtimePlatform.split('-'); const [os, cpu] = runtimePlatform.split('-');
help.push('- Add platform-specific dependencies:'); help.push(
help.push(` npm install --os=${os} --cpu=${cpu} sharp`); '- Ensure optional dependencies can be installed:',
help.push(' or'); ' npm install --include=optional sharp',
help.push(` npm install --force @img/sharp-${runtimePlatform}`); ' yarn add sharp --ignore-engines',
'- Ensure your package manager supports multi-platform installation:',
' See https://sharp.pixelplumbing.com/install#cross-platform',
'- Add platform-specific dependencies:',
` npm install --os=${os} --cpu=${cpu} sharp`,
` npm install --force @img/sharp-${runtimePlatform}`
);
} else { } else {
help.push(`- Manually install libvips >= ${minimumLibvipsVersion}`); help.push(
help.push('- Add experimental WebAssembly-based dependencies:'); `- Manually install libvips >= ${minimumLibvipsVersion}`,
help.push(' npm install --cpu=wasm32 sharp'); '- Add experimental WebAssembly-based dependencies:',
' npm install --cpu=wasm32 sharp',
' npm install --force @img/sharp-wasm32'
);
} }
if (isLinux && /symbol not found/i.test(messages)) { if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
try { try {
const { engines } = require(`@img/sharp-libvips-${runtimePlatform}/package`); const { engines } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
const libcFound = `${familySync()} ${versionSync()}`; const libcFound = `${familySync()} ${versionSync()}`;
const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`; const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`;
help.push('- Update your OS:'); help.push(
help.push(` Found ${libcFound}`); '- Update your OS:',
help.push(` Requires ${libcRequires}`); ` Found ${libcFound}`,
` Requires ${libcRequires}`
);
} catch (errEngines) {} } catch (errEngines) {}
} }
if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
help.push(
'- Remove the Node.js Snap, which does not support native modules',
' snap remove node'
);
}
if (isMacOs && /Incompatible library version/.test(messages)) { if (isMacOs && /Incompatible library version/.test(messages)) {
help.push('- Update Homebrew:'); help.push(
help.push(' brew update && brew upgrade vips'); '- Update Homebrew:',
' brew update && brew upgrade vips'
);
} }
if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) { if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
help.push('- Run Node.js without using the --no-addons flag'); help.push('- Run Node.js without using the --no-addons flag');
} }
if (process.versions.pnp) {
help.push('- Use a supported yarn linker, either pnpm or node-modules:');
help.push(' yarn config set nodeLinker node-modules');
}
// Link to installation docs // Link to installation docs
if (isWindows && /The specified procedure could not be found/.test(messages)) { if (isWindows && /The specified procedure could not be found/.test(messages)) {
help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows'); help.push(
} else { '- Using the canvas package on Windows?',
help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install'); ' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
'- Check for outdated versions of sharp in the dependency tree:',
' npm ls sharp'
);
} }
help.push(
'- Consult the installation documentation:',
' See https://sharp.pixelplumbing.com/install'
);
throw new Error(help.join('\n')); throw new Error(help.join('\n'));
} }

View File

@@ -183,17 +183,17 @@ function counters () {
/** /**
* Get and set use of SIMD vector unit instructions. * Get and set use of SIMD vector unit instructions.
* Requires libvips to have been compiled with liborc support. * Requires libvips to have been compiled with highway support.
* *
* Improves the performance of `resize`, `blur` and `sharpen` operations * Improves the performance of `resize`, `blur` and `sharpen` operations
* by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON. * by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
* *
* @example * @example
* const simd = sharp.simd(); * const simd = sharp.simd();
* // simd is `true` if the runtime use of liborc is currently enabled * // simd is `true` if the runtime use of highway is currently enabled
* @example * @example
* const simd = sharp.simd(false); * const simd = sharp.simd(false);
* // prevent libvips from using liborc at runtime * // prevent libvips from using highway at runtime
* *
* @param {boolean} [simd=true] * @param {boolean} [simd=true]
* @returns {boolean} * @returns {boolean}
@@ -201,7 +201,6 @@ function counters () {
function simd (simd) { function simd (simd) {
return sharp.simd(is.bool(simd) ? simd : null); return sharp.simd(is.bool(simd) ? simd : null);
} }
simd(true);
/** /**
* Block libvips operations at runtime. * Block libvips operations at runtime.

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-darwin-arm64", "name": "@img/sharp-darwin-arm64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with macOS 64-bit ARM", "description": "Prebuilt sharp for use with macOS 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-darwin-x64", "name": "@img/sharp-darwin-x64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with macOS x64", "description": "Prebuilt sharp for use with macOS x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-arm", "name": "@img/sharp-linux-arm",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)", "description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-arm64", "name": "@img/sharp-linux-arm64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM", "description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-s390x", "name": "@img/sharp-linux-s390x",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Linux (glibc) s390x", "description": "Prebuilt sharp for use with Linux (glibc) s390x",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-x64", "name": "@img/sharp-linux-x64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Linux (glibc) x64", "description": "Prebuilt sharp for use with Linux (glibc) x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linuxmusl-arm64", "name": "@img/sharp-linuxmusl-arm64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM", "description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linuxmusl-x64", "name": "@img/sharp-linuxmusl-x64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Linux (musl) x64", "description": "Prebuilt sharp for use with Linux (musl) x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp", "name": "@img/sharp",
"version": "0.33.0-rc.1", "version": "0.33.1",
"private": "true", "private": "true",
"workspaces": [ "workspaces": [
"darwin-arm64", "darwin-arm64",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-wasm32", "name": "@img/sharp-wasm32",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with wasm32", "description": "Prebuilt sharp for use with wasm32",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-win32-ia32", "name": "@img/sharp-win32-ia32",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Windows x86 (32-bit)", "description": "Prebuilt sharp for use with Windows x86 (32-bit)",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-win32-x64", "name": "@img/sharp-win32-x64",
"version": "0.33.0-rc.1", "version": "0.33.1",
"description": "Prebuilt sharp for use with Windows x64", "description": "Prebuilt sharp for use with Windows x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,9 +1,9 @@
{ {
"name": "sharp", "name": "sharp",
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images", "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
"version": "0.33.0-rc.1", "version": "0.33.1",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://github.com/lovell/sharp", "homepage": "https://sharp.pixelplumbing.com",
"contributors": [ "contributors": [
"Pierre Inglebert <pierre.inglebert@gmail.com>", "Pierre Inglebert <pierre.inglebert@gmail.com>",
"Jonathan Ong <jonathanrichardong@gmail.com>", "Jonathan Ong <jonathanrichardong@gmail.com>",
@@ -141,8 +141,8 @@
"semver": "^7.5.4" "semver": "^7.5.4"
}, },
"optionalDependencies": { "optionalDependencies": {
"@img/sharp-darwin-arm64": "0.33.0-rc.1", "@img/sharp-darwin-arm64": "0.33.1",
"@img/sharp-darwin-x64": "0.33.0-rc.1", "@img/sharp-darwin-x64": "0.33.1",
"@img/sharp-libvips-darwin-arm64": "1.0.0", "@img/sharp-libvips-darwin-arm64": "1.0.0",
"@img/sharp-libvips-darwin-x64": "1.0.0", "@img/sharp-libvips-darwin-x64": "1.0.0",
"@img/sharp-libvips-linux-arm": "1.0.0", "@img/sharp-libvips-linux-arm": "1.0.0",
@@ -151,15 +151,15 @@
"@img/sharp-libvips-linux-x64": "1.0.0", "@img/sharp-libvips-linux-x64": "1.0.0",
"@img/sharp-libvips-linuxmusl-arm64": "1.0.0", "@img/sharp-libvips-linuxmusl-arm64": "1.0.0",
"@img/sharp-libvips-linuxmusl-x64": "1.0.0", "@img/sharp-libvips-linuxmusl-x64": "1.0.0",
"@img/sharp-linux-arm": "0.33.0-rc.1", "@img/sharp-linux-arm": "0.33.1",
"@img/sharp-linux-arm64": "0.33.0-rc.1", "@img/sharp-linux-arm64": "0.33.1",
"@img/sharp-linux-s390x": "0.33.0-rc.1", "@img/sharp-linux-s390x": "0.33.1",
"@img/sharp-linux-x64": "0.33.0-rc.1", "@img/sharp-linux-x64": "0.33.1",
"@img/sharp-linuxmusl-arm64": "0.33.0-rc.1", "@img/sharp-linuxmusl-arm64": "0.33.1",
"@img/sharp-linuxmusl-x64": "0.33.0-rc.1", "@img/sharp-linuxmusl-x64": "0.33.1",
"@img/sharp-wasm32": "0.33.0-rc.1", "@img/sharp-wasm32": "0.33.1",
"@img/sharp-win32-ia32": "0.33.0-rc.1", "@img/sharp-win32-ia32": "0.33.1",
"@img/sharp-win32-x64": "0.33.0-rc.1" "@img/sharp-win32-x64": "0.33.1"
}, },
"devDependencies": { "devDependencies": {
"@emnapi/runtime": "^0.44.0", "@emnapi/runtime": "^0.44.0",

View File

@@ -6,6 +6,7 @@
'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")', 'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")', 'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
'sharp_libvips_version': '<!(node -p "require(\'../package.json\').optionalDependencies[\'@img/sharp-libvips-<(platform_and_arch)\']")', 'sharp_libvips_version': '<!(node -p "require(\'../package.json\').optionalDependencies[\'@img/sharp-libvips-<(platform_and_arch)\']")',
'sharp_libvips_yarn_locator': '<!(node -p "require(\'../lib/libvips\').yarnLocator()")',
'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")', 'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")', 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")' 'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
@@ -157,7 +158,8 @@
'-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'', '-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath,\'@loader_path/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'', '-Wl,-rpath,\'@loader_path/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
'-Wl,-rpath,\'@loader_path/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'', '-Wl,-rpath,\'@loader_path/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath,\'@loader_path/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'' '-Wl,-rpath,\'@loader_path/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath,\'@loader_path/../../../../../@img-sharp-libvips-<(platform_and_arch)-npm-<(sharp_libvips_version)-<(sharp_libvips_yarn_locator)/node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''
] ]
} }
}], }],
@@ -176,7 +178,8 @@
'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'', '-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'', '-Wl,-rpath=\'$$ORIGIN/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'', '-Wl,-rpath=\'$$ORIGIN/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'' '-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath,\'$$ORIGIN/../../../../../@img-sharp-libvips-<(platform_and_arch)-npm-<(sharp_libvips_version)-<(sharp_libvips_yarn_locator)/node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''
] ]
} }
}], }],

View File

@@ -794,11 +794,15 @@ class PipelineWorker : public Napi::AsyncWorker {
// Apply output ICC profile // Apply output ICC profile
if (!baton->withIccProfile.empty()) { if (!baton->withIccProfile.empty()) {
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option() try {
->set("input_profile", processingProfile) image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
->set("embedded", TRUE) ->set("input_profile", processingProfile)
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8) ->set("embedded", TRUE)
->set("intent", VIPS_INTENT_PERCEPTUAL)); ->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
->set("intent", VIPS_INTENT_PERCEPTUAL));
} catch(...) {
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
}
} else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) { } else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) {
image = sharp::SetProfile(image, inputProfile); image = sharp::SetProfile(image, inputProfile);
} }

View File

@@ -1,12 +1,14 @@
FROM ubuntu:22.04 FROM ubuntu:23.10
ARG BRANCH=main ARG BRANCH=main
# Install basic dependencies # Install basic dependencies
RUN apt-get -y update && apt-get install -y build-essential curl git RUN apt-get -y update && apt-get install -y build-essential curl git ca-certificates gnupg
# Install latest Node.js LTS # Install latest Node.js LTS
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - RUN mkdir -p /etc/apt/keyrings
RUN apt-get install -y nodejs RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get -y update && apt-get install -y nodejs
# Install benchmark dependencies # Install benchmark dependencies
RUN apt-get install -y imagemagick libmagick++-dev graphicsmagick RUN apt-get install -y imagemagick libmagick++-dev graphicsmagick

View File

@@ -10,14 +10,14 @@
"dependencies": { "dependencies": {
"@squoosh/cli": "0.7.3", "@squoosh/cli": "0.7.3",
"@squoosh/lib": "0.5.3", "@squoosh/lib": "0.5.3",
"async": "3.2.4", "async": "3.2.5",
"benchmark": "2.1.4", "benchmark": "2.1.4",
"gm": "1.25.0", "gm": "1.25.0",
"imagemagick": "0.1.3", "imagemagick": "0.1.3",
"jimp": "0.22.10" "jimp": "0.22.10"
}, },
"optionalDependencies": { "optionalDependencies": {
"@tensorflow/tfjs-node": "4.11.0", "@tensorflow/tfjs-node": "4.13.0",
"mapnik": "4.5.9" "mapnik": "4.5.9"
}, },
"license": "Apache-2.0" "license": "Apache-2.0"

BIN
test/fixtures/invalid-illuminant.icc vendored Normal file

Binary file not shown.

View File

@@ -1,4 +1,5 @@
#!/bin/sh #!/usr/bin/env bash
set -e
if ! type valgrind >/dev/null; then if ! type valgrind >/dev/null; then
echo "Please install valgrind before running memory leak tests" echo "Please install valgrind before running memory leak tests"
@@ -7,14 +8,15 @@ fi
curl -s -o ./test/leak/libvips.supp https://raw.githubusercontent.com/libvips/libvips/master/suppressions/valgrind.supp curl -s -o ./test/leak/libvips.supp https://raw.githubusercontent.com/libvips/libvips/master/suppressions/valgrind.supp
for test in ./test/unit/*.js; do TESTS=$(ls test/unit --ignore=svg.js --ignore=text.js)
for test in $TESTS; do
G_SLICE=always-malloc G_DEBUG=gc-friendly VIPS_LEAK=1 VIPS_NOVECTOR=1 valgrind \ G_SLICE=always-malloc G_DEBUG=gc-friendly VIPS_LEAK=1 VIPS_NOVECTOR=1 valgrind \
--suppressions=test/leak/libvips.supp \ --suppressions=test/leak/libvips.supp \
--suppressions=test/leak/sharp.supp \ --suppressions=test/leak/sharp.supp \
--gen-suppressions=yes \ --gen-suppressions=yes \
--leak-check=full \ --leak-check=full \
--show-leak-kinds=definite,indirect,possible \ --show-leak-kinds=definite,indirect \
--num-callers=20 \ --num-callers=20 \
--trace-children=yes \ --trace-children=yes \
node --expose-gc node_modules/.bin/mocha --no-config --slow=60000 --timeout=120000 --require test/beforeEach.js "$test"; node --expose-gc --zero-fill-buffers node_modules/.bin/mocha --no-config --slow=60000 --timeout=120000 --require test/beforeEach.js "test/unit/$test";
done done

View File

@@ -173,41 +173,6 @@
fun:TIFFWriteEncodedTile fun:TIFFWriteEncodedTile
} }
# gsf
{
param_gsf_output_write
Memcheck:Param
write(buf)
fun:write
...
fun:gsf_output_write
}
{
value_gsf_output_write_crc32_little
Memcheck:Value8
fun:crc32_little
...
fun:gsf_output_write
}
{
param_gsf_new_do_write
Memcheck:Param
write(buf)
...
fun:new_do_write
...
fun:gsf_output_close
}
{
param_gsf_output_write
Memcheck:Param
write(buf)
...
fun:new_do_write
...
fun:gsf_output_write
}
# fontconfig # fontconfig
{ {
leak_fontconfig_FcConfigSubstituteWithPat leak_fontconfig_FcConfigSubstituteWithPat
@@ -349,11 +314,39 @@
fun:heif_context_read_from_reader fun:heif_context_read_from_reader
} }
# orc # glib
{ {
addr_orcexec leak_glib__tls_get_addr
Memcheck:Addr1 Memcheck:Leak
obj:*/orcexec.* match-leak-kinds: possible
...
fun:malloc
fun:allocate_dtv_entry
fun:allocate_and_init
fun:tls_get_addr_tail
fun:__tls_get_addr
}
{
value_g_utf8_make_valid_strlen
Memcheck:Value8
fun:strlen
fun:g_utf8_make_valid
}
{
value_g_utf8_make_valid_strncpy
Memcheck:Value8
fun:strncpy
fun:g_strndup
...
fun:g_utf8_make_valid
}
{
cond_g_utf8_make_valid_strncpy
Memcheck:Cond
fun:strncpy
fun:g_strndup
...
fun:g_utf8_make_valid
} }
# libvips # libvips
@@ -943,6 +936,79 @@
... ...
fun:_ZN2v88internal18ArrayBufferSweeper10ReleaseAllEv fun:_ZN2v88internal18ArrayBufferSweeper10ReleaseAllEv
} }
{
cond_node_Builtins_JSEntry
Memcheck:Cond
...
fun:Builtins_JSEntry
...
fun:uv__poll_io_uring
}
{
cond_node_Builtins_TestEqualStrictHandler
Memcheck:Cond
fun:Builtins_TestEqualStrictHandler
...
fun:uv__poll_io_uring
}
{
cond_node_Builtins_TestGreaterThanHandler
Memcheck:Cond
fun:Builtins_TestGreaterThanHandler
...
fun:uv__poll_io_uring
}
{
cond_node_AfterStat
Memcheck:Cond
...
fun:_ZN4node2fs9AfterStatEP7uv_fs_s
...
fun:uv__poll_io_uring
}
{
cond_node_AfterMkdirp
Memcheck:Cond
fun:_ZN4node2fs11AfterMkdirpEP7uv_fs_s
fun:_ZN4node24MakeLibuvRequestCallbackI7uv_fs_sPFvPS1_EE7WrapperES2_
fun:_ZZZN4node2fs11MKDirpAsyncEP9uv_loop_sP7uv_fs_sPKciPFvS4_EENKUlS4_E_clES4_ENUlS4_E_4_FUNES4_
fun:uv__poll_io_uring
}
{
cond_v8_ArrayBufferSweeper_Finalize
Memcheck:Cond
fun:_ZN2v88internal18ArrayBufferSweeper8FinalizeEv
}
{
cond_v8_AdjustAmountOfExternalAllocatedMemory
Memcheck:Cond
fun:_ZN2v87Isolate37AdjustAmountOfExternalAllocatedMemoryEl
}
{
cond_v8_IncrementalMarkingLimitReached
Memcheck:Cond
fun:_ZN2v88internal4Heap30IncrementalMarkingLimitReachedEv
}
{
cond_v8_ShouldExpandOldGenerationOnSlowAllocation
Memcheck:Cond
fun:_ZN2v88internal4Heap41ShouldExpandOldGenerationOnSlowAllocationEPNS0_9LocalHeapENS0_16AllocationOriginE
}
{
cond_v8_ArrayBufferSweeper_SweepingJob_SweepListFull
Memcheck:Cond
fun:_ZN2v88internal18ArrayBufferSweeper11SweepingJob13SweepListFullEPNS0_15ArrayBufferListE
}
{
cond_v8_ArrayBufferSweeper_SweepingJob_SweepYoung
Memcheck:Cond
fun:_ZN2v88internal18ArrayBufferSweeper11SweepingJob10SweepYoungEv
}
{
cond_v8_StartIncrementalMarkingIfAllocationLimitIsReachedBackground
Memcheck:Cond
fun:_ZN2v88internal4Heap59StartIncrementalMarkingIfAllocationLimitIsReachedBackgroundEv
}
{ {
addr_v8_ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0 addr_v8_ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0
Memcheck:Addr8 Memcheck:Addr8

View File

@@ -96,22 +96,28 @@ describe('libvips binaries', function () {
describe('Build time directories', () => { describe('Build time directories', () => {
it('sharp-libvips include', () => { it('sharp-libvips include', () => {
const dir = libvips.buildSharpLibvipsIncludeDir(); const dir = libvips.buildSharpLibvipsIncludeDir();
assert.strictEqual(fs.statSync(dir).isDirectory(), true); if (dir) {
assert.strictEqual(fs.statSync(dir).isDirectory(), true);
}
}); });
it('sharp-libvips cplusplus', () => { it('sharp-libvips cplusplus', () => {
const dir = libvips.buildSharpLibvipsCPlusPlusDir(); const dir = libvips.buildSharpLibvipsCPlusPlusDir();
assert.strictEqual(fs.statSync(dir).isDirectory(), true); if (dir) {
assert.strictEqual(fs.statSync(dir).isDirectory(), true);
}
}); });
it('sharp-libvips lib', () => { it('sharp-libvips lib', () => {
const dir = libvips.buildSharpLibvipsLibDir(); const dir = libvips.buildSharpLibvipsLibDir();
assert.strictEqual(fs.statSync(dir).isDirectory(), true); if (dir) {
assert.strictEqual(fs.statSync(dir).isDirectory(), true);
}
}); });
}); });
describe('Runtime detection', () => { describe('Runtime detection', () => {
it('platform', () => { it('platform', () => {
const [platform] = libvips.runtimePlatformArch().split('-'); const [platform] = libvips.runtimePlatformArch().split('-');
assert.strict(['darwin', 'linux', 'linuxmusl', 'win32'].includes(platform)); assert.strict(['darwin', 'freebsd', 'linux', 'linuxmusl', 'win32'].includes(platform));
}); });
it('arch', () => { it('arch', () => {
const [, arch] = libvips.runtimePlatformArch().split('-'); const [, arch] = libvips.runtimePlatformArch().split('-');
@@ -144,4 +150,26 @@ describe('libvips binaries', function () {
libvips.log(new Error('problem')); libvips.log(new Error('problem'));
}); });
}); });
describe('yarn locator hash', () => {
it('known platform', () => {
const cc = process.env.CC;
delete process.env.CC;
process.env.npm_config_platform = 'linux';
process.env.npm_config_arch = 's390x';
process.env.npm_config_libc = '';
const locatorHash = libvips.yarnLocator();
assert.strictEqual(locatorHash, '86cc8ee6e4');
delete process.env.npm_config_platform;
delete process.env.npm_config_arch;
delete process.env.npm_config_libc;
process.env.CC = cc;
});
it('unknown platform', () => {
process.env.npm_config_platform = 'unknown-platform';
const locatorHash = libvips.yarnLocator();
assert.strictEqual(locatorHash, '');
delete process.env.npm_config_platform;
});
});
}); });

View File

@@ -598,6 +598,24 @@ describe('Image metadata', function () {
assert.strictEqual(undefined, metadata.icc); assert.strictEqual(undefined, metadata.icc);
}); });
it('transform to invalid ICC profile emits warning', async () => {
const img = sharp({ create })
.png()
.withIccProfile(fixtures.path('invalid-illuminant.icc'));
let warningEmitted = '';
img.on('warning', (warning) => {
warningEmitted = warning;
});
const data = await img.toBuffer();
assert.strictEqual('Invalid profile', warningEmitted);
const metadata = await sharp(data).metadata();
assert.strictEqual(3, metadata.channels);
assert.strictEqual(undefined, metadata.icc);
});
it('Apply CMYK output ICC profile', function (done) { it('Apply CMYK output ICC profile', function (done) {
const output = fixtures.path('output.icc-cmyk.jpg'); const output = fixtures.path('output.icc-cmyk.jpg');
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)

View File

@@ -9,16 +9,19 @@ const sharp = require('../../');
describe('Utilities', function () { describe('Utilities', function () {
describe('Cache', function () { describe('Cache', function () {
it('Can be disabled', function () { it('Can be disabled', function (done) {
sharp.cache(false); queueMicrotask(() => {
const cache = sharp.cache(false); sharp.cache(false);
assert.strictEqual(cache.memory.current, 0); const cache = sharp.cache(false);
assert.strictEqual(cache.memory.max, 0); assert.strictEqual(cache.memory.current, 0);
assert.strictEqual(typeof cache.memory.high, 'number'); assert.strictEqual(cache.memory.max, 0);
assert.strictEqual(cache.files.current, 0); assert.strictEqual(typeof cache.memory.high, 'number');
assert.strictEqual(cache.files.max, 0); assert.strictEqual(cache.files.current, 0);
assert.strictEqual(cache.items.current, 0); assert.strictEqual(cache.files.max, 0);
assert.strictEqual(cache.items.max, 0); assert.strictEqual(cache.items.current, 0);
assert.strictEqual(cache.items.max, 0);
done();
});
}); });
it('Can be enabled with defaults', function () { it('Can be enabled with defaults', function () {
const cache = sharp.cache(true); const cache = sharp.cache(true);