Compare commits
60 Commits
v0.33.3
...
v0.33.5-rc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2474bd4163 | ||
|
|
ff2e689d35 | ||
|
|
6327f13717 | ||
|
|
f1e69a218e | ||
|
|
3c14dbb21e | ||
|
|
82cebc31d0 | ||
|
|
ad36fa0605 | ||
|
|
de42667767 | ||
|
|
2eb03b0049 | ||
|
|
f7ed9b7fb6 | ||
|
|
7fbb988180 | ||
|
|
490210fc60 | ||
|
|
735fee74db | ||
|
|
67a5854b89 | ||
|
|
f128ebdbd4 | ||
|
|
2672de2480 | ||
|
|
67a4592756 | ||
|
|
10c6f474d9 | ||
|
|
d642108be2 | ||
|
|
c2a024101b | ||
|
|
2f0bbebfc9 | ||
|
|
60c5c5083d | ||
|
|
eab7dc1b49 | ||
|
|
5c7f37a0e0 | ||
|
|
ae06f46914 | ||
|
|
9c05ea8dd2 | ||
|
|
472aaf3311 | ||
|
|
56fae3eda1 | ||
|
|
cc96c21e42 | ||
|
|
1d344888ec | ||
|
|
bee235ee76 | ||
|
|
19d0e272e6 | ||
|
|
16b764f1c1 | ||
|
|
1593ee3838 | ||
|
|
668b5ba8bc | ||
|
|
29336f4cc7 | ||
|
|
b5fddd7c5e | ||
|
|
da655a1859 | ||
|
|
93c615d39f | ||
|
|
f325dc3ec9 | ||
|
|
0fde71c783 | ||
|
|
9c8fbaa1cc | ||
|
|
a9e662e612 | ||
|
|
ba843002be | ||
|
|
7f3d452bc5 | ||
|
|
aa8bc19362 | ||
|
|
36e60bf040 | ||
|
|
a1309aa3b8 | ||
|
|
3e8a0fc522 | ||
|
|
397ee492d9 | ||
|
|
52b9dc0f63 | ||
|
|
a715c73fc2 | ||
|
|
579cf93030 | ||
|
|
f67228e5ea | ||
|
|
6257994746 | ||
|
|
7950fc0ea3 | ||
|
|
fc93ab3b82 | ||
|
|
0981b24f60 | ||
|
|
02fd565476 | ||
|
|
e55bb93b10 |
2
.github/ISSUE_TEMPLATE/installation.md
vendored
@@ -43,7 +43,7 @@ and try again before opening an issue.
|
|||||||
|
|
||||||
<!-- 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 with `--include=optional`
|
- [ ] I am using npm >= 10.1.0 with `--include=optional`
|
||||||
- [ ] I am using yarn >= 3.2.0
|
- [ ] I am using yarn >= 3.2.0
|
||||||
- [ ] I am using pnpm >= 7.1.0 with `--no-optional=false`
|
- [ ] I am using pnpm >= 7.1.0 with `--no-optional=false`
|
||||||
- [ ] I am using Deno
|
- [ ] I am using Deno
|
||||||
|
|||||||
16
.github/ISSUE_TEMPLATE/possible-bug.md
vendored
@@ -32,6 +32,22 @@ If you are using another package which depends on a version of `sharp` that is n
|
|||||||
|
|
||||||
<!-- Please provide output of the above command here. -->
|
<!-- Please provide output of the above command here. -->
|
||||||
|
|
||||||
|
### Does this problem relate to file caching?
|
||||||
|
|
||||||
|
The default behaviour of libvips is to cache input files, which can lead to `EBUSY` or `EPERM` errors on Windows.
|
||||||
|
Use [`sharp.cache(false)`](https://sharp.pixelplumbing.com/api-utility#cache) to switch this feature off.
|
||||||
|
|
||||||
|
- [ ] Adding `sharp.cache(false)` does not fix this problem.
|
||||||
|
|
||||||
|
### Does this problem relate to images appearing to have been rotated by 90 degrees?
|
||||||
|
|
||||||
|
Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.
|
||||||
|
|
||||||
|
- To auto-orient pixel values use the parameter-less [`rotate()`](https://sharp.pixelplumbing.com/api-operation#rotate) operation.
|
||||||
|
- To retain EXIF Orientation use [`keepExif()`](https://sharp.pixelplumbing.com/api-output#keepexif).
|
||||||
|
|
||||||
|
- [ ] Using `rotate()` or `keepExif()` does not fix this problem.
|
||||||
|
|
||||||
### What are the steps to reproduce?
|
### What are the steps to reproduce?
|
||||||
|
|
||||||
<!-- Please enter steps to reproduce here. -->
|
<!-- Please enter steps to reproduce here. -->
|
||||||
|
|||||||
12
.github/workflows/ci.yml
vendored
@@ -36,13 +36,13 @@ jobs:
|
|||||||
container: node:20-alpine3.18
|
container: node:20-alpine3.18
|
||||||
nodejs_version_major: 20
|
nodejs_version_major: 20
|
||||||
platform: linuxmusl-x64
|
platform: linuxmusl-x64
|
||||||
- os: macos-11
|
- os: macos-12
|
||||||
nodejs_arch: x64
|
nodejs_arch: x64
|
||||||
nodejs_version: "^18.17.0"
|
nodejs_version: "^18.17.0"
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
platform: darwin-x64
|
platform: darwin-x64
|
||||||
prebuild: true
|
prebuild: true
|
||||||
- os: macos-11
|
- os: macos-12
|
||||||
nodejs_arch: x64
|
nodejs_arch: x64
|
||||||
nodejs_version: "^20.3.0"
|
nodejs_version: "^20.3.0"
|
||||||
nodejs_version_major: 20
|
nodejs_version_major: 20
|
||||||
@@ -84,7 +84,7 @@ jobs:
|
|||||||
- name: Dependencies (Rocky Linux glibc)
|
- name: Dependencies (Rocky Linux glibc)
|
||||||
if: contains(matrix.container, 'rockylinux')
|
if: contains(matrix.container, 'rockylinux')
|
||||||
run: |
|
run: |
|
||||||
dnf install -y gcc-toolset-11-gcc-c++ make git python3 fontconfig google-noto-sans-fonts
|
dnf install -y gcc-toolset-11-gcc-c++ make git python3.12 fontconfig google-noto-sans-fonts
|
||||||
echo "/opt/rh/gcc-toolset-11/root/usr/bin" >> $GITHUB_PATH
|
echo "/opt/rh/gcc-toolset-11/root/usr/bin" >> $GITHUB_PATH
|
||||||
- name: Dependencies (Linux musl)
|
- name: Dependencies (Linux musl)
|
||||||
if: contains(matrix.container, 'alpine')
|
if: contains(matrix.container, 'alpine')
|
||||||
@@ -131,12 +131,14 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- platform: linux-arm
|
- platform: linux-arm
|
||||||
|
distro: bullseye
|
||||||
run_on_arch: armv6
|
run_on_arch: armv6
|
||||||
nodejs_arch: armv6l
|
nodejs_arch: armv6l
|
||||||
nodejs_hostname: unofficial-builds.nodejs.org
|
nodejs_hostname: unofficial-builds.nodejs.org
|
||||||
nodejs_version: "18.17.0"
|
nodejs_version: "18.17.0"
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
- platform: linux-s390x
|
- platform: linux-s390x
|
||||||
|
distro: bullseye
|
||||||
run_on_arch: s390x
|
run_on_arch: s390x
|
||||||
nodejs_arch: s390x
|
nodejs_arch: s390x
|
||||||
nodejs_hostname: nodejs.org
|
nodejs_hostname: nodejs.org
|
||||||
@@ -147,7 +149,7 @@ jobs:
|
|||||||
- uses: uraimo/run-on-arch-action@v2
|
- uses: uraimo/run-on-arch-action@v2
|
||||||
with:
|
with:
|
||||||
arch: ${{ matrix.run_on_arch }}
|
arch: ${{ matrix.run_on_arch }}
|
||||||
distro: buster
|
distro: ${{ matrix.distro }}
|
||||||
env: |
|
env: |
|
||||||
prebuild_upload: "${{ startsWith(github.ref, 'refs/tags/') && secrets.GITHUB_TOKEN || '' }}"
|
prebuild_upload: "${{ startsWith(github.ref, 'refs/tags/') && secrets.GITHUB_TOKEN || '' }}"
|
||||||
run: |
|
run: |
|
||||||
@@ -169,7 +171,7 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
name: wasm32 - prebuild
|
name: wasm32 - prebuild
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
container: "emscripten/emsdk:3.1.56"
|
container: "emscripten/emsdk:3.1.64"
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|||||||
42
.github/workflows/npm.yml
vendored
@@ -31,6 +31,10 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
runtime: node
|
runtime: node
|
||||||
package-manager: yarn-pnp
|
package-manager: yarn-pnp
|
||||||
|
- name: linux-x64-node-yarn-v1
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-v1
|
||||||
- name: linux-x64-deno
|
- name: linux-x64-deno
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
runtime: deno
|
runtime: deno
|
||||||
@@ -39,26 +43,30 @@ jobs:
|
|||||||
runtime: bun
|
runtime: bun
|
||||||
|
|
||||||
- name: darwin-x64-node-npm
|
- name: darwin-x64-node-npm
|
||||||
runs-on: macos-11
|
runs-on: macos-12
|
||||||
runtime: node
|
runtime: node
|
||||||
package-manager: npm
|
package-manager: npm
|
||||||
- name: darwin-x64-node-pnpm
|
- name: darwin-x64-node-pnpm
|
||||||
runs-on: macos-11
|
runs-on: macos-12
|
||||||
runtime: node
|
runtime: node
|
||||||
package-manager: pnpm
|
package-manager: pnpm
|
||||||
- name: darwin-x64-node-yarn
|
- name: darwin-x64-node-yarn
|
||||||
runs-on: macos-11
|
runs-on: macos-12
|
||||||
runtime: node
|
runtime: node
|
||||||
package-manager: yarn
|
package-manager: yarn
|
||||||
- name: darwin-x64-node-yarn-pnp
|
- name: darwin-x64-node-yarn-pnp
|
||||||
runs-on: macos-11
|
runs-on: macos-12
|
||||||
runtime: node
|
runtime: node
|
||||||
package-manager: yarn-pnp
|
package-manager: yarn-pnp
|
||||||
|
- name: darwin-x64-node-yarn-v1
|
||||||
|
runs-on: macos-12
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-v1
|
||||||
- name: darwin-x64-deno
|
- name: darwin-x64-deno
|
||||||
runs-on: macos-11
|
runs-on: macos-12
|
||||||
runtime: deno
|
runtime: deno
|
||||||
- name: darwin-x64-bun
|
- name: darwin-x64-bun
|
||||||
runs-on: macos-11
|
runs-on: macos-12
|
||||||
runtime: bun
|
runtime: bun
|
||||||
|
|
||||||
- name: win32-x64-node-npm
|
- name: win32-x64-node-npm
|
||||||
@@ -77,6 +85,10 @@ jobs:
|
|||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
runtime: node
|
runtime: node
|
||||||
package-manager: yarn-pnp
|
package-manager: yarn-pnp
|
||||||
|
- name: win32-x64-node-yarn-v1
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-v1
|
||||||
- name: win32-x64-deno
|
- name: win32-x64-deno
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
runtime: deno
|
runtime: deno
|
||||||
@@ -89,7 +101,7 @@ jobs:
|
|||||||
node-version: 20
|
node-version: 20
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
if: ${{ matrix.package-manager == 'pnpm' }}
|
if: ${{ matrix.package-manager == 'pnpm' }}
|
||||||
uses: pnpm/action-setup@v2
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
- name: Install Deno
|
- name: Install Deno
|
||||||
@@ -99,18 +111,18 @@ jobs:
|
|||||||
deno-version: v1.x
|
deno-version: v1.x
|
||||||
- name: Install Bun
|
- name: Install Bun
|
||||||
if: ${{ matrix.runtime == 'bun' }}
|
if: ${{ matrix.runtime == 'bun' }}
|
||||||
uses: oven-sh/setup-bun@v1
|
uses: oven-sh/setup-bun@v2
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
|
||||||
- name: Version
|
- name: Version
|
||||||
id: version
|
id: version
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
core.setOutput('semver', context.ref.replace('refs/tags/v',''))
|
core.setOutput('semver', context.ref.replace('refs/tags/v',''))
|
||||||
- name: Create package.json
|
- name: Create package.json
|
||||||
uses: DamianReeves/write-file-action@v1.2
|
uses: DamianReeves/write-file-action@v1.3
|
||||||
with:
|
with:
|
||||||
path: package.json
|
path: package.json
|
||||||
contents: |
|
contents: |
|
||||||
@@ -121,7 +133,7 @@ jobs:
|
|||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
- name: Create release.mjs
|
- name: Create release.mjs
|
||||||
uses: DamianReeves/write-file-action@v1.2
|
uses: DamianReeves/write-file-action@v1.3
|
||||||
with:
|
with:
|
||||||
path: release.mjs
|
path: release.mjs
|
||||||
contents: |
|
contents: |
|
||||||
@@ -163,6 +175,14 @@ jobs:
|
|||||||
yarn install
|
yarn install
|
||||||
yarn node release.mjs
|
yarn node release.mjs
|
||||||
|
|
||||||
|
- name: Run with Node.js + yarn v1
|
||||||
|
if: ${{ matrix.package-manager == 'yarn-v1' }}
|
||||||
|
run: |
|
||||||
|
corepack enable
|
||||||
|
yarn set version classic
|
||||||
|
yarn install
|
||||||
|
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
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ The input image will be converted to the provided colourspace at the start of th
|
|||||||
All operations will use this colourspace before converting to the output colourspace,
|
All operations will use this colourspace before converting to the output colourspace,
|
||||||
as defined by [toColourspace](#tocolourspace).
|
as defined by [toColourspace](#tocolourspace).
|
||||||
|
|
||||||
This feature is experimental and has not yet been fully-tested with all operations.
|
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
- `xmp`: Buffer containing raw XMP data, if present
|
- `xmp`: Buffer containing raw XMP data, if present
|
||||||
- `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
- `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||||
- `formatMagick`: String containing format for images loaded via *magick
|
- `formatMagick`: String containing format for images loaded via *magick
|
||||||
|
- `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ const output = await sharp(input).median(5).toBuffer();
|
|||||||
|
|
||||||
|
|
||||||
## blur
|
## blur
|
||||||
> blur([sigma]) ⇒ <code>Sharp</code>
|
> blur([options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
Blur the image.
|
Blur the image.
|
||||||
|
|
||||||
@@ -245,9 +245,12 @@ When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
|||||||
- <code>Error</code> Invalid parameters
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
| Param | Type | Description |
|
| Param | Type | Default | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| [sigma] | <code>number</code> | a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`. |
|
| [options] | <code>Object</code> \| <code>number</code> \| <code>Boolean</code> | | |
|
||||||
|
| [options.sigma] | <code>number</code> | | a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`. |
|
||||||
|
| [options.precision] | <code>string</code> | <code>"'integer'"</code> | How accurate the operation should be, one of: integer, float, approximate. |
|
||||||
|
| [options.minAmplitude] | <code>number</code> | <code>0.2</code> | A value between 0.001 and 1. A smaller value will generate a larger, more accurate mask. |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -580,7 +583,7 @@ Recombine the image with the specified matrix.
|
|||||||
|
|
||||||
| Param | Type | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| inputMatrix | <code>Array.<Array.<number>></code> | 3x3 Recombination matrix |
|
| inputMatrix | <code>Array.<Array.<number>></code> | 3x3 or 4x4 Recombination matrix |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
| Param | Type | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| fileOut | <code>string</code> | the path to write the image data to. |
|
| fileOut | <code>string</code> | the path to write the image data to. |
|
||||||
| [callback] | <code>function</code> | called on completion with two arguments `(err, info)`. `info` contains the output image `format`, `size` (bytes), `width`, `height`, `channels` and `premultiplied` (indicating if premultiplication was used). When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`. When using the attention crop strategy also contains `attentionX` and `attentionY`, the focal point of the cropped region. May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text. |
|
| [callback] | <code>function</code> | called on completion with two arguments `(err, info)`. `info` contains the output image `format`, `size` (bytes), `width`, `height`, `channels` and `premultiplied` (indicating if premultiplication was used). When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`. When using the attention crop strategy also contains `attentionX` and `attentionY`, the focal point of the cropped region. Animated output will also contain `pageHeight` and `pages`. May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text. |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -59,6 +59,7 @@ See [withMetadata](#withmetadata) for control over this.
|
|||||||
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
Animated output will also contain `pageHeight` and `pages`.
|
||||||
May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|||||||
@@ -21,18 +21,22 @@ When using a **fit** of `cover` or `contain`, the default **position** is `centr
|
|||||||
|
|
||||||
Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
||||||
|
|
||||||
The experimental strategy-based approach resizes so one dimension is at its target length
|
The strategy-based approach initially resizes so one dimension is at its target length
|
||||||
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
||||||
- `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
- `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
||||||
- `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
- `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
||||||
|
|
||||||
Possible interpolation kernels are:
|
Possible downsizing kernels are:
|
||||||
- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||||
|
- `linear`: Use a [triangle filter](https://en.wikipedia.org/wiki/Triangular_function).
|
||||||
- `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
- `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||||
- `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
- `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
||||||
- `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
- `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||||
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
|
|
||||||
|
When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.
|
||||||
|
Downsampling kernels without a matching upsampling interpolator map to `cubic`.
|
||||||
|
|
||||||
Only one resize can occur per pipeline.
|
Only one resize can occur per pipeline.
|
||||||
Previous calls to `resize` in the same pipeline will be ignored.
|
Previous calls to `resize` in the same pipeline will be ignored.
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ Previous calls to `resize` in the same pipeline will be ignored.
|
|||||||
| [options.fit] | <code>String</code> | <code>'cover'</code> | How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`. |
|
| [options.fit] | <code>String</code> | <code>'cover'</code> | How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`. |
|
||||||
| [options.position] | <code>String</code> | <code>'centre'</code> | A position, gravity or strategy to use when `fit` is `cover` or `contain`. |
|
| [options.position] | <code>String</code> | <code>'centre'</code> | A position, gravity or strategy to use when `fit` is `cover` or `contain`. |
|
||||||
| [options.background] | <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
|
| [options.background] | <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
|
||||||
| [options.kernel] | <code>String</code> | <code>'lanczos3'</code> | The kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load. |
|
| [options.kernel] | <code>String</code> | <code>'lanczos3'</code> | The kernel to use for image reduction and the inferred interpolator to use for upsampling. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load. |
|
||||||
| [options.withoutEnlargement] | <code>Boolean</code> | <code>false</code> | Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions. |
|
| [options.withoutEnlargement] | <code>Boolean</code> | <code>false</code> | Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions. |
|
||||||
| [options.withoutReduction] | <code>Boolean</code> | <code>false</code> | Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions. |
|
| [options.withoutReduction] | <code>Boolean</code> | <code>false</code> | Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions. |
|
||||||
| [options.fastShrinkOnLoad] | <code>Boolean</code> | <code>true</code> | Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension. |
|
| [options.fastShrinkOnLoad] | <code>Boolean</code> | <code>true</code> | Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension. |
|
||||||
|
|||||||
@@ -2,7 +2,70 @@
|
|||||||
|
|
||||||
## v0.33 - *gauge*
|
## v0.33 - *gauge*
|
||||||
|
|
||||||
Requires libvips v8.15.2
|
Requires libvips v8.15.3
|
||||||
|
|
||||||
|
### v0.33.5 - TBD
|
||||||
|
|
||||||
|
* Upgrade to libvips v8.15.3 for upstream bug fixes.
|
||||||
|
|
||||||
|
* Add `pageHeight` and `pages` to response of multi-page output.
|
||||||
|
[#3411](https://github.com/lovell/sharp/issues/3411)
|
||||||
|
|
||||||
|
* Ensure option to force use of a globally-installed libvips works correctly.
|
||||||
|
[#4111](https://github.com/lovell/sharp/pull/4111)
|
||||||
|
[@project0](https://github.com/project0)
|
||||||
|
|
||||||
|
* Minimise use of `engines` property to improve yarn v1 support.
|
||||||
|
[#4130](https://github.com/lovell/sharp/issues/4130)
|
||||||
|
|
||||||
|
* Ensure `sharp.format.heif` includes only AVIF when using prebuilt binaries.
|
||||||
|
[#4132](https://github.com/lovell/sharp/issues/4132)
|
||||||
|
|
||||||
|
* Add support to recomb operation for 4x4 matrices.
|
||||||
|
[#4147](https://github.com/lovell/sharp/pull/4147)
|
||||||
|
[@ton11797](https://github.com/ton11797)
|
||||||
|
|
||||||
|
* Expose PNG text chunks as `comments` metadata.
|
||||||
|
[#4157](https://github.com/lovell/sharp/pull/4157)
|
||||||
|
[@nkeynes](https://github.com/nkeynes)
|
||||||
|
|
||||||
|
* Expose optional `precision` and `minAmplitude` parameters of `blur` operation.
|
||||||
|
[#4168](https://github.com/lovell/sharp/pull/4168)
|
||||||
|
[#4172](https://github.com/lovell/sharp/pull/4172)
|
||||||
|
[@marcosc90](https://github.com/marcosc90)
|
||||||
|
|
||||||
|
* Ensure `keepIccProfile` avoids colour transformation where possible.
|
||||||
|
[#4186](https://github.com/lovell/sharp/issues/4186)
|
||||||
|
|
||||||
|
### v0.33.4 - 16th May 2024
|
||||||
|
|
||||||
|
* Remove experimental status from `pipelineColourspace`.
|
||||||
|
|
||||||
|
* Reduce default concurrency when musl thread over-subscription detected.
|
||||||
|
|
||||||
|
* TypeScript: add missing definitions for `OverlayOptions`.
|
||||||
|
[#4048](https://github.com/lovell/sharp/pull/4048)
|
||||||
|
[@ike-gg](https://github.com/ike-gg)
|
||||||
|
|
||||||
|
* Install: add advanced option to force use of a globally-installed libvips.
|
||||||
|
[#4060](https://github.com/lovell/sharp/issues/4060)
|
||||||
|
|
||||||
|
* Expose `bilinear` resizing kernel (and interpolator).
|
||||||
|
[#4061](https://github.com/lovell/sharp/issues/4061)
|
||||||
|
|
||||||
|
* Ensure `extend` operation stays sequential for multi-page TIFF (regression in 0.32.0).
|
||||||
|
[#4069](https://github.com/lovell/sharp/issues/4069)
|
||||||
|
|
||||||
|
* Tighten validation of constructor `text` integer properties.
|
||||||
|
[#4071](https://github.com/lovell/sharp/issues/4071)
|
||||||
|
|
||||||
|
* Simplify internal StaySequential logic.
|
||||||
|
[#4074](https://github.com/lovell/sharp/pull/4074)
|
||||||
|
[@kleisauke](https://github.com/kleisauke)
|
||||||
|
|
||||||
|
* Ensure negate operation occurs after profile conversion.
|
||||||
|
[#4096](https://github.com/lovell/sharp/pull/4096)
|
||||||
|
[@adriaanmeuris](https://github.com/adriaanmeuris)
|
||||||
|
|
||||||
### v0.33.3 - 23rd March 2024
|
### v0.33.3 - 23rd March 2024
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Name: Brandon Aaron
|
|||||||
GitHub: https://github.com/brandonaaron
|
GitHub: https://github.com/brandonaaron
|
||||||
|
|
||||||
Name: Andreas Lind
|
Name: Andreas Lind
|
||||||
GitHub: https://github.com/papandreouGitHub:
|
GitHub: https://github.com/papandreou
|
||||||
|
|
||||||
Name: Maurus Cuelenaere
|
Name: Maurus Cuelenaere
|
||||||
GitHub: https://github.com/mcuelenaere
|
GitHub: https://github.com/mcuelenaere
|
||||||
@@ -261,7 +261,7 @@ GitHub: https://github.com/brahima
|
|||||||
Name: Anton Marsden
|
Name: Anton Marsden
|
||||||
GitHub: https://github.com/antonmarsden
|
GitHub: https://github.com/antonmarsden
|
||||||
|
|
||||||
Name: Marcos Casagrande
|
Name: Marcos Casagrande
|
||||||
GitHub: https://github.com/marcosc90
|
GitHub: https://github.com/marcosc90
|
||||||
|
|
||||||
Name: Emanuel Jöbstl
|
Name: Emanuel Jöbstl
|
||||||
@@ -290,3 +290,15 @@ GitHub: https://github.com/yolopunk
|
|||||||
|
|
||||||
Name: Mert Alev
|
Name: Mert Alev
|
||||||
GitHub: https://github.com/mertalev
|
GitHub: https://github.com/mertalev
|
||||||
|
|
||||||
|
Name: Adriaan Meuris
|
||||||
|
GitHub: https://github.com/adriaanmeuris
|
||||||
|
|
||||||
|
Name: Richard Hillmann
|
||||||
|
GitHub: https://github.com/project0
|
||||||
|
|
||||||
|
Name: Pongsatorn Manusopit
|
||||||
|
GitHub: https://github.com/ton11797
|
||||||
|
|
||||||
|
Name: Nathan Keynes
|
||||||
|
GitHub: https://github.com/nkeynes
|
||||||
|
|||||||
@@ -7,15 +7,13 @@
|
|||||||
<meta name="description" content="Resize large images in common formats to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions">
|
<meta name="description" content="Resize large images in common formats to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions">
|
||||||
<meta property="og:title" content="sharp - High performance Node.js image processing">
|
<meta property="og:title" content="sharp - High performance Node.js image processing">
|
||||||
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo-600.png">
|
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo-600.png">
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; object-src 'none'; style-src 'unsafe-inline';
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; connect-src 'self'; object-src 'none';
|
||||||
img-src 'unsafe-inline' data: https://cdn.jsdelivr.net/gh/lovell/ https://www.google-analytics.com;
|
style-src 'unsafe-inline';
|
||||||
connect-src 'self' https://www.google-analytics.com;
|
img-src 'unsafe-inline' data: https://cdn.jsdelivr.net/gh/lovell/;
|
||||||
script-src 'self' 'unsafe-inline' 'unsafe-eval'
|
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://static.cloudflareinsights.com/beacon.min.js/;">
|
||||||
https://www.google-analytics.com/analytics.js;">
|
|
||||||
<link rel="icon" type="image/svg+xml" href="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg">
|
<link rel="icon" type="image/svg+xml" href="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg">
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo-32.png">
|
<link rel="icon" type="image/png" sizes="32x32" href="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo-32.png">
|
||||||
<link rel="author" href="/humans.txt" type="text/plain">
|
<link rel="author" href="/humans.txt" type="text/plain">
|
||||||
<link rel="dns-prefetch" href="https://www.google-analytics.com">
|
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
{
|
{
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
@@ -67,7 +65,6 @@
|
|||||||
<div id="docute"></div>
|
<div id="docute"></div>
|
||||||
<script src="docute.min.js"></script>
|
<script src="docute.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
/* docute-google-analytics@1/dist/index.min.js */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).docuteGoogleAnalytics=n()}(this,function(){"use strict";function e(e){var n;window.ga||((n=document.createElement("script")).async=!0,n.src="https://www.google-analytics.com/analytics.js",document.body.appendChild(n),window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=Number(new Date),ga("create",e,"auto"))}function n(n,t){e(t),ga("set","page",n),ga("send","pageview")}return function(e){return{name:"@google-analytics",extend:function(t){!function(e,t){"function"==typeof e?e(function(e){n(e,t)}):e.afterEach(function(e){n(e.fullPath,t)})}(t.router,e)}}}});
|
|
||||||
const docuteApiTitlePlugin = {
|
const docuteApiTitlePlugin = {
|
||||||
name: 'apiTitle',
|
name: 'apiTitle',
|
||||||
extend(api) {
|
extend(api) {
|
||||||
@@ -126,7 +123,6 @@
|
|||||||
detectSystemDarkTheme: true,
|
detectSystemDarkTheme: true,
|
||||||
footer: '<a href="https://pixelplumbing.com/" target="_blank">pixelplumbing.com<a>',
|
footer: '<a href="https://pixelplumbing.com/" target="_blank">pixelplumbing.com<a>',
|
||||||
plugins: [
|
plugins: [
|
||||||
docuteGoogleAnalytics('UA-13034748-12'),
|
|
||||||
docuteApiTitlePlugin,
|
docuteApiTitlePlugin,
|
||||||
docuteApiSearchPlugin
|
docuteApiSearchPlugin
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -20,11 +20,6 @@ pnpm add sharp
|
|||||||
yarn add sharp
|
yarn add sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
|
||||||
# yarn v1 (maintenance mode)
|
|
||||||
yarn add sharp --ignore-engines
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
bun add sharp
|
bun add sharp
|
||||||
```
|
```
|
||||||
@@ -45,7 +40,7 @@ Ready-compiled sharp and libvips binaries are provided for use on the most commo
|
|||||||
* macOS ARM64
|
* macOS ARM64
|
||||||
* Linux ARM (glibc >= 2.28)
|
* Linux ARM (glibc >= 2.28)
|
||||||
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
|
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
|
||||||
* Linux s390x (glibc >= 2.28)
|
* Linux s390x (glibc >= 2.31)
|
||||||
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
|
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
|
||||||
* Windows x64
|
* Windows x64
|
||||||
* Windows x86
|
* Windows x86
|
||||||
@@ -67,15 +62,17 @@ within the same installation tree and/or using the same lockfile.
|
|||||||
|
|
||||||
Provides limited support via `--os`, `--cpu` and `--libc` flags.
|
Provides limited support via `--os`, `--cpu` and `--libc` flags.
|
||||||
|
|
||||||
Example to support both Intel and ARM CPUs on macOS:
|
To support macOS with Intel x64 and ARM64 CPUs:
|
||||||
```sh
|
```sh
|
||||||
npm install --cpu=x64 --os=darwin sharp
|
npm install --cpu=x64 --os=darwin sharp
|
||||||
npm install --cpu=arm64 --os=darwin sharp
|
npm install --cpu=arm64 --os=darwin sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
Example to support both glibc and musl-based Linux:
|
When the cross-target is Linux, the C standard library must be specified.
|
||||||
|
|
||||||
|
To support glibc (e.g. Debian) and musl (e.g. Alpine) Linux with Intel x64 CPUs:
|
||||||
```sh
|
```sh
|
||||||
npm install --cpu=x64 --os=linux sharp
|
npm install --cpu=x64 --os=linux --libc=glibc sharp
|
||||||
npm install --cpu=x64 --os=linux --libc=musl sharp
|
npm install --cpu=x64 --os=linux --libc=musl sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -90,7 +87,7 @@ Use the [supportedArchitectures](https://pnpm.io/package_json#pnpmsupportedarchi
|
|||||||
## 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,
|
||||||
make sure it is at least the version listed under `engines.libvips` in the `package.json` file
|
make sure it is at least the version listed under `config.libvips` in the `package.json` file
|
||||||
and that it can be located using `pkg-config --modversion vips-cpp`.
|
and that it can be located using `pkg-config --modversion vips-cpp`.
|
||||||
|
|
||||||
For help compiling libvips and its dependencies, please see
|
For help compiling libvips and its dependencies, please see
|
||||||
@@ -103,9 +100,14 @@ and on macOS when running Node.js under Rosetta.
|
|||||||
|
|
||||||
This module will be compiled from source at `npm install` time when:
|
This module will be compiled from source at `npm install` time when:
|
||||||
|
|
||||||
* a globally-installed libvips is detected (set the `SHARP_IGNORE_GLOBAL_LIBVIPS` environment variable to skip this), or
|
* a globally-installed libvips is detected, or
|
||||||
* when the `npm install --build-from-source` flag is used.
|
* when the `npm install --build-from-source` flag is used.
|
||||||
|
|
||||||
|
The logic to detect a globally-installed libvips can be skipped by setting the
|
||||||
|
`SHARP_IGNORE_GLOBAL_LIBVIPS` (never try to use it) or
|
||||||
|
`SHARP_FORCE_GLOBAL_LIBVIPS` (always try to use it, even when missing or outdated)
|
||||||
|
environment variables.
|
||||||
|
|
||||||
Building from source requires:
|
Building from source requires:
|
||||||
|
|
||||||
* C++11 compiler
|
* C++11 compiler
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ module.exports = [
|
|||||||
'current',
|
'current',
|
||||||
'date',
|
'date',
|
||||||
'default',
|
'default',
|
||||||
|
'deprecated',
|
||||||
'does',
|
'does',
|
||||||
'each',
|
'each',
|
||||||
'either',
|
'either',
|
||||||
@@ -46,6 +47,7 @@ module.exports = [
|
|||||||
'given',
|
'given',
|
||||||
'has',
|
'has',
|
||||||
'have',
|
'have',
|
||||||
|
'helps',
|
||||||
'how',
|
'how',
|
||||||
'image',
|
'image',
|
||||||
'implies',
|
'implies',
|
||||||
@@ -58,6 +60,7 @@ module.exports = [
|
|||||||
'lots',
|
'lots',
|
||||||
'make',
|
'make',
|
||||||
'may',
|
'may',
|
||||||
|
'meaning',
|
||||||
'more',
|
'more',
|
||||||
'most',
|
'most',
|
||||||
'much',
|
'much',
|
||||||
@@ -79,6 +82,7 @@ module.exports = [
|
|||||||
'pre',
|
'pre',
|
||||||
'previously',
|
'previously',
|
||||||
'produce',
|
'produce',
|
||||||
|
'proper',
|
||||||
'provide',
|
'provide',
|
||||||
'provided',
|
'provided',
|
||||||
'ready',
|
'ready',
|
||||||
@@ -116,6 +120,7 @@ module.exports = [
|
|||||||
'unless',
|
'unless',
|
||||||
'unmaintained',
|
'unmaintained',
|
||||||
'unsuitable',
|
'unsuitable',
|
||||||
|
'unsupported',
|
||||||
'until',
|
'until',
|
||||||
'use',
|
'use',
|
||||||
'used',
|
'used',
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ try {
|
|||||||
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');
|
const addonApi = require('node-addon-api');
|
||||||
log('Found node-addon-api');
|
log(`Found node-addon-api ${addonApi.version || ''}`);
|
||||||
} 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 ${gyp().version}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Please add node-gyp to your dependencies');
|
log('Please add node-gyp to your dependencies');
|
||||||
return;
|
return;
|
||||||
@@ -30,7 +30,7 @@ try {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (useGlobalLibvips()) {
|
if (useGlobalLibvips(log)) {
|
||||||
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');
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ function grayscale (grayscale) {
|
|||||||
* All operations will use this colourspace before converting to the output colourspace,
|
* All operations will use this colourspace before converting to the output colourspace,
|
||||||
* as defined by {@link #tocolourspace|toColourspace}.
|
* as defined by {@link #tocolourspace|toColourspace}.
|
||||||
*
|
*
|
||||||
* This feature is experimental and has not yet been fully-tested with all operations.
|
|
||||||
*
|
|
||||||
* @since 0.29.0
|
* @since 0.29.0
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
@@ -226,6 +226,8 @@ const Sharp = function (input, options) {
|
|||||||
negateAlpha: true,
|
negateAlpha: true,
|
||||||
medianSize: 0,
|
medianSize: 0,
|
||||||
blurSigma: 0,
|
blurSigma: 0,
|
||||||
|
precision: 'integer',
|
||||||
|
minAmpl: 0.2,
|
||||||
sharpenSigma: 0,
|
sharpenSigma: 0,
|
||||||
sharpenM1: 1,
|
sharpenM1: 1,
|
||||||
sharpenM2: 2,
|
sharpenM2: 2,
|
||||||
|
|||||||
33
lib/index.d.ts
vendored
@@ -464,7 +464,7 @@ declare namespace sharp {
|
|||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
* @returns A sharp instance that can be used to chain operations
|
* @returns A sharp instance that can be used to chain operations
|
||||||
*/
|
*/
|
||||||
blur(sigma?: number | boolean): Sharp;
|
blur(sigma?: number | boolean | BlurOptions): Sharp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge alpha transparency channel, if any, with background.
|
* Merge alpha transparency channel, if any, with background.
|
||||||
@@ -571,11 +571,11 @@ declare namespace sharp {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Recomb the image with the specified matrix.
|
* Recomb the image with the specified matrix.
|
||||||
* @param inputMatrix 3x3 Recombination matrix
|
* @param inputMatrix 3x3 Recombination matrix or 4x4 Recombination matrix
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
* @returns A sharp instance that can be used to chain operations
|
* @returns A sharp instance that can be used to chain operations
|
||||||
*/
|
*/
|
||||||
recomb(inputMatrix: Matrix3x3): Sharp;
|
recomb(inputMatrix: Matrix3x3 | Matrix4x4): Sharp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the image using brightness, saturation, hue rotation and lightness.
|
* Transforms the image using brightness, saturation, hue rotation and lightness.
|
||||||
@@ -1108,6 +1108,8 @@ declare namespace sharp {
|
|||||||
resolutionUnit?: 'inch' | 'cm' | undefined;
|
resolutionUnit?: 'inch' | 'cm' | undefined;
|
||||||
/** String containing format for images loaded via *magick */
|
/** String containing format for images loaded via *magick */
|
||||||
formatMagick?: string | undefined;
|
formatMagick?: string | undefined;
|
||||||
|
/** Array of keyword/text pairs representing PNG text blocks, if present. */
|
||||||
|
comments?: CommentsMetadata[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LevelMetadata {
|
interface LevelMetadata {
|
||||||
@@ -1115,6 +1117,11 @@ declare namespace sharp {
|
|||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CommentsMetadata {
|
||||||
|
keyword: string;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface Stats {
|
interface Stats {
|
||||||
/** Array of channel statistics for each channel in the image. */
|
/** Array of channel statistics for each channel in the image. */
|
||||||
channels: ChannelStats[];
|
channels: ChannelStats[];
|
||||||
@@ -1335,6 +1342,17 @@ declare namespace sharp {
|
|||||||
background?: Color | undefined;
|
background?: Color | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Precision = 'integer' | 'float' | 'approximate';
|
||||||
|
|
||||||
|
interface BlurOptions {
|
||||||
|
/** A value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2` */
|
||||||
|
sigma: number;
|
||||||
|
/** A value between 0.001 and 1. A smaller value will generate a larger, more accurate mask. */
|
||||||
|
minAmplitude?: number;
|
||||||
|
/** How accurate the operation should be, one of: integer, float, approximate. (optional, default "integer") */
|
||||||
|
precision?: Precision | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
interface FlattenOptions {
|
interface FlattenOptions {
|
||||||
/** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
|
/** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
|
||||||
background?: Color | undefined;
|
background?: Color | undefined;
|
||||||
@@ -1479,6 +1497,14 @@ declare namespace sharp {
|
|||||||
tile?: boolean | undefined;
|
tile?: boolean | undefined;
|
||||||
/** Set to true to avoid premultipling the image below. Equivalent to the --premultiplied vips option. */
|
/** Set to true to avoid premultipling the image below. Equivalent to the --premultiplied vips option. */
|
||||||
premultiplied?: boolean | undefined;
|
premultiplied?: boolean | undefined;
|
||||||
|
/** number representing the DPI for vector overlay image. (optional, default 72)*/
|
||||||
|
density?: number | undefined;
|
||||||
|
/** Set to true to read all frames/pages of an animated image. (optional, default false) */
|
||||||
|
animated?: boolean | undefined;
|
||||||
|
/** see sharp() constructor, (optional, default 'warning') */
|
||||||
|
failOn?: FailOnOptions | undefined;
|
||||||
|
/** see sharp() constructor, (optional, default 268402689) */
|
||||||
|
limitInputPixels?: number | boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TileOptions {
|
interface TileOptions {
|
||||||
@@ -1722,6 +1748,7 @@ declare namespace sharp {
|
|||||||
|
|
||||||
type Matrix2x2 = [[number, number], [number, number]];
|
type Matrix2x2 = [[number, number], [number, number]];
|
||||||
type Matrix3x3 = [[number, number, number], [number, number, number], [number, number, number]];
|
type Matrix3x3 = [[number, number, number], [number, number, number], [number, number, number]];
|
||||||
|
type Matrix4x4 = [[number, number, number, number], [number, number, number, number], [number, number, number, number], [number, number, number, number]];
|
||||||
}
|
}
|
||||||
|
|
||||||
export = sharp;
|
export = sharp;
|
||||||
|
|||||||
17
lib/input.js
@@ -296,17 +296,17 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.width)) {
|
if (is.defined(inputOptions.text.width)) {
|
||||||
if (is.number(inputOptions.text.width)) {
|
if (is.integer(inputOptions.text.width) && inputOptions.text.width > 0) {
|
||||||
inputDescriptor.textWidth = inputOptions.text.width;
|
inputDescriptor.textWidth = inputOptions.text.width;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('text.textWidth', 'number', inputOptions.text.width);
|
throw is.invalidParameterError('text.width', 'positive integer', inputOptions.text.width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.height)) {
|
if (is.defined(inputOptions.text.height)) {
|
||||||
if (is.number(inputOptions.text.height)) {
|
if (is.integer(inputOptions.text.height) && inputOptions.text.height > 0) {
|
||||||
inputDescriptor.textHeight = inputOptions.text.height;
|
inputDescriptor.textHeight = inputOptions.text.height;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('text.height', 'number', inputOptions.text.height);
|
throw is.invalidParameterError('text.height', 'positive integer', inputOptions.text.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.align)) {
|
if (is.defined(inputOptions.text.align)) {
|
||||||
@@ -324,10 +324,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.dpi)) {
|
if (is.defined(inputOptions.text.dpi)) {
|
||||||
if (is.number(inputOptions.text.dpi) && is.inRange(inputOptions.text.dpi, 1, 100000)) {
|
if (is.integer(inputOptions.text.dpi) && is.inRange(inputOptions.text.dpi, 1, 1000000)) {
|
||||||
inputDescriptor.textDpi = inputOptions.text.dpi;
|
inputDescriptor.textDpi = inputOptions.text.dpi;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('text.dpi', 'number between 1 and 100000', inputOptions.text.dpi);
|
throw is.invalidParameterError('text.dpi', 'integer between 1 and 1000000', inputOptions.text.dpi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.rgba)) {
|
if (is.defined(inputOptions.text.rgba)) {
|
||||||
@@ -338,10 +338,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.spacing)) {
|
if (is.defined(inputOptions.text.spacing)) {
|
||||||
if (is.number(inputOptions.text.spacing)) {
|
if (is.integer(inputOptions.text.spacing) && is.inRange(inputOptions.text.spacing, -1000000, 1000000)) {
|
||||||
inputDescriptor.textSpacing = inputOptions.text.spacing;
|
inputDescriptor.textSpacing = inputOptions.text.spacing;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('text.spacing', 'number', inputOptions.text.spacing);
|
throw is.invalidParameterError('text.spacing', 'integer between -1000000 and 1000000', inputOptions.text.spacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(inputOptions.text.wrap)) {
|
if (is.defined(inputOptions.text.wrap)) {
|
||||||
@@ -450,6 +450,7 @@ function _isStreamInput () {
|
|||||||
* - `xmp`: Buffer containing raw XMP data, if present
|
* - `xmp`: Buffer containing raw XMP data, if present
|
||||||
* - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
* - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||||
* - `formatMagick`: String containing format for images loaded via *magick
|
* - `formatMagick`: String containing format for images loaded via *magick
|
||||||
|
* - `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const metadata = await sharp(input).metadata();
|
* const metadata = await sharp(input).metadata();
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
|||||||
const semverSatisfies = require('semver/functions/satisfies');
|
const semverSatisfies = require('semver/functions/satisfies');
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
|
|
||||||
const { engines, optionalDependencies } = require('../package.json');
|
const { config, 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;
|
config.libvips;
|
||||||
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
||||||
|
|
||||||
const prebuiltPlatforms = [
|
const prebuiltPlatforms = [
|
||||||
@@ -162,15 +162,23 @@ const pkgConfigPath = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const useGlobalLibvips = () => {
|
const skipSearch = (status, reason, logger) => {
|
||||||
|
if (logger) {
|
||||||
|
logger(`Detected ${reason}, skipping search for globally-installed libvips`);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
};
|
||||||
|
|
||||||
|
const useGlobalLibvips = (logger) => {
|
||||||
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||||
log('Detected SHARP_IGNORE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips');
|
return skipSearch(false, 'SHARP_IGNORE_GLOBAL_LIBVIPS', logger);
|
||||||
return false;
|
}
|
||||||
|
if (Boolean(process.env.SHARP_FORCE_GLOBAL_LIBVIPS) === true) {
|
||||||
|
return skipSearch(true, 'SHARP_FORCE_GLOBAL_LIBVIPS', logger);
|
||||||
}
|
}
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (isRosetta()) {
|
if (isRosetta()) {
|
||||||
log('Detected Rosetta, skipping search for globally-installed libvips');
|
return skipSearch(false, 'Rosetta', logger);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
const globalVipsVersion = globalLibvipsVersion();
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
return !!globalVipsVersion && /* istanbul ignore next */
|
return !!globalVipsVersion && /* istanbul ignore next */
|
||||||
|
|||||||
@@ -6,6 +6,17 @@
|
|||||||
const color = require('color');
|
const color = require('color');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How accurate an operation should be.
|
||||||
|
* @member
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const vipsPrecision = {
|
||||||
|
integer: 'integer',
|
||||||
|
float: 'float',
|
||||||
|
approximate: 'approximate'
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate the output image by either an explicit angle
|
* Rotate the output image by either an explicit angle
|
||||||
* or auto-orient based on the EXIF `Orientation` tag.
|
* or auto-orient based on the EXIF `Orientation` tag.
|
||||||
@@ -367,23 +378,51 @@ function median (size) {
|
|||||||
* .blur(5)
|
* .blur(5)
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @param {number} [sigma] a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
* @param {Object|number|Boolean} [options]
|
||||||
|
* @param {number} [options.sigma] a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
|
* @param {string} [options.precision='integer'] How accurate the operation should be, one of: integer, float, approximate.
|
||||||
|
* @param {number} [options.minAmplitude=0.2] A value between 0.001 and 1. A smaller value will generate a larger, more accurate mask.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function blur (sigma) {
|
function blur (options) {
|
||||||
if (!is.defined(sigma)) {
|
let sigma;
|
||||||
|
if (is.number(options)) {
|
||||||
|
sigma = options;
|
||||||
|
} else if (is.plainObject(options)) {
|
||||||
|
if (!is.number(options.sigma)) {
|
||||||
|
throw is.invalidParameterError('options.sigma', 'number between 0.3 and 1000', sigma);
|
||||||
|
}
|
||||||
|
sigma = options.sigma;
|
||||||
|
if ('precision' in options) {
|
||||||
|
if (is.string(vipsPrecision[options.precision])) {
|
||||||
|
this.options.precision = vipsPrecision[options.precision];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('precision', 'one of: integer, float, approximate', options.precision);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('minAmplitude' in options) {
|
||||||
|
if (is.number(options.minAmplitude) && is.inRange(options.minAmplitude, 0.001, 1)) {
|
||||||
|
this.options.minAmpl = options.minAmplitude;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('minAmplitude', 'number between 0.001 and 1', options.minAmplitude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is.defined(options)) {
|
||||||
// No arguments: default to mild blur
|
// No arguments: default to mild blur
|
||||||
this.options.blurSigma = -1;
|
this.options.blurSigma = -1;
|
||||||
} else if (is.bool(sigma)) {
|
} else if (is.bool(options)) {
|
||||||
// Boolean argument: apply mild blur?
|
// Boolean argument: apply mild blur?
|
||||||
this.options.blurSigma = sigma ? -1 : 0;
|
this.options.blurSigma = options ? -1 : 0;
|
||||||
} else if (is.number(sigma) && is.inRange(sigma, 0.3, 1000)) {
|
} else if (is.number(sigma) && is.inRange(sigma, 0.3, 1000)) {
|
||||||
// Numeric argument: specific sigma
|
// Numeric argument: specific sigma
|
||||||
this.options.blurSigma = sigma;
|
this.options.blurSigma = sigma;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('sigma', 'number between 0.3 and 1000', sigma);
|
throw is.invalidParameterError('sigma', 'number between 0.3 and 1000', sigma);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,24 +826,22 @@ function linear (a, b) {
|
|||||||
* // With this example input, a sepia filter has been applied
|
* // With this example input, a sepia filter has been applied
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @param {Array<Array<number>>} inputMatrix - 3x3 Recombination matrix
|
* @param {Array<Array<number>>} inputMatrix - 3x3 or 4x4 Recombination matrix
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function recomb (inputMatrix) {
|
function recomb (inputMatrix) {
|
||||||
if (!Array.isArray(inputMatrix) || inputMatrix.length !== 3 ||
|
if (!Array.isArray(inputMatrix)) {
|
||||||
inputMatrix[0].length !== 3 ||
|
throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
|
||||||
inputMatrix[1].length !== 3 ||
|
|
||||||
inputMatrix[2].length !== 3
|
|
||||||
) {
|
|
||||||
// must pass in a kernel
|
|
||||||
throw new Error('Invalid recombination matrix');
|
|
||||||
}
|
}
|
||||||
this.options.recombMatrix = [
|
if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
|
||||||
inputMatrix[0][0], inputMatrix[0][1], inputMatrix[0][2],
|
throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
|
||||||
inputMatrix[1][0], inputMatrix[1][1], inputMatrix[1][2],
|
}
|
||||||
inputMatrix[2][0], inputMatrix[2][1], inputMatrix[2][2]
|
const recombMatrix = inputMatrix.flat().map(Number);
|
||||||
].map(Number);
|
if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
|
||||||
|
throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
|
||||||
|
}
|
||||||
|
this.options.recombMatrix = recombMatrix;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ const bitdepthFromColourCount = (colours) => 1 << 31 - Math.clz32(Math.ceil(Math
|
|||||||
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
* When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
* When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
* When using the attention crop strategy also contains `attentionX` and `attentionY`, the focal point of the cropped region.
|
* When using the attention crop strategy also contains `attentionX` and `attentionY`, the focal point of the cropped region.
|
||||||
|
* Animated output will also contain `pageHeight` and `pages`.
|
||||||
* May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
* May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
||||||
* @returns {Promise<Object>} - when no callback is provided
|
* @returns {Promise<Object>} - when no callback is provided
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
@@ -109,6 +110,7 @@ function toFile (fileOut, callback) {
|
|||||||
* - `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
* - `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
* When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
* When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
* Animated output will also contain `pageHeight` and `pages`.
|
||||||
* May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
* May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
||||||
*
|
*
|
||||||
* A `Promise` is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ const strategy = {
|
|||||||
*/
|
*/
|
||||||
const kernel = {
|
const kernel = {
|
||||||
nearest: 'nearest',
|
nearest: 'nearest',
|
||||||
|
linear: 'linear',
|
||||||
cubic: 'cubic',
|
cubic: 'cubic',
|
||||||
mitchell: 'mitchell',
|
mitchell: 'mitchell',
|
||||||
lanczos2: 'lanczos2',
|
lanczos2: 'lanczos2',
|
||||||
@@ -135,18 +136,22 @@ function isResizeExpected (options) {
|
|||||||
*
|
*
|
||||||
* Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
* Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
||||||
*
|
*
|
||||||
* The experimental strategy-based approach resizes so one dimension is at its target length
|
* The strategy-based approach initially resizes so one dimension is at its target length
|
||||||
* then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
* then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
||||||
* - `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
* - `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
||||||
* - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
* - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
||||||
*
|
*
|
||||||
* Possible interpolation kernels are:
|
* Possible downsizing kernels are:
|
||||||
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||||
|
* - `linear`: Use a [triangle filter](https://en.wikipedia.org/wiki/Triangular_function).
|
||||||
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||||
* - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
* - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
||||||
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||||
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
*
|
*
|
||||||
|
* When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.
|
||||||
|
* Downsampling kernels without a matching upsampling interpolator map to `cubic`.
|
||||||
|
*
|
||||||
* Only one resize can occur per pipeline.
|
* Only one resize can occur per pipeline.
|
||||||
* Previous calls to `resize` in the same pipeline will be ignored.
|
* Previous calls to `resize` in the same pipeline will be ignored.
|
||||||
*
|
*
|
||||||
@@ -239,7 +244,7 @@ function isResizeExpected (options) {
|
|||||||
* @param {String} [options.fit='cover'] - How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`.
|
* @param {String} [options.fit='cover'] - How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`.
|
||||||
* @param {String} [options.position='centre'] - A position, gravity or strategy to use when `fit` is `cover` or `contain`.
|
* @param {String} [options.position='centre'] - A position, gravity or strategy to use when `fit` is `cover` or `contain`.
|
||||||
* @param {String|Object} [options.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
* @param {String|Object} [options.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
||||||
* @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.
|
* @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction and the inferred interpolator to use for upsampling. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.
|
||||||
* @param {Boolean} [options.withoutEnlargement=false] - Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions.
|
* @param {Boolean} [options.withoutEnlargement=false] - Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions.
|
||||||
* @param {Boolean} [options.withoutReduction=false] - Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions.
|
* @param {Boolean} [options.withoutReduction=false] - Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions.
|
||||||
* @param {Boolean} [options.fastShrinkOnLoad=true] - Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension.
|
* @param {Boolean} [options.fastShrinkOnLoad=true] - Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension.
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ if (sharp) {
|
|||||||
help.push(
|
help.push(
|
||||||
'- Ensure optional dependencies can be installed:',
|
'- Ensure optional dependencies can be installed:',
|
||||||
' npm install --include=optional sharp',
|
' npm install --include=optional sharp',
|
||||||
' yarn add sharp --ignore-engines',
|
|
||||||
'- Ensure your package manager supports multi-platform installation:',
|
'- Ensure your package manager supports multi-platform installation:',
|
||||||
' See https://sharp.pixelplumbing.com/install#cross-platform',
|
' See https://sharp.pixelplumbing.com/install#cross-platform',
|
||||||
'- Add platform-specific dependencies:',
|
'- Add platform-specific dependencies:',
|
||||||
@@ -73,9 +72,9 @@ if (sharp) {
|
|||||||
}
|
}
|
||||||
if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
|
if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
|
||||||
try {
|
try {
|
||||||
const { engines } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
|
const { config } = 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 = `${config.musl ? 'musl' : 'glibc'} ${config.musl || config.glibc}`;
|
||||||
help.push(
|
help.push(
|
||||||
'- Update your OS:',
|
'- Update your OS:',
|
||||||
` Found ${libcFound}`,
|
` Found ${libcFound}`,
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ if (!libvipsVersion.isGlobal) {
|
|||||||
}
|
}
|
||||||
versions.sharp = require('../package.json').version;
|
versions.sharp = require('../package.json').version;
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (versions.heif && format.heif) {
|
||||||
|
// Prebuilt binaries provide AV1
|
||||||
|
format.heif.input.fileSuffix = ['.avif'];
|
||||||
|
format.heif.output.alias = ['avif'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
* Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
||||||
* Existing entries in the cache will be trimmed after any change in limits.
|
* Existing entries in the cache will be trimmed after any change in limits.
|
||||||
@@ -153,6 +160,9 @@ function concurrency (concurrency) {
|
|||||||
if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
|
if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
|
||||||
// Reduce default concurrency to 1 when using glibc memory allocator
|
// Reduce default concurrency to 1 when using glibc memory allocator
|
||||||
sharp.concurrency(1);
|
sharp.concurrency(1);
|
||||||
|
} else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) {
|
||||||
|
// Reduce default concurrency when musl thread over-subscription detected
|
||||||
|
sharp.concurrency(require('node:os').availableParallelism());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-darwin-arm64",
|
"name": "@img/sharp-darwin-arm64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-darwin-arm64": "1.0.2"
|
"@img/sharp-libvips-darwin-arm64": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,11 +29,7 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
|
||||||
"yarn": ">=3.2.0",
|
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"glibc": ">=2.26"
|
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-darwin-x64",
|
"name": "@img/sharp-darwin-x64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-darwin-x64": "1.0.2"
|
"@img/sharp-libvips-darwin-x64": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,11 +29,7 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
|
||||||
"yarn": ">=3.2.0",
|
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"glibc": ">=2.26"
|
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-linux-arm",
|
"name": "@img/sharp-linux-arm",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-linux-arm": "1.0.2"
|
"@img/sharp-libvips-linux-arm": "1.0.5"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,10 +29,9 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
},
|
||||||
"yarn": ">=3.2.0",
|
"config": {
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"glibc": ">=2.28"
|
"glibc": ">=2.28"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-linux-arm64",
|
"name": "@img/sharp-linux-arm64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-linux-arm64": "1.0.2"
|
"@img/sharp-libvips-linux-arm64": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,10 +29,9 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
},
|
||||||
"yarn": ">=3.2.0",
|
"config": {
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"glibc": ">=2.26"
|
"glibc": ">=2.26"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-linux-s390x",
|
"name": "@img/sharp-linux-s390x",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-linux-s390x": "1.0.2"
|
"@img/sharp-libvips-linux-s390x": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,11 +29,10 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
},
|
||||||
"yarn": ">=3.2.0",
|
"config": {
|
||||||
"pnpm": ">=7.1.0",
|
"glibc": ">=2.31"
|
||||||
"glibc": ">=2.28"
|
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-linux-x64",
|
"name": "@img/sharp-linux-x64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-linux-x64": "1.0.2"
|
"@img/sharp-libvips-linux-x64": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,10 +29,9 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
},
|
||||||
"yarn": ">=3.2.0",
|
"config": {
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"glibc": ">=2.26"
|
"glibc": ">=2.26"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-linuxmusl-arm64",
|
"name": "@img/sharp-linuxmusl-arm64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-linuxmusl-arm64": "1.0.2"
|
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,10 +29,9 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
},
|
||||||
"yarn": ">=3.2.0",
|
"config": {
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"musl": ">=1.2.2"
|
"musl": ">=1.2.2"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-linuxmusl-x64",
|
"name": "@img/sharp-linuxmusl-x64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-libvips-linuxmusl-x64": "1.0.2"
|
"@img/sharp-libvips-linuxmusl-x64": "1.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
@@ -29,10 +29,9 @@
|
|||||||
"./package": "./package.json"
|
"./package": "./package.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
},
|
||||||
"yarn": ">=3.2.0",
|
"config": {
|
||||||
"pnpm": ">=7.1.0",
|
|
||||||
"musl": ">=1.2.2"
|
"musl": ">=1.2.2"
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp",
|
"name": "@img/sharp",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.1",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"darwin-arm64",
|
"darwin-arm64",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-wasm32",
|
"name": "@img/sharp-wasm32",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -28,13 +28,10 @@
|
|||||||
"./versions": "./versions.json"
|
"./versions": "./versions.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
|
||||||
"yarn": ">=3.2.0",
|
|
||||||
"pnpm": ">=7.1.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emnapi/runtime": "^1.1.0"
|
"@emnapi/runtime": "^1.2.0"
|
||||||
},
|
},
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"wasm32"
|
"wasm32"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-win32-ia32",
|
"name": "@img/sharp-win32-ia32",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -28,10 +28,7 @@
|
|||||||
"./versions": "./versions.json"
|
"./versions": "./versions.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
|
||||||
"yarn": ">=3.2.0",
|
|
||||||
"pnpm": ">=7.1.0"
|
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@img/sharp-win32-x64",
|
"name": "@img/sharp-win32-x64",
|
||||||
"version": "0.33.3",
|
"version": "0.33.5-rc.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",
|
||||||
@@ -28,10 +28,7 @@
|
|||||||
"./versions": "./versions.json"
|
"./versions": "./versions.json"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"npm": ">=9.6.5",
|
|
||||||
"yarn": ">=3.2.0",
|
|
||||||
"pnpm": ">=7.1.0"
|
|
||||||
},
|
},
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
|
|||||||
79
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"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.3",
|
"version": "0.33.5-rc.1",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -82,13 +82,14 @@
|
|||||||
"Joris Dugué <zaruike10@gmail.com>",
|
"Joris Dugué <zaruike10@gmail.com>",
|
||||||
"Chris Banks <christopher.bradley.banks@gmail.com>",
|
"Chris Banks <christopher.bradley.banks@gmail.com>",
|
||||||
"Ompal Singh <ompal.hitm09@gmail.com>",
|
"Ompal Singh <ompal.hitm09@gmail.com>",
|
||||||
"Brodan <christopher.hranj@gmail.com",
|
"Brodan <christopher.hranj@gmail.com>",
|
||||||
"Ankur Parihar <ankur.github@gmail.com>",
|
"Ankur Parihar <ankur.github@gmail.com>",
|
||||||
"Brahim Ait elhaj <brahima@gmail.com>",
|
"Brahim Ait elhaj <brahima@gmail.com>",
|
||||||
"Mart Jansink <m.jansink@gmail.com>",
|
"Mart Jansink <m.jansink@gmail.com>",
|
||||||
"Lachlan Newman <lachnewman007@gmail.com>",
|
"Lachlan Newman <lachnewman007@gmail.com>",
|
||||||
"Dennis Beatty <dennis@dcbeatty.com>",
|
"Dennis Beatty <dennis@dcbeatty.com>",
|
||||||
"Ingvar Stepanyan <me@rreverser.com>"
|
"Ingvar Stepanyan <me@rreverser.com>",
|
||||||
|
"Don Denton <don@happycollision.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node install/check",
|
"install": "node install/check",
|
||||||
@@ -138,56 +139,58 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"detect-libc": "^2.0.3",
|
"detect-libc": "^2.0.3",
|
||||||
"semver": "^7.6.0"
|
"semver": "^7.6.3"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@img/sharp-darwin-arm64": "0.33.3",
|
"@img/sharp-darwin-arm64": "0.33.5-rc.1",
|
||||||
"@img/sharp-darwin-x64": "0.33.3",
|
"@img/sharp-darwin-x64": "0.33.5-rc.1",
|
||||||
"@img/sharp-libvips-darwin-arm64": "1.0.2",
|
"@img/sharp-libvips-darwin-arm64": "1.0.4",
|
||||||
"@img/sharp-libvips-darwin-x64": "1.0.2",
|
"@img/sharp-libvips-darwin-x64": "1.0.4",
|
||||||
"@img/sharp-libvips-linux-arm": "1.0.2",
|
"@img/sharp-libvips-linux-arm": "1.0.5",
|
||||||
"@img/sharp-libvips-linux-arm64": "1.0.2",
|
"@img/sharp-libvips-linux-arm64": "1.0.4",
|
||||||
"@img/sharp-libvips-linux-s390x": "1.0.2",
|
"@img/sharp-libvips-linux-s390x": "1.0.4",
|
||||||
"@img/sharp-libvips-linux-x64": "1.0.2",
|
"@img/sharp-libvips-linux-x64": "1.0.4",
|
||||||
"@img/sharp-libvips-linuxmusl-arm64": "1.0.2",
|
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4",
|
||||||
"@img/sharp-libvips-linuxmusl-x64": "1.0.2",
|
"@img/sharp-libvips-linuxmusl-x64": "1.0.4",
|
||||||
"@img/sharp-linux-arm": "0.33.3",
|
"@img/sharp-linux-arm": "0.33.5-rc.1",
|
||||||
"@img/sharp-linux-arm64": "0.33.3",
|
"@img/sharp-linux-arm64": "0.33.5-rc.1",
|
||||||
"@img/sharp-linux-s390x": "0.33.3",
|
"@img/sharp-linux-s390x": "0.33.5-rc.1",
|
||||||
"@img/sharp-linux-x64": "0.33.3",
|
"@img/sharp-linux-x64": "0.33.5-rc.1",
|
||||||
"@img/sharp-linuxmusl-arm64": "0.33.3",
|
"@img/sharp-linuxmusl-arm64": "0.33.5-rc.1",
|
||||||
"@img/sharp-linuxmusl-x64": "0.33.3",
|
"@img/sharp-linuxmusl-x64": "0.33.5-rc.1",
|
||||||
"@img/sharp-wasm32": "0.33.3",
|
"@img/sharp-wasm32": "0.33.5-rc.1",
|
||||||
"@img/sharp-win32-ia32": "0.33.3",
|
"@img/sharp-win32-ia32": "0.33.5-rc.1",
|
||||||
"@img/sharp-win32-x64": "0.33.3"
|
"@img/sharp-win32-x64": "0.33.5-rc.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@emnapi/runtime": "^1.1.0",
|
"@emnapi/runtime": "^1.2.0",
|
||||||
"@img/sharp-libvips-dev": "1.0.2",
|
"@img/sharp-libvips-dev": "1.0.4",
|
||||||
"@img/sharp-libvips-dev-wasm32": "1.0.3",
|
"@img/sharp-libvips-dev-wasm32": "1.0.5",
|
||||||
"@img/sharp-libvips-win32-ia32": "1.0.2",
|
"@img/sharp-libvips-win32-ia32": "1.0.4",
|
||||||
"@img/sharp-libvips-win32-x64": "1.0.2",
|
"@img/sharp-libvips-win32-x64": "1.0.4",
|
||||||
"@types/node": "*",
|
"@types/node": "*",
|
||||||
"async": "^3.2.5",
|
"async": "^3.2.5",
|
||||||
"cc": "^3.0.1",
|
"cc": "^3.0.1",
|
||||||
"emnapi": "^1.1.0",
|
"emnapi": "^1.2.0",
|
||||||
"exif-reader": "^2.0.1",
|
"exif-reader": "^2.0.1",
|
||||||
"extract-zip": "^2.0.1",
|
"extract-zip": "^2.0.1",
|
||||||
"icc": "^3.0.0",
|
"icc": "^3.0.0",
|
||||||
"jsdoc-to-markdown": "^8.0.1",
|
"jsdoc-to-markdown": "^8.0.3",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^10.3.0",
|
"mocha": "^10.7.3",
|
||||||
"node-addon-api": "^8.0.0",
|
"node-addon-api": "^8.1.0",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^17.0.0",
|
||||||
"prebuild": "^13.0.0",
|
"prebuild": "^13.0.1",
|
||||||
"semistandard": "^17.0.0",
|
"semistandard": "^17.0.0",
|
||||||
"tar-fs": "^3.0.5",
|
"tar-fs": "^3.0.6",
|
||||||
"tsd": "^0.30.7"
|
"tsd": "^0.31.1"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
"libvips": ">=8.15.2"
|
},
|
||||||
|
"config": {
|
||||||
|
"libvips": ">=8.15.3"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
|
|||||||
@@ -192,7 +192,7 @@
|
|||||||
'-Oz',
|
'-Oz',
|
||||||
'-sALLOW_MEMORY_GROWTH',
|
'-sALLOW_MEMORY_GROWTH',
|
||||||
'-sENVIRONMENT=node',
|
'-sENVIRONMENT=node',
|
||||||
'-sEXPORTED_FUNCTIONS=["_vips_shutdown", "_uv_library_shutdown"]',
|
'-sEXPORTED_FUNCTIONS=["emnapiInit", "_vips_shutdown", "_uv_library_shutdown"]',
|
||||||
'-sNODERAWFS',
|
'-sNODERAWFS',
|
||||||
'-sTEXTDECODER=0',
|
'-sTEXTDECODER=0',
|
||||||
'-sWASM_ASYNC_COMPILATION=0',
|
'-sWASM_ASYNC_COMPILATION=0',
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace sharp {
|
|||||||
Napi::Buffer<char> buffer = input.Get("buffer").As<Napi::Buffer<char>>();
|
Napi::Buffer<char> buffer = input.Get("buffer").As<Napi::Buffer<char>>();
|
||||||
descriptor->bufferLength = buffer.Length();
|
descriptor->bufferLength = buffer.Length();
|
||||||
descriptor->buffer = buffer.Data();
|
descriptor->buffer = buffer.Data();
|
||||||
descriptor->isBuffer = TRUE;
|
descriptor->isBuffer = true;
|
||||||
}
|
}
|
||||||
descriptor->failOn = AttrAsEnum<VipsFailOn>(input, "failOn", VIPS_TYPE_FAIL_ON);
|
descriptor->failOn = AttrAsEnum<VipsFailOn>(input, "failOn", VIPS_TYPE_FAIL_ON);
|
||||||
// Density for vector-based input
|
// Density for vector-based input
|
||||||
@@ -384,7 +384,7 @@ namespace sharp {
|
|||||||
->set("access", descriptor->access)
|
->set("access", descriptor->access)
|
||||||
->set("fail_on", descriptor->failOn);
|
->set("fail_on", descriptor->failOn);
|
||||||
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
|
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
|
||||||
option->set("unlimited", TRUE);
|
option->set("unlimited", true);
|
||||||
}
|
}
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||||
option->set("dpi", descriptor->density);
|
option->set("dpi", descriptor->density);
|
||||||
@@ -488,7 +488,7 @@ namespace sharp {
|
|||||||
->set("access", descriptor->access)
|
->set("access", descriptor->access)
|
||||||
->set("fail_on", descriptor->failOn);
|
->set("fail_on", descriptor->failOn);
|
||||||
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
|
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
|
||||||
option->set("unlimited", TRUE);
|
option->set("unlimited", true);
|
||||||
}
|
}
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||||
option->set("dpi", descriptor->density);
|
option->set("dpi", descriptor->density);
|
||||||
@@ -768,7 +768,7 @@ namespace sharp {
|
|||||||
int *timeout = VIPS_NEW(im, int);
|
int *timeout = VIPS_NEW(im, int);
|
||||||
*timeout = seconds;
|
*timeout = seconds;
|
||||||
g_signal_connect(im, "eval", G_CALLBACK(VipsProgressCallBack), timeout);
|
g_signal_connect(im, "eval", G_CALLBACK(VipsProgressCallBack), timeout);
|
||||||
vips_image_set_progress(im, TRUE);
|
vips_image_set_progress(im, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -778,7 +778,7 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
void VipsProgressCallBack(VipsImage *im, VipsProgress *progress, int *timeout) {
|
void VipsProgressCallBack(VipsImage *im, VipsProgress *progress, int *timeout) {
|
||||||
if (*timeout > 0 && progress->run >= *timeout) {
|
if (*timeout > 0 && progress->run >= *timeout) {
|
||||||
vips_image_set_kill(im, TRUE);
|
vips_image_set_kill(im, true);
|
||||||
vips_error("timeout", "%d%% complete", progress->percent);
|
vips_error("timeout", "%d%% complete", progress->percent);
|
||||||
*timeout = 0;
|
*timeout = 0;
|
||||||
}
|
}
|
||||||
@@ -1081,9 +1081,10 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
Ensure decoding remains sequential.
|
Ensure decoding remains sequential.
|
||||||
*/
|
*/
|
||||||
VImage StaySequential(VImage image, VipsAccess access, bool condition) {
|
VImage StaySequential(VImage image, bool condition) {
|
||||||
if (access == VIPS_ACCESS_SEQUENTIAL && condition) {
|
if (vips_image_is_sequential(image.get_image()) && condition) {
|
||||||
return image.copy_memory();
|
image = image.copy_memory().copy();
|
||||||
|
image.remove(VIPS_META_SEQUENTIAL);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/common.h
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION < 8) || \
|
#if (VIPS_MAJOR_VERSION < 8) || \
|
||||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 15) || \
|
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 15) || \
|
||||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 15 && VIPS_MICRO_VERSION < 2)
|
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 15 && VIPS_MICRO_VERSION < 3)
|
||||||
#error "libvips version 8.15.2+ is required - please see https://sharp.pixelplumbing.com/install"
|
#error "libvips version 8.15.3+ is required - please see https://sharp.pixelplumbing.com/install"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
|
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
|
||||||
@@ -79,12 +79,12 @@ namespace sharp {
|
|||||||
buffer(nullptr),
|
buffer(nullptr),
|
||||||
failOn(VIPS_FAIL_ON_WARNING),
|
failOn(VIPS_FAIL_ON_WARNING),
|
||||||
limitInputPixels(0x3FFF * 0x3FFF),
|
limitInputPixels(0x3FFF * 0x3FFF),
|
||||||
unlimited(FALSE),
|
unlimited(false),
|
||||||
access(VIPS_ACCESS_RANDOM),
|
access(VIPS_ACCESS_RANDOM),
|
||||||
bufferLength(0),
|
bufferLength(0),
|
||||||
isBuffer(FALSE),
|
isBuffer(false),
|
||||||
density(72.0),
|
density(72.0),
|
||||||
ignoreIcc(FALSE),
|
ignoreIcc(false),
|
||||||
rawDepth(VIPS_FORMAT_UCHAR),
|
rawDepth(VIPS_FORMAT_UCHAR),
|
||||||
rawChannels(0),
|
rawChannels(0),
|
||||||
rawWidth(0),
|
rawWidth(0),
|
||||||
@@ -103,9 +103,9 @@ namespace sharp {
|
|||||||
textWidth(0),
|
textWidth(0),
|
||||||
textHeight(0),
|
textHeight(0),
|
||||||
textAlign(VIPS_ALIGN_LOW),
|
textAlign(VIPS_ALIGN_LOW),
|
||||||
textJustify(FALSE),
|
textJustify(false),
|
||||||
textDpi(72),
|
textDpi(72),
|
||||||
textRgba(FALSE),
|
textRgba(false),
|
||||||
textSpacing(0),
|
textSpacing(0),
|
||||||
textWrap(VIPS_TEXT_WRAP_WORD),
|
textWrap(VIPS_TEXT_WRAP_WORD),
|
||||||
textAutofitDpi(0) {}
|
textAutofitDpi(0) {}
|
||||||
@@ -386,7 +386,7 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
Ensure decoding remains sequential.
|
Ensure decoding remains sequential.
|
||||||
*/
|
*/
|
||||||
VImage StaySequential(VImage image, VipsAccess access, bool condition = TRUE);
|
VImage StaySequential(VImage image, bool condition = true);
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
'default_configuration': 'Release',
|
'default_configuration': 'Release',
|
||||||
'type': 'executable',
|
'type': 'executable',
|
||||||
'cflags': [
|
'cflags': [
|
||||||
'-pthread',
|
'-pthread'
|
||||||
'-sDEFAULT_TO_CXX=0'
|
|
||||||
],
|
],
|
||||||
'cflags_cc': [
|
'cflags_cc': [
|
||||||
'-pthread'
|
'-pthread'
|
||||||
@@ -19,6 +18,7 @@
|
|||||||
'--js-library=<!(node -p "require(\'emnapi\').js_library")',
|
'--js-library=<!(node -p "require(\'emnapi\').js_library")',
|
||||||
'-sAUTO_JS_LIBRARIES=0',
|
'-sAUTO_JS_LIBRARIES=0',
|
||||||
'-sAUTO_NATIVE_LIBRARIES=0',
|
'-sAUTO_NATIVE_LIBRARIES=0',
|
||||||
|
'-sDEFAULT_TO_CXX=0',
|
||||||
'-sNODEJS_CATCH_EXIT=0',
|
'-sNODEJS_CATCH_EXIT=0',
|
||||||
'-sNODEJS_CATCH_REJECTION=0'
|
'-sNODEJS_CATCH_REJECTION=0'
|
||||||
],
|
],
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
'EMNAPI_WORKER_POOL_SIZE=1'
|
'EMNAPI_WORKER_POOL_SIZE=1'
|
||||||
],
|
],
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'<!(node -p "require(\'emnapi\').include")'
|
'<!(node -p "require(\'emnapi\').include_dir")'
|
||||||
],
|
],
|
||||||
'sources': [
|
'sources': [
|
||||||
'<!@(node -p "require(\'emnapi\').sources.map(x => JSON.stringify(path.relative(process.cwd(), x))).join(\' \')")'
|
'<!@(node -p "require(\'emnapi\').sources.map(x => JSON.stringify(path.relative(process.cwd(), x))).join(\' \')")'
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
|
static void* readPNGComment(VipsImage *image, const char *field, GValue *value, void *p);
|
||||||
|
|
||||||
class MetadataWorker : public Napi::AsyncWorker {
|
class MetadataWorker : public Napi::AsyncWorker {
|
||||||
public:
|
public:
|
||||||
MetadataWorker(Napi::Function callback, MetadataBaton *baton, Napi::Function debuglog) :
|
MetadataWorker(Napi::Function callback, MetadataBaton *baton, Napi::Function debuglog) :
|
||||||
@@ -131,6 +133,8 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
memcpy(baton->tifftagPhotoshop, tifftagPhotoshop, tifftagPhotoshopLength);
|
memcpy(baton->tifftagPhotoshop, tifftagPhotoshop, tifftagPhotoshopLength);
|
||||||
baton->tifftagPhotoshopLength = tifftagPhotoshopLength;
|
baton->tifftagPhotoshopLength = tifftagPhotoshopLength;
|
||||||
}
|
}
|
||||||
|
// PNG comments
|
||||||
|
vips_image_map(image.get_image(), readPNGComment, &baton->comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
@@ -246,6 +250,17 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
Napi::Buffer<char>::NewOrCopy(env, baton->tifftagPhotoshop,
|
Napi::Buffer<char>::NewOrCopy(env, baton->tifftagPhotoshop,
|
||||||
baton->tifftagPhotoshopLength, sharp::FreeCallback));
|
baton->tifftagPhotoshopLength, sharp::FreeCallback));
|
||||||
}
|
}
|
||||||
|
if (baton->comments.size() > 0) {
|
||||||
|
int i = 0;
|
||||||
|
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
|
||||||
|
for (auto &c : baton->comments) {
|
||||||
|
Napi::Object comment = Napi::Object::New(env);
|
||||||
|
comment.Set("keyword", c.first);
|
||||||
|
comment.Set("text", c.second);
|
||||||
|
comments.Set(i++, comment);
|
||||||
|
}
|
||||||
|
info.Set("comments", comments);
|
||||||
|
}
|
||||||
Callback().Call(Receiver().Value(), { env.Null(), info });
|
Callback().Call(Receiver().Value(), { env.Null(), info });
|
||||||
} else {
|
} else {
|
||||||
Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
||||||
@@ -285,3 +300,21 @@ Napi::Value metadata(const Napi::CallbackInfo& info) {
|
|||||||
|
|
||||||
return info.Env().Undefined();
|
return info.Env().Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *PNG_COMMENT_START = "png-comment-";
|
||||||
|
const int PNG_COMMENT_START_LEN = strlen(PNG_COMMENT_START);
|
||||||
|
|
||||||
|
static void* readPNGComment(VipsImage *image, const char *field, GValue *value, void *p) {
|
||||||
|
MetadataComments *comments = static_cast<MetadataComments *>(p);
|
||||||
|
|
||||||
|
if (vips_isprefix(PNG_COMMENT_START, field)) {
|
||||||
|
const char *keyword = strchr(field + PNG_COMMENT_START_LEN, '-');
|
||||||
|
const char *str;
|
||||||
|
if (keyword != NULL && !vips_image_get_string(image, field, &str)) {
|
||||||
|
keyword++; // Skip the hyphen
|
||||||
|
comments->push_back(std::make_pair(keyword, str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "./common.h"
|
#include "./common.h"
|
||||||
|
|
||||||
|
typedef std::vector<std::pair<std::string, std::string>> MetadataComments;
|
||||||
|
|
||||||
struct MetadataBaton {
|
struct MetadataBaton {
|
||||||
// Input
|
// Input
|
||||||
sharp::InputDescriptor *input;
|
sharp::InputDescriptor *input;
|
||||||
@@ -47,6 +49,7 @@ struct MetadataBaton {
|
|||||||
size_t xmpLength;
|
size_t xmpLength;
|
||||||
char *tifftagPhotoshop;
|
char *tifftagPhotoshop;
|
||||||
size_t tifftagPhotoshopLength;
|
size_t tifftagPhotoshopLength;
|
||||||
|
MetadataComments comments;
|
||||||
std::string err;
|
std::string err;
|
||||||
|
|
||||||
MetadataBaton():
|
MetadataBaton():
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
||||||
*/
|
*/
|
||||||
VImage Blur(VImage image, double const sigma) {
|
VImage Blur(VImage image, double const sigma, VipsPrecision precision, double const minAmpl) {
|
||||||
if (sigma == -1.0) {
|
if (sigma == -1.0) {
|
||||||
// Fast, mild blur - averages neighbouring pixels
|
// Fast, mild blur - averages neighbouring pixels
|
||||||
VImage blur = VImage::new_matrixv(3, 3,
|
VImage blur = VImage::new_matrixv(3, 3,
|
||||||
@@ -155,7 +155,9 @@ namespace sharp {
|
|||||||
return image.conv(blur);
|
return image.conv(blur);
|
||||||
} else {
|
} else {
|
||||||
// Slower, accurate Gaussian blur
|
// Slower, accurate Gaussian blur
|
||||||
return StaySequential(image, VIPS_ACCESS_SEQUENTIAL).gaussblur(sigma);
|
return StaySequential(image).gaussblur(sigma, VImage::option()
|
||||||
|
->set("precision", precision)
|
||||||
|
->set("min_ampl", minAmpl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,10 +166,10 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Convolve(VImage image, int const width, int const height,
|
VImage Convolve(VImage image, int const width, int const height,
|
||||||
double const scale, double const offset,
|
double const scale, double const offset,
|
||||||
std::unique_ptr<double[]> const &kernel_v
|
std::vector<double> const &kernel_v
|
||||||
) {
|
) {
|
||||||
VImage kernel = VImage::new_from_memory(
|
VImage kernel = VImage::new_from_memory(
|
||||||
kernel_v.get(),
|
static_cast<void*>(const_cast<double*>(kernel_v.data())),
|
||||||
width * height * sizeof(double),
|
width * height * sizeof(double),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
@@ -183,19 +185,21 @@ namespace sharp {
|
|||||||
* Recomb with a Matrix of the given bands/channel size.
|
* Recomb with a Matrix of the given bands/channel size.
|
||||||
* Eg. RGB will be a 3x3 matrix.
|
* Eg. RGB will be a 3x3 matrix.
|
||||||
*/
|
*/
|
||||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
VImage Recomb(VImage image, std::vector<double> const& matrix) {
|
||||||
double *m = matrix.get();
|
double* m = const_cast<double*>(matrix.data());
|
||||||
image = image.colourspace(VIPS_INTERPRETATION_sRGB);
|
image = image.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
return image
|
if (matrix.size() == 9) {
|
||||||
.recomb(image.bands() == 3
|
return image
|
||||||
? VImage::new_from_memory(
|
.recomb(image.bands() == 3
|
||||||
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
? VImage::new_matrix(3, 3, m, 9)
|
||||||
)
|
: VImage::new_matrixv(4, 4,
|
||||||
: VImage::new_matrixv(4, 4,
|
m[0], m[1], m[2], 0.0,
|
||||||
m[0], m[1], m[2], 0.0,
|
m[3], m[4], m[5], 0.0,
|
||||||
m[3], m[4], m[5], 0.0,
|
m[6], m[7], m[8], 0.0,
|
||||||
m[6], m[7], m[8], 0.0,
|
0.0, 0.0, 0.0, 1.0));
|
||||||
0.0, 0.0, 0.0, 1.0));
|
} else {
|
||||||
|
return image.recomb(VImage::new_matrix(4, 4, m, 16));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VImage Modulate(VImage image, double const brightness, double const saturation,
|
VImage Modulate(VImage image, double const brightness, double const saturation,
|
||||||
@@ -386,7 +390,7 @@ namespace sharp {
|
|||||||
pages.reserve(nPages);
|
pages.reserve(nPages);
|
||||||
|
|
||||||
// Split the image into cropped frames
|
// Split the image into cropped frames
|
||||||
image = StaySequential(image, VIPS_ACCESS_SEQUENTIAL);
|
image = StaySequential(image);
|
||||||
for (int i = 0; i < nPages; i++) {
|
for (int i = 0; i < nPages; i++) {
|
||||||
pages.push_back(
|
pages.push_back(
|
||||||
image.extract_area(left, *pageHeight * i + top, width, height));
|
image.extract_area(left, *pageHeight * i + top, width, height));
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
||||||
*/
|
*/
|
||||||
VImage Blur(VImage image, double const sigma);
|
VImage Blur(VImage image, double const sigma, VipsPrecision precision, double const minAmpl);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convolution with a kernel.
|
* Convolution with a kernel.
|
||||||
*/
|
*/
|
||||||
VImage Convolve(VImage image, int const width, int const height,
|
VImage Convolve(VImage image, int const width, int const height,
|
||||||
double const scale, double const offset, std::unique_ptr<double[]> const &kernel_v);
|
double const scale, double const offset, std::vector<double> const &kernel_v);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
||||||
@@ -95,7 +95,7 @@ namespace sharp {
|
|||||||
* Recomb with a Matrix of the given bands/channel size.
|
* Recomb with a Matrix of the given bands/channel size.
|
||||||
* Eg. RGB will be a 3x3 matrix.
|
* Eg. RGB will be a 3x3 matrix.
|
||||||
*/
|
*/
|
||||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix);
|
VImage Recomb(VImage image, std::vector<double> const &matrix);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Modulate brightness, saturation, hue and lightness
|
* Modulate brightness, saturation, hue and lightness
|
||||||
|
|||||||
115
src/pipeline.cc
@@ -70,8 +70,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Calculate angle of rotation
|
// Calculate angle of rotation
|
||||||
VipsAngle rotation = VIPS_ANGLE_D0;
|
VipsAngle rotation = VIPS_ANGLE_D0;
|
||||||
VipsAngle autoRotation = VIPS_ANGLE_D0;
|
VipsAngle autoRotation = VIPS_ANGLE_D0;
|
||||||
bool autoFlip = FALSE;
|
bool autoFlip = false;
|
||||||
bool autoFlop = FALSE;
|
bool autoFlop = false;
|
||||||
|
|
||||||
if (baton->useExifOrientation) {
|
if (baton->useExifOrientation) {
|
||||||
// Rotate and flip image according to Exif orientation
|
// Rotate and flip image according to Exif orientation
|
||||||
@@ -88,7 +88,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
baton->rotationAngle != 0.0);
|
baton->rotationAngle != 0.0);
|
||||||
|
|
||||||
if (shouldRotateBefore) {
|
if (shouldRotateBefore) {
|
||||||
image = sharp::StaySequential(image, access,
|
image = sharp::StaySequential(image,
|
||||||
rotation != VIPS_ANGLE_D0 ||
|
rotation != VIPS_ANGLE_D0 ||
|
||||||
autoRotation != VIPS_ANGLE_D0 ||
|
autoRotation != VIPS_ANGLE_D0 ||
|
||||||
autoFlip ||
|
autoFlip ||
|
||||||
@@ -104,17 +104,17 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
if (autoFlip) {
|
if (autoFlip) {
|
||||||
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
||||||
autoFlip = FALSE;
|
autoFlip = false;
|
||||||
} else if (baton->flip) {
|
} else if (baton->flip) {
|
||||||
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
||||||
baton->flip = FALSE;
|
baton->flip = false;
|
||||||
}
|
}
|
||||||
if (autoFlop) {
|
if (autoFlop) {
|
||||||
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
||||||
autoFlop = FALSE;
|
autoFlop = false;
|
||||||
} else if (baton->flop) {
|
} else if (baton->flop) {
|
||||||
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
||||||
baton->flop = FALSE;
|
baton->flop = false;
|
||||||
}
|
}
|
||||||
if (rotation != VIPS_ANGLE_D0) {
|
if (rotation != VIPS_ANGLE_D0) {
|
||||||
if (rotation != VIPS_ANGLE_D180) {
|
if (rotation != VIPS_ANGLE_D180) {
|
||||||
@@ -126,7 +126,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (baton->rotationAngle != 0.0) {
|
if (baton->rotationAngle != 0.0) {
|
||||||
MultiPageUnsupported(nPages, "Rotate");
|
MultiPageUnsupported(nPages, "Rotate");
|
||||||
std::vector<double> background;
|
std::vector<double> background;
|
||||||
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, FALSE);
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, false);
|
||||||
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background)).copy_memory();
|
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background)).copy_memory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Trim
|
// Trim
|
||||||
if (baton->trimThreshold >= 0.0) {
|
if (baton->trimThreshold >= 0.0) {
|
||||||
MultiPageUnsupported(nPages, "Trim");
|
MultiPageUnsupported(nPages, "Trim");
|
||||||
image = sharp::StaySequential(image, access);
|
image = sharp::StaySequential(image);
|
||||||
image = sharp::Trim(image, baton->trimBackground, baton->trimThreshold, baton->trimLineArt);
|
image = sharp::Trim(image, baton->trimBackground, baton->trimThreshold, baton->trimLineArt);
|
||||||
baton->trimOffsetLeft = image.xoffset();
|
baton->trimOffsetLeft = image.xoffset();
|
||||||
baton->trimOffsetTop = image.yoffset();
|
baton->trimOffsetTop = image.yoffset();
|
||||||
@@ -325,6 +325,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->withIccProfile.empty()) {
|
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->withIccProfile.empty()) {
|
||||||
// Cache input profile for use with output
|
// Cache input profile for use with output
|
||||||
inputProfile = sharp::GetProfile(image);
|
inputProfile = sharp::GetProfile(image);
|
||||||
|
baton->input->ignoreIcc = true;
|
||||||
}
|
}
|
||||||
char const *processingProfile = image.interpretation() == VIPS_INTERPRETATION_RGB16 ? "p3" : "srgb";
|
char const *processingProfile = image.interpretation() == VIPS_INTERPRETATION_RGB16 ? "p3" : "srgb";
|
||||||
if (
|
if (
|
||||||
@@ -337,7 +338,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Convert to sRGB/P3 using embedded profile
|
// Convert to sRGB/P3 using embedded profile
|
||||||
try {
|
try {
|
||||||
image = image.icc_transform(processingProfile, VImage::option()
|
image = image.icc_transform(processingProfile, VImage::option()
|
||||||
->set("embedded", TRUE)
|
->set("embedded", true)
|
||||||
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
@@ -357,11 +358,6 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = sharp::Flatten(image, baton->flattenBackground);
|
image = sharp::Flatten(image, baton->flattenBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negate the colours in the image
|
|
||||||
if (baton->negate) {
|
|
||||||
image = sharp::Negate(image, baton->negateAlpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gamma encoding (darken)
|
// Gamma encoding (darken)
|
||||||
if (baton->gamma >= 1 && baton->gamma <= 3) {
|
if (baton->gamma >= 1 && baton->gamma <= 3) {
|
||||||
image = sharp::Gamma(image, 1.0 / baton->gamma);
|
image = sharp::Gamma(image, 1.0 / baton->gamma);
|
||||||
@@ -397,7 +393,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
->set("kernel", baton->kernel));
|
->set("kernel", baton->kernel));
|
||||||
}
|
}
|
||||||
|
|
||||||
image = sharp::StaySequential(image, access,
|
image = sharp::StaySequential(image,
|
||||||
autoRotation != VIPS_ANGLE_D0 ||
|
autoRotation != VIPS_ANGLE_D0 ||
|
||||||
baton->flip ||
|
baton->flip ||
|
||||||
autoFlip ||
|
autoFlip ||
|
||||||
@@ -500,7 +496,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
// Attention-based or Entropy-based crop
|
// Attention-based or Entropy-based crop
|
||||||
MultiPageUnsupported(nPages, "Resize strategy");
|
MultiPageUnsupported(nPages, "Resize strategy");
|
||||||
image = sharp::StaySequential(image, access);
|
image = sharp::StaySequential(image);
|
||||||
image = image.smartcrop(baton->width, baton->height, VImage::option()
|
image = image.smartcrop(baton->width, baton->height, VImage::option()
|
||||||
->set("interesting", baton->position == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION)
|
->set("interesting", baton->position == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION)
|
||||||
->set("premultiplied", shouldPremultiplyAlpha)
|
->set("premultiplied", shouldPremultiplyAlpha)
|
||||||
@@ -519,7 +515,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Rotate post-extract non-90 angle
|
// Rotate post-extract non-90 angle
|
||||||
if (!baton->rotateBeforePreExtract && baton->rotationAngle != 0.0) {
|
if (!baton->rotateBeforePreExtract && baton->rotationAngle != 0.0) {
|
||||||
MultiPageUnsupported(nPages, "Rotate");
|
MultiPageUnsupported(nPages, "Rotate");
|
||||||
image = sharp::StaySequential(image, access);
|
image = sharp::StaySequential(image);
|
||||||
std::vector<double> background;
|
std::vector<double> background;
|
||||||
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, shouldPremultiplyAlpha);
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, shouldPremultiplyAlpha);
|
||||||
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background));
|
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background));
|
||||||
@@ -543,7 +539,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Affine transform
|
// Affine transform
|
||||||
if (!baton->affineMatrix.empty()) {
|
if (!baton->affineMatrix.empty()) {
|
||||||
MultiPageUnsupported(nPages, "Affine");
|
MultiPageUnsupported(nPages, "Affine");
|
||||||
image = sharp::StaySequential(image, access);
|
image = sharp::StaySequential(image);
|
||||||
std::vector<double> background;
|
std::vector<double> background;
|
||||||
std::tie(image, background) = sharp::ApplyAlpha(image, baton->affineBackground, shouldPremultiplyAlpha);
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->affineBackground, shouldPremultiplyAlpha);
|
||||||
vips::VInterpolate interp = vips::VInterpolate::new_from_name(
|
vips::VInterpolate interp = vips::VInterpolate::new_from_name(
|
||||||
@@ -566,6 +562,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::vector<double> background;
|
std::vector<double> background;
|
||||||
std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
|
||||||
|
|
||||||
|
image = sharp::StaySequential(image, nPages > 1);
|
||||||
image = nPages > 1
|
image = nPages > 1
|
||||||
? sharp::EmbedMultiPage(image,
|
? sharp::EmbedMultiPage(image,
|
||||||
baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
||||||
@@ -574,7 +571,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
VImage::option()->set("extend", baton->extendWith)->set("background", background));
|
VImage::option()->set("extend", baton->extendWith)->set("background", background));
|
||||||
} else {
|
} else {
|
||||||
std::vector<double> ignoredBackground(1);
|
std::vector<double> ignoredBackground(1);
|
||||||
image = sharp::StaySequential(image, baton->input->access);
|
image = sharp::StaySequential(image);
|
||||||
image = nPages > 1
|
image = nPages > 1
|
||||||
? sharp::EmbedMultiPage(image,
|
? sharp::EmbedMultiPage(image,
|
||||||
baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
||||||
@@ -596,7 +593,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
// Blur
|
// Blur
|
||||||
if (shouldBlur) {
|
if (shouldBlur) {
|
||||||
image = sharp::Blur(image, baton->blurSigma);
|
image = sharp::Blur(image, baton->blurSigma, baton->precision, baton->minAmpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unflatten the image
|
// Unflatten the image
|
||||||
@@ -613,7 +610,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recomb
|
// Recomb
|
||||||
if (baton->recombMatrix != NULL) {
|
if (!baton->recombMatrix.empty()) {
|
||||||
image = sharp::Recomb(image, baton->recombMatrix);
|
image = sharp::Recomb(image, baton->recombMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,7 +667,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (across != 0 || down != 0) {
|
if (across != 0 || down != 0) {
|
||||||
int left;
|
int left;
|
||||||
int top;
|
int top;
|
||||||
compositeImage = sharp::StaySequential(compositeImage, access).replicate(across, down);
|
compositeImage = sharp::StaySequential(compositeImage).replicate(across, down);
|
||||||
if (composite->hasOffset) {
|
if (composite->hasOffset) {
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
std::tie(left, top) = sharp::CalculateCrop(
|
||||||
compositeImage.width(), compositeImage.height(), image.width(), image.height(),
|
compositeImage.width(), compositeImage.height(), image.width(), image.height(),
|
||||||
@@ -728,13 +725,13 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
// Apply normalisation - stretch luminance to cover full dynamic range
|
// Apply normalisation - stretch luminance to cover full dynamic range
|
||||||
if (baton->normalise) {
|
if (baton->normalise) {
|
||||||
image = sharp::StaySequential(image, access);
|
image = sharp::StaySequential(image);
|
||||||
image = sharp::Normalise(image, baton->normaliseLower, baton->normaliseUpper);
|
image = sharp::Normalise(image, baton->normaliseLower, baton->normaliseUpper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply contrast limiting adaptive histogram equalization (CLAHE)
|
// Apply contrast limiting adaptive histogram equalization (CLAHE)
|
||||||
if (baton->claheWidth != 0 && baton->claheHeight != 0) {
|
if (baton->claheWidth != 0 && baton->claheHeight != 0) {
|
||||||
image = sharp::StaySequential(image, access);
|
image = sharp::StaySequential(image);
|
||||||
image = sharp::Clahe(image, baton->claheWidth, baton->claheHeight, baton->claheMaxSlope);
|
image = sharp::Clahe(image, baton->claheWidth, baton->claheHeight, baton->claheMaxSlope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,7 +777,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->colourspacePipeline != VIPS_INTERPRETATION_CMYK &&
|
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->colourspacePipeline != VIPS_INTERPRETATION_CMYK &&
|
||||||
baton->withIccProfile.empty() && sharp::HasProfile(image)) {
|
baton->withIccProfile.empty() && sharp::HasProfile(image)) {
|
||||||
image = image.icc_transform(processingProfile, VImage::option()
|
image = image.icc_transform(processingProfile, VImage::option()
|
||||||
->set("embedded", TRUE)
|
->set("embedded", true)
|
||||||
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
}
|
}
|
||||||
@@ -811,7 +808,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
try {
|
try {
|
||||||
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
|
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
|
||||||
->set("input_profile", processingProfile)
|
->set("input_profile", processingProfile)
|
||||||
->set("embedded", TRUE)
|
->set("embedded", true)
|
||||||
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
@@ -820,6 +817,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Negate the colours in the image
|
||||||
|
if (baton->negate) {
|
||||||
|
image = sharp::Negate(image, baton->negateAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
// Override EXIF Orientation tag
|
// Override EXIF Orientation tag
|
||||||
if (baton->withMetadataOrientation != -1) {
|
if (baton->withMetadataOrientation != -1) {
|
||||||
image = sharp::SetExifOrientation(image, baton->withMetadataOrientation);
|
image = sharp::SetExifOrientation(image, baton->withMetadataOrientation);
|
||||||
@@ -847,6 +850,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = sharp::SetAnimationProperties(
|
image = sharp::SetAnimationProperties(
|
||||||
image, nPages, targetPageHeight, baton->delay, baton->loop);
|
image, nPages, targetPageHeight, baton->delay, baton->loop);
|
||||||
|
|
||||||
|
if (image.get_typeof(VIPS_META_PAGE_HEIGHT) == G_TYPE_INT) {
|
||||||
|
baton->pageHeightOut = image.get_int(VIPS_META_PAGE_HEIGHT);
|
||||||
|
baton->pagesOut = image.get_int(VIPS_META_N_PAGES);
|
||||||
|
}
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
sharp::SetTimeout(image, baton->timeoutSeconds);
|
sharp::SetTimeout(image, baton->timeoutSeconds);
|
||||||
if (baton->fileOut.empty()) {
|
if (baton->fileOut.empty()) {
|
||||||
@@ -1004,7 +1012,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (!sharp::HasAlpha(image)) {
|
if (!sharp::HasAlpha(image)) {
|
||||||
baton->tileBackground.pop_back();
|
baton->tileBackground.pop_back();
|
||||||
}
|
}
|
||||||
image = sharp::StaySequential(image, access, baton->tileAngle != 0);
|
image = sharp::StaySequential(image, baton->tileAngle != 0);
|
||||||
vips::VOption *options = BuildOptionsDZ(baton);
|
vips::VOption *options = BuildOptionsDZ(baton);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.dzsave_buffer(options));
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.dzsave_buffer(options));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
@@ -1206,7 +1214,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (!sharp::HasAlpha(image)) {
|
if (!sharp::HasAlpha(image)) {
|
||||||
baton->tileBackground.pop_back();
|
baton->tileBackground.pop_back();
|
||||||
}
|
}
|
||||||
image = sharp::StaySequential(image, access, baton->tileAngle != 0);
|
image = sharp::StaySequential(image, baton->tileAngle != 0);
|
||||||
vips::VOption *options = BuildOptionsDZ(baton);
|
vips::VOption *options = BuildOptionsDZ(baton);
|
||||||
image.dzsave(const_cast<char*>(baton->fileOut.data()), options);
|
image.dzsave(const_cast<char*>(baton->fileOut.data()), options);
|
||||||
baton->formatOut = "dz";
|
baton->formatOut = "dz";
|
||||||
@@ -1282,6 +1290,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (baton->input->textAutofitDpi) {
|
if (baton->input->textAutofitDpi) {
|
||||||
info.Set("textAutofitDpi", static_cast<uint32_t>(baton->input->textAutofitDpi));
|
info.Set("textAutofitDpi", static_cast<uint32_t>(baton->input->textAutofitDpi));
|
||||||
}
|
}
|
||||||
|
if (baton->pageHeightOut) {
|
||||||
|
info.Set("pageHeight", static_cast<int32_t>(baton->pageHeightOut));
|
||||||
|
info.Set("pages", static_cast<int32_t>(baton->pagesOut));
|
||||||
|
}
|
||||||
|
|
||||||
if (baton->bufferOutLength > 0) {
|
if (baton->bufferOutLength > 0) {
|
||||||
// Add buffer size to info
|
// Add buffer size to info
|
||||||
@@ -1338,16 +1350,16 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::tuple<VipsAngle, bool, bool>
|
std::tuple<VipsAngle, bool, bool>
|
||||||
CalculateExifRotationAndFlip(int const exifOrientation) {
|
CalculateExifRotationAndFlip(int const exifOrientation) {
|
||||||
VipsAngle rotate = VIPS_ANGLE_D0;
|
VipsAngle rotate = VIPS_ANGLE_D0;
|
||||||
bool flip = FALSE;
|
bool flip = false;
|
||||||
bool flop = FALSE;
|
bool flop = false;
|
||||||
switch (exifOrientation) {
|
switch (exifOrientation) {
|
||||||
case 6: rotate = VIPS_ANGLE_D90; break;
|
case 6: rotate = VIPS_ANGLE_D90; break;
|
||||||
case 3: rotate = VIPS_ANGLE_D180; break;
|
case 3: rotate = VIPS_ANGLE_D180; break;
|
||||||
case 8: rotate = VIPS_ANGLE_D270; break;
|
case 8: rotate = VIPS_ANGLE_D270; break;
|
||||||
case 2: flop = TRUE; break; // flop 1
|
case 2: flop = true; break; // flop 1
|
||||||
case 7: flip = TRUE; rotate = VIPS_ANGLE_D90; break; // flip 6
|
case 7: flip = true; rotate = VIPS_ANGLE_D90; break; // flip 6
|
||||||
case 4: flop = TRUE; rotate = VIPS_ANGLE_D180; break; // flop 3
|
case 4: flop = true; rotate = VIPS_ANGLE_D180; break; // flop 3
|
||||||
case 5: flip = TRUE; rotate = VIPS_ANGLE_D270; break; // flip 8
|
case 5: flip = true; rotate = VIPS_ANGLE_D270; break; // flip 8
|
||||||
}
|
}
|
||||||
return std::make_tuple(rotate, flip, flop);
|
return std::make_tuple(rotate, flip, flop);
|
||||||
}
|
}
|
||||||
@@ -1395,7 +1407,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::string suffix;
|
std::string suffix;
|
||||||
if (baton->tileFormat == "png") {
|
if (baton->tileFormat == "png") {
|
||||||
std::vector<std::pair<std::string, std::string>> options {
|
std::vector<std::pair<std::string, std::string>> options {
|
||||||
{"interlace", baton->pngProgressive ? "TRUE" : "FALSE"},
|
{"interlace", baton->pngProgressive ? "true" : "false"},
|
||||||
{"compression", std::to_string(baton->pngCompressionLevel)},
|
{"compression", std::to_string(baton->pngCompressionLevel)},
|
||||||
{"filter", baton->pngAdaptiveFiltering ? "all" : "none"}
|
{"filter", baton->pngAdaptiveFiltering ? "all" : "none"}
|
||||||
};
|
};
|
||||||
@@ -1404,25 +1416,25 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::vector<std::pair<std::string, std::string>> options {
|
std::vector<std::pair<std::string, std::string>> options {
|
||||||
{"Q", std::to_string(baton->webpQuality)},
|
{"Q", std::to_string(baton->webpQuality)},
|
||||||
{"alpha_q", std::to_string(baton->webpAlphaQuality)},
|
{"alpha_q", std::to_string(baton->webpAlphaQuality)},
|
||||||
{"lossless", baton->webpLossless ? "TRUE" : "FALSE"},
|
{"lossless", baton->webpLossless ? "true" : "false"},
|
||||||
{"near_lossless", baton->webpNearLossless ? "TRUE" : "FALSE"},
|
{"near_lossless", baton->webpNearLossless ? "true" : "false"},
|
||||||
{"smart_subsample", baton->webpSmartSubsample ? "TRUE" : "FALSE"},
|
{"smart_subsample", baton->webpSmartSubsample ? "true" : "false"},
|
||||||
{"preset", vips_enum_nick(VIPS_TYPE_FOREIGN_WEBP_PRESET, baton->webpPreset)},
|
{"preset", vips_enum_nick(VIPS_TYPE_FOREIGN_WEBP_PRESET, baton->webpPreset)},
|
||||||
{"min_size", baton->webpMinSize ? "TRUE" : "FALSE"},
|
{"min_size", baton->webpMinSize ? "true" : "false"},
|
||||||
{"mixed", baton->webpMixed ? "TRUE" : "FALSE"},
|
{"mixed", baton->webpMixed ? "true" : "false"},
|
||||||
{"effort", std::to_string(baton->webpEffort)}
|
{"effort", std::to_string(baton->webpEffort)}
|
||||||
};
|
};
|
||||||
suffix = AssembleSuffixString(".webp", options);
|
suffix = AssembleSuffixString(".webp", options);
|
||||||
} else {
|
} else {
|
||||||
std::vector<std::pair<std::string, std::string>> options {
|
std::vector<std::pair<std::string, std::string>> options {
|
||||||
{"Q", std::to_string(baton->jpegQuality)},
|
{"Q", std::to_string(baton->jpegQuality)},
|
||||||
{"interlace", baton->jpegProgressive ? "TRUE" : "FALSE"},
|
{"interlace", baton->jpegProgressive ? "true" : "false"},
|
||||||
{"subsample_mode", baton->jpegChromaSubsampling == "4:4:4" ? "off" : "on"},
|
{"subsample_mode", baton->jpegChromaSubsampling == "4:4:4" ? "off" : "on"},
|
||||||
{"trellis_quant", baton->jpegTrellisQuantisation ? "TRUE" : "FALSE"},
|
{"trellis_quant", baton->jpegTrellisQuantisation ? "true" : "false"},
|
||||||
{"quant_table", std::to_string(baton->jpegQuantisationTable)},
|
{"quant_table", std::to_string(baton->jpegQuantisationTable)},
|
||||||
{"overshoot_deringing", baton->jpegOvershootDeringing ? "TRUE": "FALSE"},
|
{"overshoot_deringing", baton->jpegOvershootDeringing ? "true": "false"},
|
||||||
{"optimize_scans", baton->jpegOptimiseScans ? "TRUE": "FALSE"},
|
{"optimize_scans", baton->jpegOptimiseScans ? "true": "false"},
|
||||||
{"optimize_coding", baton->jpegOptimiseCoding ? "TRUE": "FALSE"}
|
{"optimize_coding", baton->jpegOptimiseCoding ? "true": "false"}
|
||||||
};
|
};
|
||||||
std::string extname = baton->tileLayout == VIPS_FOREIGN_DZ_LAYOUT_DZ ? ".jpeg" : ".jpg";
|
std::string extname = baton->tileLayout == VIPS_FOREIGN_DZ_LAYOUT_DZ ? ".jpeg" : ".jpg";
|
||||||
suffix = AssembleSuffixString(extname, options);
|
suffix = AssembleSuffixString(extname, options);
|
||||||
@@ -1530,6 +1542,8 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->negate = sharp::AttrAsBool(options, "negate");
|
baton->negate = sharp::AttrAsBool(options, "negate");
|
||||||
baton->negateAlpha = sharp::AttrAsBool(options, "negateAlpha");
|
baton->negateAlpha = sharp::AttrAsBool(options, "negateAlpha");
|
||||||
baton->blurSigma = sharp::AttrAsDouble(options, "blurSigma");
|
baton->blurSigma = sharp::AttrAsDouble(options, "blurSigma");
|
||||||
|
baton->precision = sharp::AttrAsEnum<VipsPrecision>(options, "precision", VIPS_TYPE_PRECISION);
|
||||||
|
baton->minAmpl = sharp::AttrAsDouble(options, "minAmpl");
|
||||||
baton->brightness = sharp::AttrAsDouble(options, "brightness");
|
baton->brightness = sharp::AttrAsDouble(options, "brightness");
|
||||||
baton->saturation = sharp::AttrAsDouble(options, "saturation");
|
baton->saturation = sharp::AttrAsDouble(options, "saturation");
|
||||||
baton->hue = sharp::AttrAsInt32(options, "hue");
|
baton->hue = sharp::AttrAsInt32(options, "hue");
|
||||||
@@ -1595,17 +1609,18 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->convKernelScale = sharp::AttrAsDouble(kernel, "scale");
|
baton->convKernelScale = sharp::AttrAsDouble(kernel, "scale");
|
||||||
baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset");
|
baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset");
|
||||||
size_t const kernelSize = static_cast<size_t>(baton->convKernelWidth * baton->convKernelHeight);
|
size_t const kernelSize = static_cast<size_t>(baton->convKernelWidth * baton->convKernelHeight);
|
||||||
baton->convKernel = std::unique_ptr<double[]>(new double[kernelSize]);
|
baton->convKernel.resize(kernelSize);
|
||||||
Napi::Array kdata = kernel.Get("kernel").As<Napi::Array>();
|
Napi::Array kdata = kernel.Get("kernel").As<Napi::Array>();
|
||||||
for (unsigned int i = 0; i < kernelSize; i++) {
|
for (unsigned int i = 0; i < kernelSize; i++) {
|
||||||
baton->convKernel[i] = sharp::AttrAsDouble(kdata, i);
|
baton->convKernel[i] = sharp::AttrAsDouble(kdata, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.Has("recombMatrix")) {
|
if (options.Has("recombMatrix")) {
|
||||||
baton->recombMatrix = std::unique_ptr<double[]>(new double[9]);
|
|
||||||
Napi::Array recombMatrix = options.Get("recombMatrix").As<Napi::Array>();
|
Napi::Array recombMatrix = options.Get("recombMatrix").As<Napi::Array>();
|
||||||
for (unsigned int i = 0; i < 9; i++) {
|
unsigned int matrixElements = recombMatrix.Length();
|
||||||
baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
|
baton->recombMatrix.resize(matrixElements);
|
||||||
|
for (unsigned int i = 0; i < matrixElements; i++) {
|
||||||
|
baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
baton->colourspacePipeline = sharp::AttrAsEnum<VipsInterpretation>(
|
baton->colourspacePipeline = sharp::AttrAsEnum<VipsInterpretation>(
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ struct PipelineBaton {
|
|||||||
std::string fileOut;
|
std::string fileOut;
|
||||||
void *bufferOut;
|
void *bufferOut;
|
||||||
size_t bufferOutLength;
|
size_t bufferOutLength;
|
||||||
|
int pageHeightOut;
|
||||||
|
int pagesOut;
|
||||||
std::vector<Composite *> composite;
|
std::vector<Composite *> composite;
|
||||||
std::vector<sharp::InputDescriptor *> joinChannelIn;
|
std::vector<sharp::InputDescriptor *> joinChannelIn;
|
||||||
int topOffsetPre;
|
int topOffsetPre;
|
||||||
@@ -76,6 +78,8 @@ struct PipelineBaton {
|
|||||||
bool negate;
|
bool negate;
|
||||||
bool negateAlpha;
|
bool negateAlpha;
|
||||||
double blurSigma;
|
double blurSigma;
|
||||||
|
VipsPrecision precision;
|
||||||
|
double minAmpl;
|
||||||
double brightness;
|
double brightness;
|
||||||
double saturation;
|
double saturation;
|
||||||
int hue;
|
int hue;
|
||||||
@@ -195,7 +199,7 @@ struct PipelineBaton {
|
|||||||
std::unordered_map<std::string, std::string> withExif;
|
std::unordered_map<std::string, std::string> withExif;
|
||||||
bool withExifMerge;
|
bool withExifMerge;
|
||||||
int timeoutSeconds;
|
int timeoutSeconds;
|
||||||
std::unique_ptr<double[]> convKernel;
|
std::vector<double> convKernel;
|
||||||
int convKernelWidth;
|
int convKernelWidth;
|
||||||
int convKernelHeight;
|
int convKernelHeight;
|
||||||
double convKernelScale;
|
double convKernelScale;
|
||||||
@@ -221,11 +225,13 @@ struct PipelineBaton {
|
|||||||
VipsForeignDzDepth tileDepth;
|
VipsForeignDzDepth tileDepth;
|
||||||
std::string tileId;
|
std::string tileId;
|
||||||
std::string tileBasename;
|
std::string tileBasename;
|
||||||
std::unique_ptr<double[]> recombMatrix;
|
std::vector<double> recombMatrix;
|
||||||
|
|
||||||
PipelineBaton():
|
PipelineBaton():
|
||||||
input(nullptr),
|
input(nullptr),
|
||||||
bufferOutLength(0),
|
bufferOutLength(0),
|
||||||
|
pageHeightOut(0),
|
||||||
|
pagesOut(0),
|
||||||
topOffsetPre(-1),
|
topOffsetPre(-1),
|
||||||
topOffsetPost(-1),
|
topOffsetPost(-1),
|
||||||
channels(0),
|
channels(0),
|
||||||
|
|||||||
BIN
test/fixtures/XCMYK 2017.icc
vendored
Normal file
BIN
test/fixtures/d.png
vendored
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
test/fixtures/expected/colourspace.cmyk-to-cmyk-negated.tif
vendored
Normal file
BIN
test/fixtures/expected/d-opacity-30.png
vendored
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
test/fixtures/expected/flip-and-flop.jpg
vendored
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 16 KiB |
BIN
test/fixtures/expected/negate-trans.png
vendored
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 5.3 KiB |
BIN
test/fixtures/fogra-0-100-100-0.tif
vendored
Normal file
80
test/fixtures/index.js
vendored
@@ -14,29 +14,26 @@ const getPath = function (filename) {
|
|||||||
|
|
||||||
// Generates a 64-bit-as-binary-string image fingerprint
|
// Generates a 64-bit-as-binary-string image fingerprint
|
||||||
// Based on the dHash gradient method - see http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
// Based on the dHash gradient method - see http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
||||||
const fingerprint = function (image, callback) {
|
async function fingerprint (image) {
|
||||||
sharp(image)
|
return sharp(image)
|
||||||
.flatten('gray')
|
.flatten('gray')
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.normalise()
|
.normalise()
|
||||||
.resize(9, 8, { fit: sharp.fit.fill })
|
.resize(9, 8, { fit: sharp.fit.fill })
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer(function (err, data) {
|
.toBuffer()
|
||||||
if (err) {
|
.then(function (data) {
|
||||||
callback(err);
|
let fingerprint = '';
|
||||||
} else {
|
for (let col = 0; col < 8; col++) {
|
||||||
let fingerprint = '';
|
for (let row = 0; row < 8; row++) {
|
||||||
for (let col = 0; col < 8; col++) {
|
const left = data[(row * 8) + col];
|
||||||
for (let row = 0; row < 8; row++) {
|
const right = data[(row * 8) + col + 1];
|
||||||
const left = data[(row * 8) + col];
|
fingerprint = fingerprint + (left < right ? '1' : '0');
|
||||||
const right = data[(row * 8) + col + 1];
|
|
||||||
fingerprint = fingerprint + (left < right ? '1' : '0');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
callback(null, fingerprint);
|
|
||||||
}
|
}
|
||||||
|
return fingerprint;
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
@@ -102,6 +99,7 @@ module.exports = {
|
|||||||
inputPngTrimSpecificColour16bit: getPath('Flag_of_the_Netherlands-16bit.png'), // convert Flag_of_the_Netherlands.png -depth 16 Flag_of_the_Netherlands-16bit.png
|
inputPngTrimSpecificColour16bit: getPath('Flag_of_the_Netherlands-16bit.png'), // convert Flag_of_the_Netherlands.png -depth 16 Flag_of_the_Netherlands-16bit.png
|
||||||
inputPngTrimSpecificColourIncludeAlpha: getPath('Flag_of_the_Netherlands-alpha.png'), // convert Flag_of_the_Netherlands.png -alpha set -background none -channel A -evaluate multiply 0.5 +channel Flag_of_the_Netherlands-alpha.png
|
inputPngTrimSpecificColourIncludeAlpha: getPath('Flag_of_the_Netherlands-alpha.png'), // convert Flag_of_the_Netherlands.png -alpha set -background none -channel A -evaluate multiply 0.5 +channel Flag_of_the_Netherlands-alpha.png
|
||||||
inputPngUint32Limit: getPath('65536-uint32-limit.png'), // https://alexandre.alapetite.fr/doc-alex/large-image/
|
inputPngUint32Limit: getPath('65536-uint32-limit.png'), // https://alexandre.alapetite.fr/doc-alex/large-image/
|
||||||
|
inputPngWithProPhotoProfile: getPath('prophoto.png'),
|
||||||
|
|
||||||
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
||||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||||
@@ -114,6 +112,7 @@ module.exports = {
|
|||||||
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
||||||
inputTiff8BitDepth: getPath('8bit_depth.tiff'),
|
inputTiff8BitDepth: getPath('8bit_depth.tiff'),
|
||||||
inputTifftagPhotoshop: getPath('tifftag-photoshop.tiff'), // https://github.com/lovell/sharp/issues/1600
|
inputTifftagPhotoshop: getPath('tifftag-photoshop.tiff'), // https://github.com/lovell/sharp/issues/1600
|
||||||
|
inputTiffFogra: getPath('fogra-0-100-100-0.tif'), // https://github.com/lovell/sharp/issues/4045
|
||||||
|
|
||||||
inputJp2: getPath('relax.jp2'), // https://www.fnordware.com/j2k/relax.jp2
|
inputJp2: getPath('relax.jp2'), // https://www.fnordware.com/j2k/relax.jp2
|
||||||
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
||||||
@@ -138,6 +137,7 @@ module.exports = {
|
|||||||
|
|
||||||
testPattern: getPath('test-pattern.png'),
|
testPattern: getPath('test-pattern.png'),
|
||||||
|
|
||||||
|
inputPngWithTransparent: getPath('d.png'),
|
||||||
// Path for tests requiring human inspection
|
// Path for tests requiring human inspection
|
||||||
path: getPath,
|
path: getPath,
|
||||||
|
|
||||||
@@ -149,46 +149,44 @@ module.exports = {
|
|||||||
// Verify similarity of expected vs actual images via fingerprint
|
// Verify similarity of expected vs actual images via fingerprint
|
||||||
// Specify distance threshold using `options={threshold: 42}`, default
|
// Specify distance threshold using `options={threshold: 42}`, default
|
||||||
// `threshold` is 5;
|
// `threshold` is 5;
|
||||||
assertSimilar: function (expectedImage, actualImage, options, callback) {
|
assertSimilar: async function (expectedImage, actualImage, options, callback) {
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
if (typeof options === 'undefined' || options === null) {
|
||||||
if (typeof options === 'undefined' && options === null) {
|
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.threshold === null || typeof options.threshold === 'undefined') {
|
if (options.threshold === null || typeof options.threshold === 'undefined') {
|
||||||
options.threshold = 5; // ~7% threshold
|
options.threshold = 5; // ~7% threshold
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof options.threshold !== 'number') {
|
if (typeof options.threshold !== 'number') {
|
||||||
throw new TypeError('`options.threshold` must be a number');
|
throw new TypeError('`options.threshold` must be a number');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof callback !== 'function') {
|
try {
|
||||||
throw new TypeError('`callback` must be a function');
|
const [expectedFingerprint, actualFingerprint] = await Promise.all([
|
||||||
|
fingerprint(expectedImage),
|
||||||
|
fingerprint(actualImage)
|
||||||
|
]);
|
||||||
|
let distance = 0;
|
||||||
|
for (let i = 0; i < 64; i++) {
|
||||||
|
if (expectedFingerprint[i] !== actualFingerprint[i]) {
|
||||||
|
distance++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (distance > options.threshold) {
|
||||||
|
throw new Error(`Expected maximum similarity distance: ${options.threshold}. Actual: ${distance}.`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (callback) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
fingerprint(expectedImage, function (err, expectedFingerprint) {
|
|
||||||
if (err) return callback(err);
|
|
||||||
fingerprint(actualImage, function (err, actualFingerprint) {
|
|
||||||
if (err) return callback(err);
|
|
||||||
let distance = 0;
|
|
||||||
for (let i = 0; i < 64; i++) {
|
|
||||||
if (expectedFingerprint[i] !== actualFingerprint[i]) {
|
|
||||||
distance++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (distance > options.threshold) {
|
|
||||||
return callback(new Error('Expected maximum similarity distance: ' + options.threshold + '. Actual: ' + distance + '.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
assertMaxColourDistance: function (actualImagePath, expectedImagePath, acceptedDistance) {
|
assertMaxColourDistance: function (actualImagePath, expectedImagePath, acceptedDistance) {
|
||||||
|
|||||||
BIN
test/fixtures/prophoto.png
vendored
Normal file
|
After Width: | Height: | Size: 556 B |
@@ -59,6 +59,12 @@ sharp('input.jpg')
|
|||||||
|
|
||||||
sharp('input.jpg').resize({ width: 300 }).blur(false).blur(true).toFile('output.jpg');
|
sharp('input.jpg').resize({ width: 300 }).blur(false).blur(true).toFile('output.jpg');
|
||||||
|
|
||||||
|
sharp().blur();
|
||||||
|
sharp().blur(1);
|
||||||
|
sharp().blur({ sigma: 1 });
|
||||||
|
sharp().blur({ sigma: 1, precision: 'approximate' });
|
||||||
|
sharp().blur({ sigma: 1, minAmplitude: 0.8 });
|
||||||
|
|
||||||
sharp({
|
sharp({
|
||||||
create: {
|
create: {
|
||||||
width: 300,
|
width: 300,
|
||||||
@@ -295,6 +301,13 @@ sharp('input.gif')
|
|||||||
[0.2392, 0.4696, 0.0912],
|
[0.2392, 0.4696, 0.0912],
|
||||||
])
|
])
|
||||||
|
|
||||||
|
.recomb([
|
||||||
|
[1,0,0,0],
|
||||||
|
[0,1,0,0],
|
||||||
|
[0,0,1,0],
|
||||||
|
[0,0,0,1],
|
||||||
|
])
|
||||||
|
|
||||||
.modulate({ brightness: 2 })
|
.modulate({ brightness: 2 })
|
||||||
.modulate({ hue: 180 })
|
.modulate({ hue: 180 })
|
||||||
.modulate({ lightness: 10 })
|
.modulate({ lightness: 10 })
|
||||||
@@ -680,3 +693,24 @@ sharp(input)
|
|||||||
.keepIccProfile()
|
.keepIccProfile()
|
||||||
.withIccProfile('filename')
|
.withIccProfile('filename')
|
||||||
.withIccProfile('filename', { attach: false });
|
.withIccProfile('filename', { attach: false });
|
||||||
|
|
||||||
|
// Added missing types for OverlayOptions
|
||||||
|
// https://github.com/lovell/sharp/pull/4048
|
||||||
|
sharp(input).composite([
|
||||||
|
{
|
||||||
|
input: 'image.gif',
|
||||||
|
animated: true,
|
||||||
|
limitInputPixels: 536805378,
|
||||||
|
density: 144,
|
||||||
|
failOn: "warning"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
sharp(input).composite([
|
||||||
|
{
|
||||||
|
input: 'image.png',
|
||||||
|
animated: false,
|
||||||
|
limitInputPixels: 178935126,
|
||||||
|
density: 72,
|
||||||
|
failOn: "truncated"
|
||||||
|
}
|
||||||
|
])
|
||||||
@@ -35,6 +35,19 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('specific options.sigma 10', function (done) {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.blur({ sigma: 10 })
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('blur-10.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('specific radius 0.3', function (done) {
|
it('specific radius 0.3', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@@ -91,4 +104,54 @@ describe('Blur', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('invalid precision', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(fixtures.inputJpg).blur({ sigma: 1, precision: 'invalid' });
|
||||||
|
}, /Expected one of: integer, float, approximate for precision but received invalid of type string/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid minAmplitude', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(fixtures.inputJpg).blur({ sigma: 1, minAmplitude: 0 });
|
||||||
|
}, /Expected number between 0.001 and 1 for minAmplitude but received 0 of type number/);
|
||||||
|
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(fixtures.inputJpg).blur({ sigma: 1, minAmplitude: 1.01 });
|
||||||
|
}, /Expected number between 0.001 and 1 for minAmplitude but received 1.01 of type number/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('specific radius 10 and precision approximate', async () => {
|
||||||
|
const approximate = await sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.blur({ sigma: 10, precision: 'approximate' })
|
||||||
|
.toBuffer();
|
||||||
|
const integer = await sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.blur(10)
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.notDeepEqual(approximate, integer);
|
||||||
|
await fixtures.assertSimilar(fixtures.expected('blur-10.jpg'), approximate);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('specific radius 10 and minAmplitude 0.01', async () => {
|
||||||
|
const minAmplitudeLow = await sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.blur({ sigma: 10, minAmplitude: 0.01 })
|
||||||
|
.toBuffer();
|
||||||
|
const minAmplitudeDefault = await sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.blur(10)
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.notDeepEqual(minAmplitudeLow, minAmplitudeDefault);
|
||||||
|
await fixtures.assertSimilar(fixtures.expected('blur-10.jpg'), minAmplitudeLow);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('options.sigma is required if options object is passed', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(fixtures.inputJpg).blur({ precision: 'invalid' });
|
||||||
|
}, /Expected number between 0.3 and 1000 for options.sigma but received undefined of type undefined/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -106,6 +106,43 @@ describe('Colour space conversion', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('CMYK profile to CMYK profile conversion using perceptual intent', async () => {
|
||||||
|
const data = await sharp(fixtures.inputTiffFogra)
|
||||||
|
.resize(320, 240)
|
||||||
|
.toColourspace('cmyk')
|
||||||
|
.pipelineColourspace('cmyk')
|
||||||
|
.withIccProfile(fixtures.path('XCMYK 2017.icc'))
|
||||||
|
.raw()
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
const [c, m, y, k] = data;
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
{ c, m, y, k },
|
||||||
|
{ c: 1, m: 239, y: 227, k: 5 }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('CMYK profile to CMYK profile with negate', (done) => {
|
||||||
|
sharp(fixtures.inputTiffFogra)
|
||||||
|
.resize(320, 240)
|
||||||
|
.toColourspace('cmyk')
|
||||||
|
.pipelineColourspace('cmyk')
|
||||||
|
.withIccProfile(fixtures.path('XCMYK 2017.icc'))
|
||||||
|
.negate()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('tiff', info.format);
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
fixtures.assertSimilar(
|
||||||
|
fixtures.expected('colourspace.cmyk-to-cmyk-negated.tif'),
|
||||||
|
data,
|
||||||
|
{ threshold: 0 },
|
||||||
|
done
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', function (done) {
|
it('From sRGB with RGB16 pipeline, resize with gamma, to sRGB', function (done) {
|
||||||
sharp(fixtures.inputPngGradients)
|
sharp(fixtures.inputPngGradients)
|
||||||
.pipelineColourspace('rgb16')
|
.pipelineColourspace('rgb16')
|
||||||
|
|||||||
@@ -73,20 +73,6 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('extend top with mirroring uses ordered read', async () => {
|
|
||||||
const data = await sharp(fixtures.inputJpg)
|
|
||||||
.extend({
|
|
||||||
extendWith: 'mirror',
|
|
||||||
top: 1
|
|
||||||
})
|
|
||||||
.png({ compressionLevel: 0 })
|
|
||||||
.toBuffer();
|
|
||||||
|
|
||||||
const { width, height } = await sharp(data).metadata();
|
|
||||||
assert.strictEqual(2725, width);
|
|
||||||
assert.strictEqual(2226, height);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`extend sides unequally with RGBA (${extendWith})`, function (done) {
|
it(`extend sides unequally with RGBA (${extendWith})`, function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(120)
|
.resize(120)
|
||||||
@@ -127,6 +113,39 @@ describe('Extend', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('extend top with mirroring uses ordered read', async () => {
|
||||||
|
const data = await sharp(fixtures.inputJpg)
|
||||||
|
.extend({
|
||||||
|
extendWith: 'mirror',
|
||||||
|
top: 1
|
||||||
|
})
|
||||||
|
.png({ compressionLevel: 0 })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
const { width, height } = await sharp(data).metadata();
|
||||||
|
assert.strictEqual(2725, width);
|
||||||
|
assert.strictEqual(2226, height);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('multi-page extend uses ordered read', async () => {
|
||||||
|
const multiPageTiff = await sharp(fixtures.inputGifAnimated, { animated: true })
|
||||||
|
.resize({ width: 8, height: 48 })
|
||||||
|
.tiff()
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
const data = await sharp(multiPageTiff, { pages: -1 })
|
||||||
|
.extend({
|
||||||
|
background: 'red',
|
||||||
|
top: 1
|
||||||
|
})
|
||||||
|
.png({ compressionLevel: 0 })
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
const { width, height } = await sharp(data).metadata();
|
||||||
|
assert.strictEqual(8, width);
|
||||||
|
assert.strictEqual(1470, height);
|
||||||
|
});
|
||||||
|
|
||||||
it('missing parameter fails', function () {
|
it('missing parameter fails', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().extend();
|
sharp().extend();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ describe('GIF input', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Animated GIF first page to PNG', () =>
|
it('Animated GIF first page to non-animated GIF', () =>
|
||||||
sharp(fixtures.inputGifAnimated)
|
sharp(fixtures.inputGifAnimated)
|
||||||
.toBuffer({ resolveWithObject: true })
|
.toBuffer({ resolveWithObject: true })
|
||||||
.then(({ data, info }) => {
|
.then(({ data, info }) => {
|
||||||
@@ -49,10 +49,12 @@ describe('GIF input', () => {
|
|||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
|
assert.strictEqual(undefined, info.pages);
|
||||||
|
assert.strictEqual(undefined, info.pageHeight);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Animated GIF all pages to PNG "toilet roll"', () =>
|
it('Animated GIF round trip', () =>
|
||||||
sharp(fixtures.inputGifAnimated, { pages: -1 })
|
sharp(fixtures.inputGifAnimated, { pages: -1 })
|
||||||
.toBuffer({ resolveWithObject: true })
|
.toBuffer({ resolveWithObject: true })
|
||||||
.then(({ data, info }) => {
|
.then(({ data, info }) => {
|
||||||
@@ -62,6 +64,8 @@ describe('GIF input', () => {
|
|||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(2400, info.height);
|
assert.strictEqual(2400, info.height);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
|
assert.strictEqual(30, info.pages);
|
||||||
|
assert.strictEqual(80, info.pageHeight);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,23 @@ describe('libvips binaries', function () {
|
|||||||
|
|
||||||
delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
|
delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
|
||||||
});
|
});
|
||||||
|
it('useGlobalLibvips can be forced via an env var', function () {
|
||||||
|
process.env.SHARP_FORCE_GLOBAL_LIBVIPS = 1;
|
||||||
|
|
||||||
|
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||||
|
assert.strictEqual(true, useGlobalLibvips);
|
||||||
|
|
||||||
|
let logged = false;
|
||||||
|
const logger = function (message) {
|
||||||
|
assert.strictEqual(message, 'Detected SHARP_FORCE_GLOBAL_LIBVIPS, skipping search for globally-installed libvips');
|
||||||
|
logged = true;
|
||||||
|
};
|
||||||
|
const useGlobalLibvipsWithLogger = libvips.useGlobalLibvips(logger);
|
||||||
|
assert.strictEqual(true, useGlobalLibvipsWithLogger);
|
||||||
|
assert.strictEqual(true, logged);
|
||||||
|
|
||||||
|
delete process.env.SHARP_FORCE_GLOBAL_LIBVIPS;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Build time platform detection', () => {
|
describe('Build time platform detection', () => {
|
||||||
@@ -162,7 +179,7 @@ describe('libvips binaries', function () {
|
|||||||
process.env.npm_config_arch = 's390x';
|
process.env.npm_config_arch = 's390x';
|
||||||
process.env.npm_config_libc = '';
|
process.env.npm_config_libc = '';
|
||||||
const locatorHash = libvips.yarnLocator();
|
const locatorHash = libvips.yarnLocator();
|
||||||
assert.strictEqual(locatorHash, '45978c229d');
|
assert.strictEqual(locatorHash, 'c4ea54fdc1');
|
||||||
delete process.env.npm_config_platform;
|
delete process.env.npm_config_platform;
|
||||||
delete process.env.npm_config_arch;
|
delete process.env.npm_config_arch;
|
||||||
delete process.env.npm_config_libc;
|
delete process.env.npm_config_libc;
|
||||||
|
|||||||
@@ -154,6 +154,31 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('PNG with comment', function (done) {
|
||||||
|
sharp(fixtures.inputPngTestJoinChannel).metadata(function (err, metadata) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('png', metadata.format);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.size);
|
||||||
|
assert.strictEqual(320, metadata.width);
|
||||||
|
assert.strictEqual(240, metadata.height);
|
||||||
|
assert.strictEqual('b-w', metadata.space);
|
||||||
|
assert.strictEqual(1, metadata.channels);
|
||||||
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
|
assert.strictEqual(72, metadata.density);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.chromaSubsampling);
|
||||||
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
|
assert.strictEqual(false, metadata.hasAlpha);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.orientation);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.exif);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.icc);
|
||||||
|
assert.strictEqual(1, metadata.comments.length);
|
||||||
|
assert.strictEqual('Comment', metadata.comments[0].keyword);
|
||||||
|
assert.strictEqual('Created with GIMP', metadata.comments[0].text);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Transparent PNG', function (done) {
|
it('Transparent PNG', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -576,6 +601,17 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual(description, 'Generic RGB Profile');
|
assert.strictEqual(description, 'Generic RGB Profile');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keep existing ICC profile, avoid colour transform', async () => {
|
||||||
|
const [r, g, b] = await sharp(fixtures.inputPngWithProPhotoProfile)
|
||||||
|
.keepIccProfile()
|
||||||
|
.raw()
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
assert.strictEqual(r, 131);
|
||||||
|
assert.strictEqual(g, 141);
|
||||||
|
assert.strictEqual(b, 192);
|
||||||
|
});
|
||||||
|
|
||||||
it('keep existing CMYK ICC profile', async () => {
|
it('keep existing CMYK ICC profile', async () => {
|
||||||
const data = await sharp(fixtures.inputJpgWithCmykProfile)
|
const data = await sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
.pipelineColourspace('cmyk')
|
.pipelineColourspace('cmyk')
|
||||||
@@ -616,13 +652,13 @@ describe('Image metadata', function () {
|
|||||||
.png()
|
.png()
|
||||||
.withIccProfile(fixtures.path('invalid-illuminant.icc'));
|
.withIccProfile(fixtures.path('invalid-illuminant.icc'));
|
||||||
|
|
||||||
let warningEmitted = '';
|
const warningsEmitted = [];
|
||||||
img.on('warning', (warning) => {
|
img.on('warning', (warning) => {
|
||||||
warningEmitted = warning;
|
warningsEmitted.push(warning);
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await img.toBuffer();
|
const data = await img.toBuffer();
|
||||||
assert.strictEqual('Invalid profile', warningEmitted);
|
assert.strict(warningsEmitted.includes('Invalid profile'));
|
||||||
|
|
||||||
const metadata = await sharp(data).metadata();
|
const metadata = await sharp(data).metadata();
|
||||||
assert.strictEqual(3, metadata.channels);
|
assert.strictEqual(3, metadata.channels);
|
||||||
|
|||||||
@@ -121,6 +121,29 @@ describe('Recomb', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('applies opacity 30% to the image', function (done) {
|
||||||
|
const output = fixtures.path('output.recomb-opacity.png');
|
||||||
|
sharp(fixtures.inputPngWithTransparent)
|
||||||
|
.recomb([
|
||||||
|
[1, 0, 0, 0],
|
||||||
|
[0, 1, 0, 0],
|
||||||
|
[0, 0, 1, 0],
|
||||||
|
[0, 0, 0, 0.3]
|
||||||
|
])
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('png', info.format);
|
||||||
|
assert.strictEqual(48, info.width);
|
||||||
|
assert.strictEqual(48, info.height);
|
||||||
|
fixtures.assertMaxColourDistance(
|
||||||
|
output,
|
||||||
|
fixtures.expected('d-opacity-30.png'),
|
||||||
|
17
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('invalid matrix specification', function () {
|
describe('invalid matrix specification', function () {
|
||||||
it('missing', function () {
|
it('missing', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
|
|||||||
@@ -417,6 +417,7 @@ describe('Rotation', function () {
|
|||||||
it('Flip and flop', function (done) {
|
it('Flip and flop', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320)
|
.resize(320)
|
||||||
|
.flip()
|
||||||
.flop()
|
.flop()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
@@ -228,26 +228,34 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bad width input', function () {
|
it('invalid width', () => {
|
||||||
assert.throws(function () {
|
assert.throws(
|
||||||
sharp({
|
() => sharp({ text: { text: 'text', width: 'bad' } }),
|
||||||
text: {
|
/Expected positive integer for text\.width but received bad of type string/
|
||||||
text: 'text',
|
);
|
||||||
width: 'bad'
|
assert.throws(
|
||||||
}
|
() => sharp({ text: { text: 'text', width: 0.1 } }),
|
||||||
});
|
/Expected positive integer for text\.width but received 0.1 of type number/
|
||||||
});
|
);
|
||||||
|
assert.throws(
|
||||||
|
() => sharp({ text: { text: 'text', width: -1 } }),
|
||||||
|
/Expected positive integer for text\.width but received -1 of type number/
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bad height input', function () {
|
it('invalid height', () => {
|
||||||
assert.throws(function () {
|
assert.throws(
|
||||||
sharp({
|
() => sharp({ text: { text: 'text', height: 'bad' } }),
|
||||||
text: {
|
/Expected positive integer for text\.height but received bad of type string/
|
||||||
text: 'text',
|
);
|
||||||
height: 'bad'
|
assert.throws(
|
||||||
}
|
() => sharp({ text: { text: 'text', height: 0.1 } }),
|
||||||
});
|
/Expected positive integer for text\.height but received 0.1 of type number/
|
||||||
});
|
);
|
||||||
|
assert.throws(
|
||||||
|
() => sharp({ text: { text: 'text', height: -1 } }),
|
||||||
|
/Expected positive integer for text\.height but received -1 of type number/
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bad align input', function () {
|
it('bad align input', function () {
|
||||||
@@ -272,15 +280,19 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bad dpi input', function () {
|
it('invalid dpi', () => {
|
||||||
assert.throws(function () {
|
assert.throws(
|
||||||
sharp({
|
() => sharp({ text: { text: 'text', dpi: 'bad' } }),
|
||||||
text: {
|
/Expected integer between 1 and 1000000 for text\.dpi but received bad of type string/
|
||||||
text: 'text',
|
);
|
||||||
dpi: -10
|
assert.throws(
|
||||||
}
|
() => sharp({ text: { text: 'text', dpi: 0.1 } }),
|
||||||
});
|
/Expected integer between 1 and 1000000 for text\.dpi but received 0.1 of type number/
|
||||||
});
|
);
|
||||||
|
assert.throws(
|
||||||
|
() => sharp({ text: { text: 'text', dpi: -1 } }),
|
||||||
|
/Expected integer between 1 and 1000000 for text\.dpi but received -1 of type number/
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bad rgba input', function () {
|
it('bad rgba input', function () {
|
||||||
@@ -294,15 +306,19 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('bad spacing input', function () {
|
it('invalid spacing', () => {
|
||||||
assert.throws(function () {
|
assert.throws(
|
||||||
sharp({
|
() => sharp({ text: { text: 'text', spacing: 'bad' } }),
|
||||||
text: {
|
/Expected integer between -1000000 and 1000000 for text\.spacing but received bad of type string/
|
||||||
text: 'text',
|
);
|
||||||
spacing: 'number expected'
|
assert.throws(
|
||||||
}
|
() => sharp({ text: { text: 'text', spacing: 0.1 } }),
|
||||||
});
|
/Expected integer between -1000000 and 1000000 for text\.spacing but received 0.1 of type number/
|
||||||
});
|
);
|
||||||
|
assert.throws(
|
||||||
|
() => sharp({ text: { text: 'text', spacing: -1000001 } }),
|
||||||
|
/Expected integer between -1000000 and 1000000 for text\.spacing but received -1000001 of type number/
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only height or dpi not both', function () {
|
it('only height or dpi not both', function () {
|
||||||
|
|||||||