Compare commits
267 Commits
v0.33.0-al
...
v0.34.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cae1abe8f | ||
|
|
66ffc48707 | ||
|
|
3c7dbb8fba | ||
|
|
a9e191328f | ||
|
|
7323dbee98 | ||
|
|
d7a771ca7a | ||
|
|
7d0585fad1 | ||
|
|
ddc1eb8c4c | ||
|
|
c26e67cc5b | ||
|
|
a00ee26d17 | ||
|
|
6dfb60cda2 | ||
|
|
dbb7606129 | ||
|
|
031c808aa5 | ||
|
|
03e1b19764 | ||
|
|
3e41f8b65e | ||
|
|
3fd818c4b5 | ||
|
|
d419aba76d | ||
|
|
3fb1091114 | ||
|
|
2035492fd9 | ||
|
|
5ee83d13e2 | ||
|
|
0d04e9dba3 | ||
|
|
f3a4f060c6 | ||
|
|
3c177af594 | ||
|
|
9d40a64120 | ||
|
|
fda06a62b0 | ||
|
|
75a135eabe | ||
|
|
c9850afe67 | ||
|
|
a619f29313 | ||
|
|
9b88547f12 | ||
|
|
8e3ec0fc61 | ||
|
|
edad89c531 | ||
|
|
9d01dd20bf | ||
|
|
5ab9168813 | ||
|
|
67ff930535 | ||
|
|
ae5ba702a4 | ||
|
|
63f0ab5e20 | ||
|
|
eeac8d4656 | ||
|
|
14c83e1f4c | ||
|
|
b7ff2645c4 | ||
|
|
79ac524262 | ||
|
|
92083ea64c | ||
|
|
82dc859a49 | ||
|
|
bee1fbaa34 | ||
|
|
eba82a8ba5 | ||
|
|
06b08bf10f | ||
|
|
7bdf419eb1 | ||
|
|
04e7f58cea | ||
|
|
3796dd8a87 | ||
|
|
8afec170ed | ||
|
|
3154af776e | ||
|
|
6480a94181 | ||
|
|
9582b5036f | ||
|
|
1533bf995a | ||
|
|
a53d7cb6bf | ||
|
|
b249357732 | ||
|
|
807d9241bd | ||
|
|
9bfaca2857 | ||
|
|
c26b77683a | ||
|
|
7ee54810d4 | ||
|
|
fc32e0bd3f | ||
|
|
0546e48467 | ||
|
|
ab65b7a0f1 | ||
|
|
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 | ||
|
|
55466f122c | ||
|
|
ede8217ab3 | ||
|
|
2689fb4e65 | ||
|
|
eaf31a59e5 | ||
|
|
aa1bbcb5c1 | ||
|
|
3c26080c39 | ||
|
|
dc07fd4e9c | ||
|
|
7bc74feb11 | ||
|
|
c5f318ed4d | ||
|
|
8fbb1cd154 | ||
|
|
88aee8a887 | ||
|
|
0f77b18078 | ||
|
|
3eeaee71c0 | ||
|
|
045d54e2e6 | ||
|
|
75fedf1b75 | ||
|
|
debdacb726 | ||
|
|
1c8ae67ed2 | ||
|
|
0eb57698ec | ||
|
|
bc95531f2d | ||
|
|
60f4048d6c | ||
|
|
fb70fbb09f | ||
|
|
fc439bedf1 | ||
|
|
26d0b7147d | ||
|
|
af6aa8a690 | ||
|
|
bd4f1abba2 | ||
|
|
d2656a3679 | ||
|
|
a3b45ceccc | ||
|
|
0dcc7d50a8 | ||
|
|
bcb22af034 | ||
|
|
d04dc62666 | ||
|
|
c30d355f97 | ||
|
|
49cb148b38 | ||
|
|
3bc31a8b20 | ||
|
|
c28523e70e | ||
|
|
278f393f74 | ||
|
|
cbf68c1395 | ||
|
|
45e8071599 | ||
|
|
b96389d975 | ||
|
|
a77ac6ae25 | ||
|
|
9bcf399b4c | ||
|
|
4aacee8055 | ||
|
|
0b18aeff62 | ||
|
|
bed1c2ac18 | ||
|
|
8cd832656b | ||
|
|
0499f59e71 | ||
|
|
1fa59bf9b3 | ||
|
|
db40ee6912 | ||
|
|
02b98b8e1b | ||
|
|
31fef216e4 | ||
|
|
77ab5d7a51 | ||
|
|
cd5cf7ce2d | ||
|
|
39cb9d9a6c | ||
|
|
4919bc5134 | ||
|
|
a4e64eb01f | ||
|
|
328b18df88 | ||
|
|
5e7bf32e5e | ||
|
|
04403f4e5f | ||
|
|
420e0822b4 | ||
|
|
f7a3ea6415 | ||
|
|
f28e79ef4f | ||
|
|
5cd787bf85 | ||
|
|
021d637fd6 | ||
|
|
2e14096af7 | ||
|
|
fe2b298a2f | ||
|
|
c9e3996007 | ||
|
|
3a0c375692 | ||
|
|
c5eaeb2ddb | ||
|
|
19fa4cd1d3 | ||
|
|
0adf7ef16f | ||
|
|
8f7fb96a44 | ||
|
|
9e3b021b1a | ||
|
|
25164d4cef | ||
|
|
516b1ec332 | ||
|
|
95ba045a69 | ||
|
|
6e02f9288e | ||
|
|
a584ae093e | ||
|
|
1592f96b7b | ||
|
|
004fff975f | ||
|
|
4d049ee8f5 | ||
|
|
c80e92fa16 | ||
|
|
545e09fad2 | ||
|
|
133dc56ff4 | ||
|
|
9c877d93fa | ||
|
|
7ad86fed03 | ||
|
|
31cf07f0ba | ||
|
|
4ffb48711a | ||
|
|
3da96a86e6 | ||
|
|
45ed9ea9bf | ||
|
|
61057f25bc | ||
|
|
68ef72cb61 | ||
|
|
ef32dccb83 | ||
|
|
e78200cc84 | ||
|
|
3f7313d031 | ||
|
|
139e4b9f65 | ||
|
|
9680f00ddd | ||
|
|
0b0ebfe6f8 | ||
|
|
5aadb8294c | ||
|
|
ace1681886 | ||
|
|
75ef61a958 | ||
|
|
2dba5b5451 | ||
|
|
a8f68ba7f0 | ||
|
|
475bf16b09 | ||
|
|
67f49a8dcd | ||
|
|
074004392c | ||
|
|
8c5a493f68 | ||
|
|
cccd1635c5 | ||
|
|
1915c1387e | ||
|
|
4a37a27cca | ||
|
|
ab8a4ed532 | ||
|
|
12fd512b83 | ||
|
|
239435a6dc | ||
|
|
7c1551bdc9 | ||
|
|
bdcf02695f | ||
|
|
d206fd5392 | ||
|
|
0bd1715f36 | ||
|
|
2e7c60675b | ||
|
|
7caaa8e22b | ||
|
|
839c92bf3d | ||
|
|
28aa176957 | ||
|
|
0f24f0f214 | ||
|
|
655da113c8 | ||
|
|
159b986cdd | ||
|
|
069d1786f5 | ||
|
|
f43829a16a | ||
|
|
65e61ad001 | ||
|
|
0107a4de81 | ||
|
|
337ce7b1c2 | ||
|
|
3719f79065 | ||
|
|
8d1747aa6a | ||
|
|
de9bdcba0a | ||
|
|
f8b6cb6d5b | ||
|
|
e6942805b4 | ||
|
|
47e76c9981 | ||
|
|
68fa84ef6f | ||
|
|
ff2fb18c76 | ||
|
|
28a9b1e9fa | ||
|
|
6377d5a73a | ||
|
|
80e4707af1 | ||
|
|
ab00e34d0d | ||
|
|
7c2f883b67 | ||
|
|
9b5eecba8f | ||
|
|
4b028edfe9 | ||
|
|
7e25dd7be1 | ||
|
|
09460d7af4 | ||
|
|
3b22640077 |
@@ -24,7 +24,7 @@ jobs:
|
|||||||
linux-arm64-glibc-node-18:
|
linux-arm64-glibc-node-18:
|
||||||
resource_class: arm.medium
|
resource_class: arm.medium
|
||||||
machine:
|
machine:
|
||||||
image: ubuntu-2004:current
|
image: ubuntu-2204:current
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: |
|
- run: |
|
||||||
@@ -38,7 +38,7 @@ jobs:
|
|||||||
- run: sudo docker exec sharp sh -c "npm test"
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
- run: |
|
- run: |
|
||||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linux-arm64=file:./npm/linux-arm64\""
|
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linux-arm64=file:./npm/linux-arm64\""
|
||||||
sudo docker exec sharp sh -c "npm run clean"
|
sudo docker exec sharp sh -c "npm run clean"
|
||||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||||
sudo docker exec sharp sh -c "npm test"
|
sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
linux-arm64-glibc-node-20:
|
linux-arm64-glibc-node-20:
|
||||||
resource_class: arm.medium
|
resource_class: arm.medium
|
||||||
machine:
|
machine:
|
||||||
image: ubuntu-2004:current
|
image: ubuntu-2204:current
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: |
|
- run: |
|
||||||
@@ -62,14 +62,14 @@ jobs:
|
|||||||
- run: sudo docker exec sharp sh -c "npm test"
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
- run: |
|
- run: |
|
||||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linux-arm64=file:./npm/linux-arm64\""
|
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linux-arm64=file:./npm/linux-arm64\""
|
||||||
sudo docker exec sharp sh -c "npm run clean"
|
sudo docker exec sharp sh -c "npm run clean"
|
||||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||||
sudo docker exec sharp sh -c "npm test"
|
sudo docker exec sharp sh -c "npm test"
|
||||||
linux-arm64-musl-node-18:
|
linux-arm64-musl-node-18:
|
||||||
resource_class: arm.medium
|
resource_class: arm.medium
|
||||||
machine:
|
machine:
|
||||||
image: ubuntu-2004:current
|
image: ubuntu-2204:current
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: |
|
- run: |
|
||||||
@@ -79,7 +79,7 @@ jobs:
|
|||||||
- run: sudo docker exec sharp sh -c "npm test"
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
- run: |
|
- run: |
|
||||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
||||||
sudo docker exec sharp sh -c "npm run clean"
|
sudo docker exec sharp sh -c "npm run clean"
|
||||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||||
sudo docker exec sharp sh -c "npm test"
|
sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -87,7 +87,7 @@ jobs:
|
|||||||
linux-arm64-musl-node-20:
|
linux-arm64-musl-node-20:
|
||||||
resource_class: arm.medium
|
resource_class: arm.medium
|
||||||
machine:
|
machine:
|
||||||
image: ubuntu-2004:current
|
image: ubuntu-2204:current
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: |
|
- run: |
|
||||||
@@ -99,7 +99,7 @@ jobs:
|
|||||||
- run: sudo docker exec sharp sh -c "npm test"
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
- run: |
|
- run: |
|
||||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
||||||
sudo docker exec sharp sh -c "npm run clean"
|
sudo docker exec sharp sh -c "npm run clean"
|
||||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||||
sudo docker exec sharp sh -c "npm test"
|
sudo docker exec sharp sh -c "npm test"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
freebsd_instance:
|
freebsd_instance:
|
||||||
image_family: freebsd-13-2
|
image_family: freebsd-14-0-snap
|
||||||
|
|
||||||
task:
|
task:
|
||||||
name: FreeBSD
|
name: FreeBSD
|
||||||
@@ -10,7 +10,8 @@ task:
|
|||||||
- pkg update -f
|
- pkg update -f
|
||||||
- pkg upgrade -y
|
- pkg upgrade -y
|
||||||
- pkg install -y devel/git devel/pkgconf graphics/vips www/node20 www/npm
|
- pkg install -y devel/git devel/pkgconf graphics/vips www/node20 www/npm
|
||||||
|
- pkg-config --modversion vips-cpp
|
||||||
install_script:
|
install_script:
|
||||||
- npm install --build-from-source
|
- npm install --build-from-source
|
||||||
test_script:
|
test_script:
|
||||||
- npm test
|
- npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||||
|
|||||||
1
.gitattributes
vendored
@@ -1 +0,0 @@
|
|||||||
src/libvips/* linguist-vendored
|
|
||||||
2
.github/CONTRIBUTING.md
vendored
@@ -63,7 +63,7 @@ By way of example, the `background()` method present in v0.20.0 was deprecated i
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The public API is documented with [JSDoc](http://usejsdoc.org/) annotated comments.
|
The public API is documented with [JSDoc](https://jsdoc.app/) annotated comments.
|
||||||
|
|
||||||
These can be converted to Markdown by running:
|
These can be converted to Markdown by running:
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
33
.github/ISSUE_TEMPLATE/installation.md
vendored
@@ -11,7 +11,10 @@ labels: installation
|
|||||||
|
|
||||||
<!-- Please place an [x] in the box to confirm. -->
|
<!-- Please place an [x] in the box to confirm. -->
|
||||||
|
|
||||||
- [ ] I have read the [documentation relating to installation](https://sharp.pixelplumbing.com/install).
|
- [ ] I have read and understood all of the [documentation relating to installation](https://sharp.pixelplumbing.com/install).
|
||||||
|
- [ ] I have searched for known bugs relating to this problem in my choice of package manager.
|
||||||
|
|
||||||
|
You must confirm both of these before continuing.
|
||||||
|
|
||||||
### Are you using the latest version of sharp?
|
### Are you using the latest version of sharp?
|
||||||
|
|
||||||
@@ -21,27 +24,37 @@ labels: installation
|
|||||||
|
|
||||||
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
|
If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
|
||||||
|
|
||||||
If you are using another package which depends on a version of `sharp` that is not the latest, please open an issue against that package instead.
|
If you are using another package which depends on a version of `sharp` that is not the latest,
|
||||||
|
please open an issue against that package instead.
|
||||||
|
|
||||||
### Are you using a supported runtime?
|
### Are you using a supported runtime?
|
||||||
|
|
||||||
<!-- Please place an [x] in the relevant box to confirm. -->
|
<!-- Please place an [x] in the relevant box to confirm. -->
|
||||||
|
|
||||||
- [ ] I am using Node.js 18 with a version >= 18.17.0
|
- [ ] I am using Node.js with a version that satisfies `^18.17.0 || ^20.3.0 || >=21.0.0`
|
||||||
- [ ] I am using Node.js 20 with a version >= 20.3.0
|
- [ ] I am using Deno
|
||||||
- [ ] I am using Node.js 21 or later
|
- [ ] I am using Bun
|
||||||
|
|
||||||
If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue.
|
If you cannot confirm any of these,
|
||||||
|
please upgrade to the latest version
|
||||||
|
and try again before opening an issue.
|
||||||
|
|
||||||
### Are you using a supported package manager?
|
### Are you using a supported package manager and installing optional dependencies?
|
||||||
|
|
||||||
<!-- Please place an [x] in the relevant box to confirm. -->
|
<!-- Please place an [x] in the relevant box to confirm. -->
|
||||||
|
|
||||||
- [ ] I am using npm >= 9.6.5
|
- [ ] I am using npm >= 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
|
- [ ] I am using pnpm >= 7.1.0 with `--no-optional=false`
|
||||||
|
- [ ] I am using Deno
|
||||||
|
- [ ] I am using Bun
|
||||||
|
|
||||||
If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue.
|
If you cannot confirm any of these, please upgrade to the latest version of your chosen package manager
|
||||||
|
and ensure you are allowing the installation of optional or multi-platform dependencies before opening an issue.
|
||||||
|
|
||||||
|
### What is the complete error message, including the full stack trace?
|
||||||
|
|
||||||
|
<!-- Please provide the error message and stack trace here. -->
|
||||||
|
|
||||||
### What is the complete output of running `npm install --verbose --foreground-scripts sharp` in an empty directory?
|
### What is the complete output of running `npm install --verbose --foreground-scripts sharp` in an empty directory?
|
||||||
|
|
||||||
|
|||||||
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. -->
|
||||||
|
|||||||
202
.github/workflows/ci.yml
vendored
@@ -14,40 +14,73 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-22.04
|
- os: ubuntu-24.04
|
||||||
container: rockylinux:8
|
container: rockylinux:8
|
||||||
|
nodejs_arch: x64
|
||||||
nodejs_version: "^18.17.0"
|
nodejs_version: "^18.17.0"
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
platform: linux-x64
|
platform: linux-x64
|
||||||
prebuild: true
|
prebuild: true
|
||||||
- os: ubuntu-22.04
|
- os: ubuntu-24.04
|
||||||
container: rockylinux:8
|
container: rockylinux:8
|
||||||
|
nodejs_arch: x64
|
||||||
nodejs_version: "^20.3.0"
|
nodejs_version: "^20.3.0"
|
||||||
nodejs_version_major: 20
|
nodejs_version_major: 20
|
||||||
platform: linux-x64
|
platform: linux-x64
|
||||||
- os: ubuntu-22.04
|
- os: ubuntu-24.04
|
||||||
|
container: rockylinux:8
|
||||||
|
nodejs_arch: x64
|
||||||
|
nodejs_version: "^22.9.0"
|
||||||
|
nodejs_version_major: 22
|
||||||
|
platform: linux-x64
|
||||||
|
- os: ubuntu-24.04
|
||||||
container: node:18-alpine3.17
|
container: node:18-alpine3.17
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
platform: linuxmusl-x64
|
platform: linuxmusl-x64
|
||||||
prebuild: true
|
prebuild: true
|
||||||
- os: ubuntu-22.04
|
- os: ubuntu-24.04
|
||||||
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: ubuntu-24.04
|
||||||
|
container: node:22-alpine3.20
|
||||||
|
nodejs_version_major: 22
|
||||||
|
platform: linuxmusl-x64
|
||||||
|
- os: macos-13
|
||||||
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-13
|
||||||
nodejs_arch: x64
|
nodejs_arch: x64
|
||||||
nodejs_version: "^20.3.0"
|
nodejs_version: "^20.3.0"
|
||||||
nodejs_version_major: 20
|
nodejs_version_major: 20
|
||||||
platform: darwin-x64
|
platform: darwin-x64
|
||||||
|
- os: macos-13
|
||||||
|
nodejs_arch: x64
|
||||||
|
nodejs_version: "^22.9.0"
|
||||||
|
nodejs_version_major: 22
|
||||||
|
platform: darwin-x64
|
||||||
|
- os: macos-14
|
||||||
|
nodejs_arch: arm64
|
||||||
|
nodejs_version: "^18.17.0"
|
||||||
|
nodejs_version_major: 18
|
||||||
|
platform: darwin-arm64
|
||||||
|
prebuild: true
|
||||||
|
- os: macos-14
|
||||||
|
nodejs_arch: arm64
|
||||||
|
nodejs_version: "^20.3.0"
|
||||||
|
nodejs_version_major: 20
|
||||||
|
platform: darwin-arm64
|
||||||
|
- os: macos-14
|
||||||
|
nodejs_arch: arm64
|
||||||
|
nodejs_version: "^22.9.0"
|
||||||
|
nodejs_version_major: 22
|
||||||
|
platform: darwin-arm64
|
||||||
- os: windows-2019
|
- os: windows-2019
|
||||||
nodejs_arch: x86
|
nodejs_arch: x86
|
||||||
nodejs_version: "^18.17.0"
|
nodejs_version: "18.18.2" # pinned to avoid 18.19.0 and npm 10
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
platform: win32-ia32
|
platform: win32-ia32
|
||||||
prebuild: true
|
prebuild: true
|
||||||
@@ -56,6 +89,11 @@ jobs:
|
|||||||
nodejs_version: "^20.3.0"
|
nodejs_version: "^20.3.0"
|
||||||
nodejs_version_major: 20
|
nodejs_version_major: 20
|
||||||
platform: win32-ia32
|
platform: win32-ia32
|
||||||
|
- os: windows-2019
|
||||||
|
nodejs_arch: x86
|
||||||
|
nodejs_version: "^22.9.0"
|
||||||
|
nodejs_version_major: 22
|
||||||
|
platform: win32-ia32
|
||||||
- os: windows-2019
|
- os: windows-2019
|
||||||
nodejs_arch: x64
|
nodejs_arch: x64
|
||||||
nodejs_version: "^18.17.0"
|
nodejs_version: "^18.17.0"
|
||||||
@@ -67,33 +105,28 @@ jobs:
|
|||||||
nodejs_version: "^20.3.0"
|
nodejs_version: "^20.3.0"
|
||||||
nodejs_version_major: 20
|
nodejs_version_major: 20
|
||||||
platform: win32-x64
|
platform: win32-x64
|
||||||
|
- os: windows-2019
|
||||||
|
nodejs_arch: x64
|
||||||
|
nodejs_version: "^22.9.0"
|
||||||
|
nodejs_version_major: 22
|
||||||
|
platform: win32-x64
|
||||||
steps:
|
steps:
|
||||||
- name: Dependencies (Linux glibc)
|
|
||||||
if: contains(matrix.container, 'centos')
|
|
||||||
run: |
|
|
||||||
yum install -y https://rpm.nodesource.com/pub_${{ matrix.nodejs_version_major }}.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm
|
|
||||||
yum install -y https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
|
|
||||||
yum install -y centos-release-scl
|
|
||||||
yum install -y devtoolset-11-gcc-c++ make git python3 nodejs fontconfig google-noto-sans-fonts
|
|
||||||
echo "/opt/rh/devtoolset-11/root/usr/bin" >> $GITHUB_PATH
|
|
||||||
- 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 https://rpm.nodesource.com/pub_${{ matrix.nodejs_version_major }}.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm
|
dnf install -y gcc-toolset-11-gcc-c++ make git python3.12 fontconfig google-noto-sans-fonts
|
||||||
dnf install -y --setopt=nodesource-nodejs.module_hotfixes=1 nodejs
|
|
||||||
dnf install -y gcc-toolset-11-gcc-c++ make git python3 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')
|
||||||
run: apk add build-base git python3 font-noto --update-cache
|
run: apk add build-base git python3 font-noto --update-cache
|
||||||
- name: Dependencies (Python 3.11 - macOS, Windows)
|
- name: Dependencies (Python 3.11 - macOS, Windows)
|
||||||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')
|
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.11'
|
python-version: "3.12"
|
||||||
- name: Dependencies (Node.js - macOS, Windows)
|
- name: Dependencies (Node.js)
|
||||||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')
|
if: "!contains(matrix.platform, 'linuxmusl')"
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.nodejs_version }}
|
node-version: ${{ matrix.nodejs_version }}
|
||||||
architecture: ${{ matrix.nodejs_arch }}
|
architecture: ${{ matrix.nodejs_arch }}
|
||||||
@@ -106,7 +139,7 @@ jobs:
|
|||||||
- name: Test packaging
|
- name: Test packaging
|
||||||
run: |
|
run: |
|
||||||
npm run package-from-local-build
|
npm run package-from-local-build
|
||||||
npm pkg set "optionalDependencies.@sharpen/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
npm pkg set "optionalDependencies.@img/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
||||||
npm run clean
|
npm run clean
|
||||||
npm install --ignore-scripts
|
npm install --ignore-scripts
|
||||||
npm test
|
npm test
|
||||||
@@ -121,73 +154,92 @@ jobs:
|
|||||||
github-runner-qemu:
|
github-runner-qemu:
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
name: linux-arm - Node.js 18 - prebuild
|
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} - prebuild
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: uraimo/run-on-arch-action@v2
|
|
||||||
with:
|
|
||||||
arch: armv6
|
|
||||||
distro: buster
|
|
||||||
env: |
|
|
||||||
nodejs_version: "18.17.0"
|
|
||||||
prebuild_upload: "${{ startsWith(github.ref, 'refs/tags/') && secrets.GITHUB_TOKEN || '' }}"
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y fontconfig fonts-noto-core g++ git libatomic1 make python3 xz-utils
|
|
||||||
mkdir /opt/nodejs
|
|
||||||
curl --silent https://unofficial-builds.nodejs.org/download/release/v${nodejs_version}/node-v${nodejs_version}-linux-armv6l.tar.xz | tar xJC /opt/nodejs --strip-components=1
|
|
||||||
export PATH=$PATH:/opt/nodejs/bin
|
|
||||||
npm install --build-from-source
|
|
||||||
npx mocha --no-config --spec=test/unit/io.js
|
|
||||||
npm run package-from-local-build
|
|
||||||
npm pkg set "optionalDependencies.@sharpen/sharp-linux-arm=file:./npm/linux-arm"
|
|
||||||
npm run clean
|
|
||||||
npm install --ignore-scripts
|
|
||||||
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
|
||||||
[[ -n $prebuild_upload ]] && cd src && ln -s ../package.json && npx prebuild || true
|
|
||||||
macstadium-runner:
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} ${{ matrix.prebuild && '- prebuild' }}
|
|
||||||
runs-on: macos-m1
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- nodejs_arch: x64
|
- platform: linux-arm
|
||||||
nodejs_version: "^18.17.0"
|
distro: bullseye
|
||||||
|
run_on_arch: armv6
|
||||||
|
nodejs_arch: armv6l
|
||||||
|
nodejs_hostname: unofficial-builds.nodejs.org
|
||||||
|
nodejs_version: "18.17.0"
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
platform: darwin-x64
|
- platform: linux-s390x
|
||||||
- nodejs_arch: arm64
|
distro: bullseye
|
||||||
nodejs_version: "^18.17.0"
|
run_on_arch: s390x
|
||||||
|
nodejs_arch: s390x
|
||||||
|
nodejs_hostname: nodejs.org
|
||||||
|
nodejs_version: "18.17.0"
|
||||||
|
nodejs_version_major: 18
|
||||||
|
- platform: linux-ppc64
|
||||||
|
distro: bullseye
|
||||||
|
run_on_arch: ppc64le
|
||||||
|
nodejs_arch: ppc64le
|
||||||
|
nodejs_hostname: nodejs.org
|
||||||
|
nodejs_version: "18.17.0"
|
||||||
nodejs_version_major: 18
|
nodejs_version_major: 18
|
||||||
platform: darwin-arm64
|
|
||||||
prebuild: true
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: /usr/bin/arch -arch arm64e /bin/bash -l {0}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Dependencies (Node.js)
|
- uses: actions/checkout@v4
|
||||||
uses: actions/setup-node@v3
|
- uses: uraimo/run-on-arch-action@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.nodejs_version }}
|
arch: ${{ matrix.run_on_arch }}
|
||||||
architecture: ${{ matrix.nodejs_arch }}
|
distro: ${{ matrix.distro }}
|
||||||
|
env: |
|
||||||
|
prebuild_upload: "${{ startsWith(github.ref, 'refs/tags/') && secrets.GITHUB_TOKEN || '' }}"
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y curl g++ git libatomic1 make python3 xz-utils
|
||||||
|
mkdir /opt/nodejs
|
||||||
|
curl --silent https://${{ matrix.nodejs_hostname }}/download/release/v${{ matrix.nodejs_version}}/node-v${{ matrix.nodejs_version}}-linux-${{ matrix.nodejs_arch }}.tar.xz | tar xJC /opt/nodejs --strip-components=1
|
||||||
|
export PATH=$PATH:/opt/nodejs/bin
|
||||||
|
npm install --build-from-source
|
||||||
|
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||||
|
npm run package-from-local-build
|
||||||
|
npm pkg set "optionalDependencies.@img/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
||||||
|
npm run clean
|
||||||
|
npm install --ignore-scripts
|
||||||
|
npx mocha --no-config --spec=test/unit/io.js --timeout=30000
|
||||||
|
[[ -n $prebuild_upload ]] && cd src && ln -s ../package.json && npx prebuild || true
|
||||||
|
github-runner-emscripten:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
name: wasm32 - prebuild
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
container: "emscripten/emsdk:4.0.6"
|
||||||
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
- name: Dependencies
|
||||||
|
run: apt-get update && apt-get install -y pkg-config
|
||||||
|
- name: Dependencies (Node.js)
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "20"
|
||||||
- name: Install
|
- name: Install
|
||||||
run: npm install --build-from-source
|
run: emmake npm install --build-from-source
|
||||||
|
- name: Verify emscripten versions match
|
||||||
|
run: |
|
||||||
|
EMSCRIPTEN_VERSION_LIBVIPS=$(node -p "require('@img/sharp-libvips-dev-wasm32/versions').emscripten")
|
||||||
|
EMSCRIPTEN_VERSION_SHARP=$(emcc -dumpversion)
|
||||||
|
echo "libvips built with emscripten $EMSCRIPTEN_VERSION_LIBVIPS"
|
||||||
|
echo "sharp built with emscripten $EMSCRIPTEN_VERSION_SHARP"
|
||||||
|
test "$EMSCRIPTEN_VERSION_LIBVIPS" = "$EMSCRIPTEN_VERSION_SHARP"
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm test
|
run: emmake npm test
|
||||||
- name: Test packaging
|
- name: Test packaging
|
||||||
run: |
|
run: |
|
||||||
npm run package-from-local-build
|
emmake npm run package-from-local-build
|
||||||
npm pkg set "optionalDependencies.@sharpen/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
|
npm pkg set "optionalDependencies.@img/sharp-wasm32=file:./npm/wasm32"
|
||||||
npm run clean
|
npm run clean
|
||||||
npm install --ignore-scripts
|
rm -rf node_modules/@img/sharp-linux-x64
|
||||||
|
npm install --cpu=wasm32
|
||||||
npm test
|
npm test
|
||||||
- name: Prebuild
|
- name: Prebuild
|
||||||
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
env:
|
env:
|
||||||
|
npm_config_nodedir: emscripten
|
||||||
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: cd src && ln -s ../package.json && npx prebuild
|
run: cd src && ln -s ../package.json && emmake npx prebuild --platform=emscripten --arch=wasm32 --strip=0
|
||||||
|
|||||||
160
.github/workflows/npm.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: "npm release smoke test"
|
name: "CI: npm smoke test"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -9,70 +9,186 @@ permissions: {}
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-smoke-test:
|
release-smoke-test:
|
||||||
name: "${{ github.ref }} ${{ matrix.name }}"
|
name: "${{ github.ref_name }} ${{ matrix.name }}"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.runs-on }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- name: linux-x64
|
- name: linux-x64-node-npm
|
||||||
os: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
- name: darwin-x64
|
runtime: node
|
||||||
os: macos-11
|
package-manager: npm
|
||||||
- name: win32-x64
|
- name: linux-x64-node-pnpm
|
||||||
os: windows-2019
|
runs-on: ubuntu-24.04
|
||||||
|
runtime: node
|
||||||
|
package-manager: pnpm
|
||||||
|
- name: linux-x64-node-yarn
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn
|
||||||
|
- name: linux-x64-node-yarn-pnp
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-pnp
|
||||||
|
- name: linux-x64-node-yarn-v1
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-v1
|
||||||
|
- name: linux-x64-deno
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
runtime: deno
|
||||||
|
- name: linux-x64-bun
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
runtime: bun
|
||||||
|
|
||||||
|
- name: darwin-x64-node-npm
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: node
|
||||||
|
package-manager: npm
|
||||||
|
- name: darwin-x64-node-pnpm
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: node
|
||||||
|
package-manager: pnpm
|
||||||
|
- name: darwin-x64-node-yarn
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn
|
||||||
|
- name: darwin-x64-node-yarn-pnp
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-pnp
|
||||||
|
- name: darwin-x64-node-yarn-v1
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-v1
|
||||||
|
- name: darwin-x64-deno
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: deno
|
||||||
|
- name: darwin-x64-bun
|
||||||
|
runs-on: macos-13
|
||||||
|
runtime: bun
|
||||||
|
|
||||||
|
- name: win32-x64-node-npm
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: node
|
||||||
|
package-manager: npm
|
||||||
|
- name: win32-x64-node-pnpm
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: node
|
||||||
|
package-manager: pnpm
|
||||||
|
- name: win32-x64-node-yarn
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn
|
||||||
|
- name: win32-x64-node-yarn-pnp
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-pnp
|
||||||
|
- name: win32-x64-node-yarn-v1
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: node
|
||||||
|
package-manager: yarn-v1
|
||||||
|
- name: win32-x64-deno
|
||||||
|
runs-on: windows-2019
|
||||||
|
runtime: deno
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install Node.js
|
- name: Install Node.js
|
||||||
uses: actions/setup-node@v3
|
if: ${{ matrix.runtime == 'node' }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
- name: Install pnpm
|
||||||
|
if: ${{ matrix.package-manager == 'pnpm' }}
|
||||||
|
uses: pnpm/action-setup@v4
|
||||||
|
with:
|
||||||
|
version: 8
|
||||||
- name: Install Deno
|
- name: Install Deno
|
||||||
|
if: ${{ matrix.runtime == 'deno' }}
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.x
|
deno-version: v1.x
|
||||||
- name: Install Bun
|
- name: Install Bun
|
||||||
if: ${{ !contains(matrix.os, 'windows') }}
|
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
|
uses: DamianReeves/write-file-action@v1.3
|
||||||
with:
|
with:
|
||||||
path: package.json
|
path: package.json
|
||||||
contents: |
|
contents: |
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"sharp": "${{ steps.version.outputs.semver }}"
|
"sharp": "${{ steps.version.outputs.semver }}"
|
||||||
}
|
},
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
- name: Create release.mjs
|
- name: Create release.mjs
|
||||||
uses: DamianReeves/write-file-action@v1
|
uses: DamianReeves/write-file-action@v1.3
|
||||||
with:
|
with:
|
||||||
path: release.mjs
|
path: release.mjs
|
||||||
contents: |
|
contents: |
|
||||||
import { createRequire } from 'node:module';
|
|
||||||
import { deepStrictEqual } from 'node:assert';
|
import { deepStrictEqual } from 'node:assert';
|
||||||
const require = createRequire(import.meta.url);
|
import sharp from 'sharp';
|
||||||
const sharp = require('sharp');
|
deepStrictEqual(['.jpg', '.jpeg', '.jpe', '.jfif'], sharp.format.jpeg.input.fileSuffix);
|
||||||
deepStrictEqual(['.jpg', '.jpeg', '.jpe'], sharp.format.jpeg.input.fileSuffix);
|
|
||||||
|
|
||||||
- name: Run with Node.js
|
- name: Run with Node.js + npm
|
||||||
|
if: ${{ matrix.package-manager == 'npm' }}
|
||||||
run: |
|
run: |
|
||||||
npm install --ignore-scripts
|
npm install --ignore-scripts
|
||||||
node release.mjs
|
node release.mjs
|
||||||
|
|
||||||
|
- name: Run with Node.js + pnpm
|
||||||
|
if: ${{ matrix.package-manager == 'pnpm' }}
|
||||||
|
run: |
|
||||||
|
pnpm install --ignore-scripts
|
||||||
|
node release.mjs
|
||||||
|
|
||||||
|
- name: Run with Node.js + yarn
|
||||||
|
if: ${{ matrix.package-manager == 'yarn' }}
|
||||||
|
run: |
|
||||||
|
corepack enable
|
||||||
|
yarn set version stable
|
||||||
|
yarn config set enableImmutableInstalls false
|
||||||
|
yarn config set enableScripts false
|
||||||
|
yarn config set nodeLinker node-modules
|
||||||
|
yarn install
|
||||||
|
node release.mjs
|
||||||
|
|
||||||
|
- name: Run with Node.js + yarn pnp
|
||||||
|
if: ${{ matrix.package-manager == 'yarn-pnp' }}
|
||||||
|
run: |
|
||||||
|
corepack enable
|
||||||
|
yarn set version stable
|
||||||
|
yarn config set enableImmutableInstalls false
|
||||||
|
yarn config set enableScripts false
|
||||||
|
yarn config set nodeLinker pnp
|
||||||
|
yarn install
|
||||||
|
yarn node release.mjs
|
||||||
|
|
||||||
|
- name: Run with 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' }}
|
||||||
run: deno run --allow-read --allow-ffi release.mjs
|
run: deno run --allow-read --allow-ffi release.mjs
|
||||||
|
|
||||||
- name: Run with Bun
|
- name: Run with Bun
|
||||||
if: ${{ !contains(matrix.os, 'windows') }}
|
if: ${{ matrix.runtime == 'bun' }}
|
||||||
run: |
|
run: |
|
||||||
bun install --ignore-scripts
|
bun install --ignore-scripts
|
||||||
bun release.mjs
|
bun release.mjs
|
||||||
|
|||||||
7
.gitignore
vendored
@@ -8,14 +8,11 @@ test/bench/node_modules
|
|||||||
test/fixtures/output*
|
test/fixtures/output*
|
||||||
test/fixtures/vips-properties.xml
|
test/fixtures/vips-properties.xml
|
||||||
test/leak/libvips.supp
|
test/leak/libvips.supp
|
||||||
test/saliency/report.json
|
|
||||||
test/saliency/Image*
|
|
||||||
test/saliency/[Uu]serData*
|
|
||||||
!test/saliency/userData.js
|
|
||||||
.gitattributes
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.nyc_output
|
.nyc_output
|
||||||
.vscode/
|
.vscode/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
.idea
|
.idea
|
||||||
.firebase
|
.firebase
|
||||||
|
.astro
|
||||||
|
docs/dist
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"runtime": "napi",
|
"runtime": "napi",
|
||||||
"include-regex": "(sharp-.+\\.node|libvips-.+\\.dll|libglib-.+\\.dll|libgobject-.+\\.dll)",
|
"include-regex": "(sharp-.+\\.node|libvips-.+\\.dll)",
|
||||||
"prerelease": true,
|
"prerelease": true,
|
||||||
"strip": true
|
"strip": true
|
||||||
}
|
}
|
||||||
|
|||||||
10
README.md
@@ -1,11 +1,15 @@
|
|||||||
# sharp
|
# sharp
|
||||||
|
|
||||||
<img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
<img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/public/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
||||||
|
|
||||||
The typical use case for this high speed Node.js module
|
The typical use case for this high speed Node-API module
|
||||||
is to convert large images in common formats to
|
is to convert large images in common formats to
|
||||||
smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
|
smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
|
||||||
|
|
||||||
|
It can be used with all JavaScript runtimes
|
||||||
|
that provide support for Node-API v9, including
|
||||||
|
Node.js (^18.17.0 or >= 20.3.0), Deno and Bun.
|
||||||
|
|
||||||
Resizing an image is typically 4x-5x faster than using the
|
Resizing an image is typically 4x-5x faster than using the
|
||||||
quickest ImageMagick and GraphicsMagick settings
|
quickest ImageMagick and GraphicsMagick settings
|
||||||
due to its use of [libvips](https://github.com/libvips/libvips).
|
due to its use of [libvips](https://github.com/libvips/libvips).
|
||||||
@@ -16,7 +20,7 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|||||||
As well as image resizing, operations such as
|
As well as image resizing, operations such as
|
||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern macOS, Windows and Linux systems running Node.js >= 18.17.0
|
Most modern macOS, Windows and Linux systems
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|||||||
79
docs/astro.config.mjs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// @ts-check
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import starlight from '@astrojs/starlight';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
site: 'https://sharp.pixelplumbing.com',
|
||||||
|
integrations: [
|
||||||
|
starlight({
|
||||||
|
title: 'sharp',
|
||||||
|
description:
|
||||||
|
'High performance Node.js image processing. The fastest module to resize JPEG, PNG, WebP and TIFF images.',
|
||||||
|
logo: {
|
||||||
|
src: './src/assets/sharp-logo.svg',
|
||||||
|
alt: '#'
|
||||||
|
},
|
||||||
|
customCss: ['./src/styles/custom.css'],
|
||||||
|
head: [{
|
||||||
|
tag: 'meta',
|
||||||
|
attrs: {
|
||||||
|
'http-equiv': 'Content-Security-Policy',
|
||||||
|
content: "default-src 'self'; connect-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://cdn.jsdelivr.net/gh/lovell/; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://static.cloudflareinsights.com/beacon.min.js/;"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tag: 'link',
|
||||||
|
attrs: {
|
||||||
|
rel: 'author',
|
||||||
|
href: '/humans.txt',
|
||||||
|
type: 'text/plain'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
tag: 'script',
|
||||||
|
attrs: {
|
||||||
|
type: 'application/ld+json'
|
||||||
|
},
|
||||||
|
content: JSON.stringify({
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'SoftwareSourceCode',
|
||||||
|
name: 'sharp',
|
||||||
|
description: 'High performance Node.js image processing',
|
||||||
|
url: 'https://sharp.pixelplumbing.com',
|
||||||
|
codeRepository: 'https://github.com/lovell/sharp',
|
||||||
|
programmingLanguage: ['JavaScript', 'C++'],
|
||||||
|
runtimePlatform: 'Node.js',
|
||||||
|
copyrightHolder: {
|
||||||
|
'@context': 'https://schema.org',
|
||||||
|
'@type': 'Person',
|
||||||
|
name: 'Lovell Fuller'
|
||||||
|
},
|
||||||
|
copyrightYear: 2013,
|
||||||
|
license: 'https://www.apache.org/licenses/LICENSE-2.0'
|
||||||
|
})
|
||||||
|
}],
|
||||||
|
sidebar: [
|
||||||
|
{ label: 'Home', link: '/' },
|
||||||
|
{ label: 'Installation', slug: 'install' },
|
||||||
|
{
|
||||||
|
label: 'API',
|
||||||
|
items: [
|
||||||
|
{ label: 'Constructor', slug: 'api-constructor' },
|
||||||
|
{ label: 'Input metadata', slug: 'api-input' },
|
||||||
|
{ label: 'Output options', slug: 'api-output' },
|
||||||
|
{ label: 'Resizing images', slug: 'api-resize' },
|
||||||
|
{ label: 'Compositing images', slug: 'api-composite' },
|
||||||
|
{ label: 'Image operations', slug: 'api-operation' },
|
||||||
|
{ label: 'Colour manipulation', slug: 'api-colour' },
|
||||||
|
{ label: 'Channel manipulation', slug: 'api-channel' },
|
||||||
|
{ label: 'Global properties', slug: 'api-utility' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ label: 'Performance', slug: 'performance' },
|
||||||
|
{ label: 'Changelog', slug: 'changelog' }
|
||||||
|
],
|
||||||
|
social: {
|
||||||
|
openCollective: 'https://opencollective.com/libvips',
|
||||||
|
github: 'https://github.com/lovell/sharp'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs').promises;
|
|
||||||
const path = require('path');
|
|
||||||
const jsdoc2md = require('jsdoc-to-markdown');
|
|
||||||
|
|
||||||
[
|
|
||||||
'constructor',
|
|
||||||
'input',
|
|
||||||
'resize',
|
|
||||||
'composite',
|
|
||||||
'operation',
|
|
||||||
'colour',
|
|
||||||
'channel',
|
|
||||||
'output',
|
|
||||||
'utility'
|
|
||||||
].forEach(async (m) => {
|
|
||||||
const input = path.join('lib', `${m}.js`);
|
|
||||||
const output = path.join('docs', `api-${m}.md`);
|
|
||||||
|
|
||||||
const ast = await jsdoc2md.getTemplateData({ files: input });
|
|
||||||
const markdown = await jsdoc2md.render({
|
|
||||||
data: ast,
|
|
||||||
'global-index-format': 'none',
|
|
||||||
'module-index-format': 'none'
|
|
||||||
});
|
|
||||||
|
|
||||||
const cleanMarkdown = markdown
|
|
||||||
.replace(/(## )([A-Za-z0-9]+)([^\n]*)/g, '$1$2\n> $2$3\n') // simplify headings to match those of documentationjs, ensures existing URLs work
|
|
||||||
.replace(/<a name="[A-Za-z0-9+]+"><\/a>/g, '') // remove anchors, let docute add these (at markdown to HTML render time)
|
|
||||||
.replace(/\*\*Kind\*\*: global[^\n]+/g, '') // remove all "global" Kind labels (requires JSDoc refactoring)
|
|
||||||
.trim();
|
|
||||||
|
|
||||||
await fs.writeFile(output, cleanMarkdown);
|
|
||||||
});
|
|
||||||
42
docs/build.mjs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import path from 'node:path';
|
||||||
|
import jsdoc2md from 'jsdoc-to-markdown';
|
||||||
|
|
||||||
|
const pages = {
|
||||||
|
constructor: 'Constructor',
|
||||||
|
input: 'Input metadata',
|
||||||
|
resize: 'Resizing images',
|
||||||
|
composite: 'Compositing images',
|
||||||
|
operation: 'Image operations',
|
||||||
|
colour: 'Colour manipulation',
|
||||||
|
channel: 'Channel manipulation',
|
||||||
|
output: 'Output options',
|
||||||
|
utility: 'Global properties'
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(pages).forEach(async (m) => {
|
||||||
|
const input = path.join('lib', `${m}.js`);
|
||||||
|
const output = path.join('docs', 'src', 'content', 'docs', `api-${m}.md`);
|
||||||
|
|
||||||
|
const ast = await jsdoc2md.getTemplateData({ files: input });
|
||||||
|
const markdown = await jsdoc2md.render({
|
||||||
|
data: ast,
|
||||||
|
'global-index-format': 'none',
|
||||||
|
'module-index-format': 'none'
|
||||||
|
});
|
||||||
|
|
||||||
|
const cleanMarkdown =
|
||||||
|
`---\n# This file was auto-generated from JSDoc in lib/${m}.js\ntitle: ${pages[m]}\n---\n\n` +
|
||||||
|
markdown
|
||||||
|
.replace(/(## )([A-Za-z0-9]+)([^\n]*)/g, '$1$2\n> $2$3\n') // simplify headings
|
||||||
|
.replace(/<a name="[A-Za-z0-9+]+"><\/a>/g, '') // remove anchors
|
||||||
|
.replace(/\*\*Kind\*\*: global[^\n]+/g, '') // remove all "global" Kind labels (requires JSDoc refactoring)
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
await fs.writeFile(output, cleanMarkdown);
|
||||||
|
});
|
||||||
1
docs/docute.min.js
vendored
@@ -1,14 +1,7 @@
|
|||||||
{
|
{
|
||||||
"hosting": {
|
"hosting": {
|
||||||
"site": "pixelplumbing-sharp",
|
"site": "pixelplumbing-sharp",
|
||||||
"public": ".",
|
"public": "dist",
|
||||||
"ignore": [
|
|
||||||
".*",
|
|
||||||
"build.js",
|
|
||||||
"firebase.json",
|
|
||||||
"image/**",
|
|
||||||
"search-index/**"
|
|
||||||
],
|
|
||||||
"headers": [
|
"headers": [
|
||||||
{
|
{
|
||||||
"source": "**",
|
"source": "**",
|
||||||
@@ -18,99 +11,6 @@
|
|||||||
{ "key": "X-Frame-Options", "value": "SAMEORIGIN" }
|
{ "key": "X-Frame-Options", "value": "SAMEORIGIN" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"redirects": [
|
|
||||||
{
|
|
||||||
"source": "**/install/**",
|
|
||||||
"destination": "/install",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "/page/install",
|
|
||||||
"destination": "/install",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-constructor/**",
|
|
||||||
"destination": "/api-constructor",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-input/**",
|
|
||||||
"destination": "/api-input",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-output/**",
|
|
||||||
"destination": "/api-output",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-resize/**",
|
|
||||||
"destination": "/api-resize",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-compsite/**",
|
|
||||||
"destination": "/api-compsite",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-operation/**",
|
|
||||||
"destination": "/api-operation",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-colour/**",
|
|
||||||
"destination": "/api-colour",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-channel/**",
|
|
||||||
"destination": "/api-channel",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/api-utility/**",
|
|
||||||
"destination": "/api-utility",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "/page/api",
|
|
||||||
"destination": "/api-constructor",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/performance/**",
|
|
||||||
"destination": "/performance",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "/page/performance",
|
|
||||||
"destination": "/performance",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "**/changelog/**",
|
|
||||||
"destination": "/changelog",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "/page/changelog",
|
|
||||||
"destination": "/changelog",
|
|
||||||
"type": 301
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "/en/**",
|
|
||||||
"destination": "/",
|
|
||||||
"type": 301
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"rewrites": [
|
|
||||||
{
|
|
||||||
"source": "**",
|
|
||||||
"destination": "/index.html"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 652 B |
|
Before Width: | Height: | Size: 2.8 KiB |
206
docs/index.html
17
docs/package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "sharp-docs",
|
||||||
|
"type": "module",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "astro dev",
|
||||||
|
"start": "astro dev",
|
||||||
|
"build": "astro build",
|
||||||
|
"preview": "astro preview",
|
||||||
|
"astro": "astro"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/starlight": "^0.32.3",
|
||||||
|
"astro": "^5.5.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
# Performance
|
|
||||||
|
|
||||||
A test to benchmark the performance of this module relative to alternatives.
|
|
||||||
|
|
||||||
Greater libvips performance can be expected with caching enabled (default)
|
|
||||||
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
|
||||||
|
|
||||||
The I/O limits of the relevant (de)compression library will generally determine maximum throughput.
|
|
||||||
|
|
||||||
## Contenders
|
|
||||||
|
|
||||||
* [jimp](https://www.npmjs.com/package/jimp) v0.22.7 - Image processing in pure JavaScript.
|
|
||||||
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
|
||||||
* [gm](https://www.npmjs.com/package/gm) v1.25.0 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
|
||||||
* [@squoosh/lib](https://www.npmjs.com/package/@squoosh/lib) v0.4.0 - Image libraries transpiled to WebAssembly, includes GPLv3 code, but "*Project no longer maintained*".
|
|
||||||
* [@squoosh/cli](https://www.npmjs.com/package/@squoosh/cli) v0.7.3 - Command line wrapper around `@squoosh/lib`, avoids GPLv3 by spawning process, but "*Project no longer maintained*".
|
|
||||||
* sharp v0.32.0 / libvips v8.14.2 - Caching within libvips disabled to ensure a fair comparison.
|
|
||||||
|
|
||||||
## Environment
|
|
||||||
|
|
||||||
### AMD64
|
|
||||||
|
|
||||||
* AWS EC2 us-east-2 [c6a.xlarge](https://aws.amazon.com/ec2/instance-types/c6a/) (4x AMD EPYC 7R13)
|
|
||||||
* Ubuntu 22.04 20230303 (ami-0122295b0eb922138)
|
|
||||||
* Node.js 16.19.1
|
|
||||||
|
|
||||||
### ARM64
|
|
||||||
|
|
||||||
* AWS EC2 us-east-2 [c7g.xlarge](https://aws.amazon.com/ec2/instance-types/c7g/) (4x ARM Graviton3)
|
|
||||||
* Ubuntu 22.04 20230303 (ami-0af198159897e7a29)
|
|
||||||
* Node.js 16.19.1
|
|
||||||
|
|
||||||
## Task: JPEG
|
|
||||||
|
|
||||||
Decompress a 2725x2225 JPEG image,
|
|
||||||
resize to 720x588 using Lanczos 3 resampling (where available),
|
|
||||||
then compress to JPEG at a "quality" setting of 80.
|
|
||||||
|
|
||||||
Note: jimp does not support Lanczos 3, bicubic resampling used instead.
|
|
||||||
|
|
||||||
#### Results: JPEG (AMD64)
|
|
||||||
|
|
||||||
| Module | Input | Output | Ops/sec | Speed-up |
|
|
||||||
| :----------------- | :----- | :----- | ------: | -------: |
|
|
||||||
| jimp | buffer | buffer | 0.84 | 1.0 |
|
|
||||||
| squoosh-cli | file | file | 1.07 | 1.3 |
|
|
||||||
| squoosh-lib | buffer | buffer | 1.82 | 2.2 |
|
|
||||||
| gm | buffer | buffer | 8.41 | 10.0 |
|
|
||||||
| gm | file | file | 8.45 | 10.0 |
|
|
||||||
| imagemagick | file | file | 8.77 | 10.4 |
|
|
||||||
| sharp | stream | stream | 36.36 | 43.3 |
|
|
||||||
| sharp | file | file | 38.67 | 46.0 |
|
|
||||||
| sharp | buffer | buffer | 39.44 | 47.0 |
|
|
||||||
|
|
||||||
#### Results: JPEG (ARM64)
|
|
||||||
|
|
||||||
| Module | Input | Output | Ops/sec | Speed-up |
|
|
||||||
| :----------------- | :----- | :----- | ------: | -------: |
|
|
||||||
| jimp | buffer | buffer | 1.02 | 1.0 |
|
|
||||||
| squoosh-cli | file | file | 1.11 | 1.1 |
|
|
||||||
| squoosh-lib | buffer | buffer | 2.08 | 2.0 |
|
|
||||||
| gm | buffer | buffer | 8.80 | 8.6 |
|
|
||||||
| gm | file | file | 10.05 | 9.9 |
|
|
||||||
| imagemagick | file | file | 10.28 | 10.1 |
|
|
||||||
| sharp | stream | stream | 26.87 | 26.3 |
|
|
||||||
| sharp | file | file | 27.88 | 27.3 |
|
|
||||||
| sharp | buffer | buffer | 28.40 | 27.8 |
|
|
||||||
|
|
||||||
## Task: PNG
|
|
||||||
|
|
||||||
Decompress a 2048x1536 RGBA PNG image,
|
|
||||||
premultiply the alpha channel,
|
|
||||||
resize to 720x540 using Lanczos 3 resampling (where available),
|
|
||||||
unpremultiply then compress as PNG with a "default" zlib compression level of 6
|
|
||||||
and without adaptive filtering.
|
|
||||||
|
|
||||||
Note: jimp does not support premultiply/unpremultiply.
|
|
||||||
|
|
||||||
### Results: PNG (AMD64)
|
|
||||||
|
|
||||||
| Module | Input | Output | Ops/sec | Speed-up |
|
|
||||||
| :----------------- | :----- | :----- | ------: | -------: |
|
|
||||||
| squoosh-cli | file | file | 0.40 | 1.0 |
|
|
||||||
| squoosh-lib | buffer | buffer | 0.47 | 1.2 |
|
|
||||||
| gm | file | file | 6.47 | 16.2 |
|
|
||||||
| jimp | buffer | buffer | 6.60 | 16.5 |
|
|
||||||
| imagemagick | file | file | 7.08 | 17.7 |
|
|
||||||
| sharp | file | file | 17.80 | 44.5 |
|
|
||||||
| sharp | buffer | buffer | 18.02 | 45.0 |
|
|
||||||
|
|
||||||
### Results: PNG (ARM64)
|
|
||||||
|
|
||||||
| Module | Input | Output | Ops/sec | Speed-up |
|
|
||||||
| :----------------- | :----- | :----- | ------: | -------: |
|
|
||||||
| squoosh-cli | file | file | 0.40 | 1.0 |
|
|
||||||
| squoosh-lib | buffer | buffer | 0.48 | 1.2 |
|
|
||||||
| gm | file | file | 7.20 | 18.0 |
|
|
||||||
| jimp | buffer | buffer | 7.62 | 19.1 |
|
|
||||||
| imagemagick | file | file | 7.96 | 19.9 |
|
|
||||||
| sharp | file | file | 12.97 | 32.4 |
|
|
||||||
| sharp | buffer | buffer | 13.12 | 32.8 |
|
|
||||||
|
|
||||||
## Running the benchmark test
|
|
||||||
|
|
||||||
Requires Docker.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git clone https://github.com/lovell/sharp.git
|
|
||||||
cd sharp/test/bench
|
|
||||||
./run-with-docker.sh
|
|
||||||
```
|
|
||||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 508 B After Width: | Height: | Size: 508 B |
@@ -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
|
||||||
@@ -275,3 +275,45 @@ GitHub: https://github.com/LachlanNewman
|
|||||||
|
|
||||||
Name: BJJ
|
Name: BJJ
|
||||||
GitHub: https://github.com/bianjunjie1981
|
GitHub: https://github.com/bianjunjie1981
|
||||||
|
|
||||||
|
Name: Dennis Beatty
|
||||||
|
GitHub: https://github.com/dnsbty
|
||||||
|
|
||||||
|
Name: Ingvar Stepanyan
|
||||||
|
GitHub: https://github.com/RReverser
|
||||||
|
|
||||||
|
Name: Tamás András Horváth
|
||||||
|
GitHub: https://github.com/icetee
|
||||||
|
|
||||||
|
Name: Aaron Che
|
||||||
|
GitHub: https://github.com/yolopunk
|
||||||
|
|
||||||
|
Name: Mert Alev
|
||||||
|
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
|
||||||
|
|
||||||
|
Name: Sumit D
|
||||||
|
GitHub: https://github.com/sumitd2
|
||||||
|
|
||||||
|
Name: Caleb Meredith
|
||||||
|
GitHub: https://github.com/calebmer
|
||||||
|
|
||||||
|
Name: Don Denton
|
||||||
|
GitHub: https://github.com/happycollision
|
||||||
|
|
||||||
|
Name: Florent Zabera
|
||||||
|
GitHub: https://github.com/florentzabera
|
||||||
|
|
||||||
|
Name: Quentin Pinçon
|
||||||
|
GitHub: https://github.com/qpincon
|
||||||
4
docs/public/robots.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow:
|
||||||
|
|
||||||
|
Sitemap: https://sharp.pixelplumbing.com/sitemap-index.xml
|
||||||
|
Before Width: | Height: | Size: 929 B After Width: | Height: | Size: 929 B |
5
docs/public/sharp-logo.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||||
|
<!-- Creative Commons CC0 1.0 Universal Public Domain Dedication -->
|
||||||
|
<path fill="none" stroke="#9c0" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66M451.441 438.66V238.484M451.441 88.363v171.572l178.725-23.917M270.323 255.602V477.22M272.71 634.17V462.591L93.984 486.515"/>
|
||||||
|
<path fill="none" stroke="#090" stroke-width="80" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 508 B |
@@ -1,2 +0,0 @@
|
|||||||
User-agent: *
|
|
||||||
Disallow:
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const { extractDescription, extractKeywords, extractParameters } = require('./extract');
|
|
||||||
|
|
||||||
const searchIndex = [];
|
|
||||||
|
|
||||||
// Install
|
|
||||||
const contents = fs.readFileSync(path.join(__dirname, '..', 'install.md'), 'utf8');
|
|
||||||
const matches = contents.matchAll(
|
|
||||||
/## (?<title>[A-Za-z0-9 ]+)\n\n(?<body>[^#]+)/gs
|
|
||||||
);
|
|
||||||
for (const match of matches) {
|
|
||||||
const { title, body } = match.groups;
|
|
||||||
const description = extractDescription(body);
|
|
||||||
|
|
||||||
searchIndex.push({
|
|
||||||
t: title,
|
|
||||||
d: description,
|
|
||||||
k: extractKeywords(`${title} ${description}`),
|
|
||||||
l: `/install#${title.toLowerCase().replace(/ /g, '-')}`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// API
|
|
||||||
[
|
|
||||||
'constructor',
|
|
||||||
'input',
|
|
||||||
'output',
|
|
||||||
'resize',
|
|
||||||
'composite',
|
|
||||||
'operation',
|
|
||||||
'channel',
|
|
||||||
'colour',
|
|
||||||
'utility'
|
|
||||||
].forEach((section) => {
|
|
||||||
const contents = fs.readFileSync(path.join(__dirname, '..', `api-${section}.md`), 'utf8');
|
|
||||||
const matches = contents.matchAll(
|
|
||||||
/## (?<title>[A-Za-z]+)\n[^\n]+\n(?<firstparagraph>.+?)\n\n.+?(?<parameters>\| Param .+?\n\n)?\*\*Example/gs
|
|
||||||
);
|
|
||||||
for (const match of matches) {
|
|
||||||
const { title, firstparagraph, parameters } = match.groups;
|
|
||||||
const description = firstparagraph.startsWith('###')
|
|
||||||
? 'Constructor'
|
|
||||||
: extractDescription(firstparagraph);
|
|
||||||
const parameterNames = parameters ? extractParameters(parameters) : '';
|
|
||||||
|
|
||||||
searchIndex.push({
|
|
||||||
t: title,
|
|
||||||
d: description,
|
|
||||||
k: extractKeywords(`${title} ${description} ${parameterNames}`),
|
|
||||||
l: `/api-${section}#${title.toLowerCase()}`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(__dirname, '..', 'search-index.json'),
|
|
||||||
JSON.stringify(searchIndex)
|
|
||||||
);
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const stopWords = require('./stop-words');
|
|
||||||
|
|
||||||
const extractDescription = (str) =>
|
|
||||||
str
|
|
||||||
.replace(/### Examples.*/sg, '')
|
|
||||||
.replace(/\(http[^)]+/g, '')
|
|
||||||
.replace(/\s+/g, ' ')
|
|
||||||
.replace(/[^A-Za-z0-9_/\-,. ]/g, '')
|
|
||||||
.replace(/\s+/g, ' ')
|
|
||||||
.substring(0, 200)
|
|
||||||
.trim();
|
|
||||||
|
|
||||||
const extractParameters = (str) =>
|
|
||||||
[...str.matchAll(/options\.(?<name>[^.`\] ]+)/gs)]
|
|
||||||
.map((match) => match.groups.name)
|
|
||||||
.map((name) => name.replace(/([A-Z])/g, ' $1').toLowerCase())
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
const extractKeywords = (str) =>
|
|
||||||
[
|
|
||||||
...new Set(
|
|
||||||
str
|
|
||||||
.split(/[ -/]/)
|
|
||||||
.map((word) => word.toLowerCase().replace(/[^a-z]/g, ''))
|
|
||||||
.filter((word) => word.length > 2 && word.length < 15 && !stopWords.includes(word))
|
|
||||||
)
|
|
||||||
].join(' ');
|
|
||||||
|
|
||||||
module.exports = { extractDescription, extractKeywords, extractParameters };
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
// Copyright 2013 Lovell Fuller and others.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = [
|
|
||||||
'about',
|
|
||||||
'after',
|
|
||||||
'all',
|
|
||||||
'allows',
|
|
||||||
'already',
|
|
||||||
'also',
|
|
||||||
'alternative',
|
|
||||||
'always',
|
|
||||||
'and',
|
|
||||||
'any',
|
|
||||||
'are',
|
|
||||||
'available',
|
|
||||||
'based',
|
|
||||||
'been',
|
|
||||||
'before',
|
|
||||||
'best',
|
|
||||||
'both',
|
|
||||||
'call',
|
|
||||||
'callback',
|
|
||||||
'can',
|
|
||||||
'containing',
|
|
||||||
'contains',
|
|
||||||
'created',
|
|
||||||
'current',
|
|
||||||
'date',
|
|
||||||
'default',
|
|
||||||
'does',
|
|
||||||
'each',
|
|
||||||
'either',
|
|
||||||
'ensure',
|
|
||||||
'entirely',
|
|
||||||
'etc',
|
|
||||||
'every',
|
|
||||||
'except',
|
|
||||||
'following',
|
|
||||||
'for',
|
|
||||||
'from',
|
|
||||||
'get',
|
|
||||||
'gets',
|
|
||||||
'given',
|
|
||||||
'has',
|
|
||||||
'have',
|
|
||||||
'how',
|
|
||||||
'image',
|
|
||||||
'implies',
|
|
||||||
'include',
|
|
||||||
'including',
|
|
||||||
'involve',
|
|
||||||
'its',
|
|
||||||
'last',
|
|
||||||
'least',
|
|
||||||
'lots',
|
|
||||||
'make',
|
|
||||||
'may',
|
|
||||||
'more',
|
|
||||||
'most',
|
|
||||||
'much',
|
|
||||||
'must',
|
|
||||||
'non',
|
|
||||||
'not',
|
|
||||||
'now',
|
|
||||||
'occur',
|
|
||||||
'occurs',
|
|
||||||
'one',
|
|
||||||
'options',
|
|
||||||
'other',
|
|
||||||
'out',
|
|
||||||
'over',
|
|
||||||
'part',
|
|
||||||
'perform',
|
|
||||||
'performs',
|
|
||||||
'please',
|
|
||||||
'pre',
|
|
||||||
'previously',
|
|
||||||
'produce',
|
|
||||||
'provide',
|
|
||||||
'provided',
|
|
||||||
'ready',
|
|
||||||
'requires',
|
|
||||||
'requiresharp',
|
|
||||||
'returned',
|
|
||||||
'run',
|
|
||||||
'same',
|
|
||||||
'see',
|
|
||||||
'set',
|
|
||||||
'sets',
|
|
||||||
'sharp',
|
|
||||||
'should',
|
|
||||||
'since',
|
|
||||||
'site',
|
|
||||||
'some',
|
|
||||||
'specified',
|
|
||||||
'spelling',
|
|
||||||
'such',
|
|
||||||
'support',
|
|
||||||
'supported',
|
|
||||||
'sure',
|
|
||||||
'take',
|
|
||||||
'task',
|
|
||||||
'than',
|
|
||||||
'that',
|
|
||||||
'the',
|
|
||||||
'their',
|
|
||||||
'then',
|
|
||||||
'there',
|
|
||||||
'therefore',
|
|
||||||
'these',
|
|
||||||
'this',
|
|
||||||
'under',
|
|
||||||
'unless',
|
|
||||||
'unmaintained',
|
|
||||||
'unsuitable',
|
|
||||||
'until',
|
|
||||||
'use',
|
|
||||||
'used',
|
|
||||||
'using',
|
|
||||||
'value',
|
|
||||||
'values',
|
|
||||||
'via',
|
|
||||||
'were',
|
|
||||||
'when',
|
|
||||||
'which',
|
|
||||||
'while',
|
|
||||||
'will',
|
|
||||||
'with',
|
|
||||||
'without',
|
|
||||||
'you',
|
|
||||||
'your'
|
|
||||||
];
|
|
||||||
5
docs/src/assets/sharp-logo.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||||
|
<!-- Creative Commons CC0 1.0 Universal Public Domain Dedication -->
|
||||||
|
<path fill="none" stroke="#9c0" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66M451.441 438.66V238.484M451.441 88.363v171.572l178.725-23.917M270.323 255.602V477.22M272.71 634.17V462.591L93.984 486.515"/>
|
||||||
|
<path fill="none" stroke="#090" stroke-width="80" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 508 B |
7
docs/src/content.config.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineCollection } from 'astro:content';
|
||||||
|
import { docsLoader } from '@astrojs/starlight/loaders';
|
||||||
|
import { docsSchema } from '@astrojs/starlight/schema';
|
||||||
|
|
||||||
|
export const collections = {
|
||||||
|
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
|
||||||
|
};
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/channel.js
|
||||||
|
title: Channel manipulation
|
||||||
|
---
|
||||||
|
|
||||||
## removeAlpha
|
## removeAlpha
|
||||||
> removeAlpha() ⇒ <code>Sharp</code>
|
> removeAlpha() ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
Remove alpha channels, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
|
|
||||||
See also [flatten](/api-operation#flatten).
|
See also [flatten](/api-operation#flatten).
|
||||||
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
## tint
|
---
|
||||||
> tint(rgb) ⇒ <code>Sharp</code>
|
# This file was auto-generated from JSDoc in lib/colour.js
|
||||||
|
title: Colour manipulation
|
||||||
|
---
|
||||||
|
|
||||||
Tint the image using the provided chroma while preserving the image luminance.
|
## tint
|
||||||
|
> tint(tint) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Tint the image using the provided colour.
|
||||||
An alpha channel may be present and will be unchanged by the operation.
|
An alpha channel may be present and will be unchanged by the operation.
|
||||||
|
|
||||||
|
|
||||||
@@ -12,7 +17,7 @@ An alpha channel may be present and will be unchanged by the operation.
|
|||||||
|
|
||||||
| Param | Type | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| rgb | <code>string</code> \| <code>Object</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values. |
|
| tint | <code>string</code> \| <code>Object</code> | Parsed by the [color](https://www.npmjs.org/package/color) module. |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -27,9 +32,9 @@ const output = await sharp(input)
|
|||||||
|
|
||||||
Convert to 8-bit greyscale; 256 shades of grey.
|
Convert to 8-bit greyscale; 256 shades of grey.
|
||||||
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||||
By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
||||||
This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
||||||
which will produce an output image containing one color channel.
|
which will produce an output image containing one colour channel.
|
||||||
An alpha channel may be present, and will be unchanged by the operation.
|
An alpha channel may be present, and will be unchanged by the operation.
|
||||||
|
|
||||||
|
|
||||||
@@ -66,8 +71,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**:
|
||||||
|
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/composite.js
|
||||||
|
title: Compositing images
|
||||||
|
---
|
||||||
|
|
||||||
## composite
|
## composite
|
||||||
> composite(images) ⇒ <code>Sharp</code>
|
> composite(images) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
@@ -6,8 +11,8 @@ Composite image(s) over the processed (resized, extracted etc.) image.
|
|||||||
The images to composite must be the same size or smaller than the processed image.
|
The images to composite must be the same size or smaller than the processed image.
|
||||||
If both `top` and `left` options are provided, they take precedence over `gravity`.
|
If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||||
|
|
||||||
Any resize, rotate or extract operations in the same processing pipeline
|
Other operations in the same processing pipeline (e.g. resize, rotate, flip,
|
||||||
will always be applied to the input image before composition.
|
flop, extract) will always be applied to the input image before composition.
|
||||||
|
|
||||||
The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||||
`dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
`dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||||
@@ -46,6 +51,7 @@ and https://www.cairographics.org/operators/
|
|||||||
| [images[].input.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
| [images[].input.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
||||||
| [images[].input.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`. |
|
| [images[].input.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`. |
|
||||||
| [images[].input.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
| [images[].input.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
||||||
|
| [images[].autoOrient] | <code>Boolean</code> | <code>false</code> | set to true to use EXIF orientation data, if present, to orient the image. |
|
||||||
| [images[].blend] | <code>String</code> | <code>'over'</code> | how to blend this image with the image below. |
|
| [images[].blend] | <code>String</code> | <code>'over'</code> | how to blend this image with the image below. |
|
||||||
| [images[].gravity] | <code>String</code> | <code>'centre'</code> | gravity at which to place the overlay. |
|
| [images[].gravity] | <code>String</code> | <code>'centre'</code> | gravity at which to place the overlay. |
|
||||||
| [images[].top] | <code>Number</code> | | the pixel offset from the top edge. |
|
| [images[].top] | <code>Number</code> | | the pixel offset from the top edge. |
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/constructor.js
|
||||||
|
title: Constructor
|
||||||
|
---
|
||||||
|
|
||||||
## Sharp
|
## Sharp
|
||||||
> Sharp
|
> Sharp
|
||||||
|
|
||||||
@@ -17,6 +22,10 @@ Non-critical problems encountered during processing are emitted as `warning` eve
|
|||||||
|
|
||||||
Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||||
|
|
||||||
|
When loading more than one page/frame of an animated image,
|
||||||
|
these are combined as a vertically-stacked "toilet roll" image
|
||||||
|
where the overall height is the `pageHeight` multiplied by the number of `pages`.
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
|
|
||||||
- <code>Error</code> Invalid parameters
|
- <code>Error</code> Invalid parameters
|
||||||
@@ -24,11 +33,12 @@ Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_st
|
|||||||
|
|
||||||
| Param | Type | Default | Description |
|
| Param | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| [input] | <code>Buffer</code> \| <code>ArrayBuffer</code> \| <code>Uint8Array</code> \| <code>Uint8ClampedArray</code> \| <code>Int8Array</code> \| <code>Uint16Array</code> \| <code>Int16Array</code> \| <code>Uint32Array</code> \| <code>Int32Array</code> \| <code>Float32Array</code> \| <code>Float64Array</code> \| <code>string</code> | | if present, can be a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or a TypedArray containing raw pixel image data, or a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file. JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present. |
|
| [input] | <code>Buffer</code> \| <code>ArrayBuffer</code> \| <code>Uint8Array</code> \| <code>Uint8ClampedArray</code> \| <code>Int8Array</code> \| <code>Uint16Array</code> \| <code>Int16Array</code> \| <code>Uint32Array</code> \| <code>Int32Array</code> \| <code>Float32Array</code> \| <code>Float64Array</code> \| <code>string</code> \| <code>Array</code> | | if present, can be a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or a TypedArray containing raw pixel image data, or a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file. An array of inputs can be provided, and these will be joined together. JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present. |
|
||||||
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||||
| [options.failOn] | <code>string</code> | <code>"'warning'"</code> | when to abort processing of invalid pixel data, one of (in order of sensitivity): 'none' (least), 'truncated', 'error' or 'warning' (most), higher levels imply lower levels, invalid metadata will always abort. |
|
| [options.failOn] | <code>string</code> | <code>"'warning'"</code> | When to abort processing of invalid pixel data, one of (in order of sensitivity, least to most): 'none', 'truncated', 'error', 'warning'. Higher levels imply lower levels. Invalid metadata will always abort. |
|
||||||
| [options.limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). |
|
| [options.limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). |
|
||||||
| [options.unlimited] | <code>boolean</code> | <code>false</code> | Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). |
|
| [options.unlimited] | <code>boolean</code> | <code>false</code> | Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). |
|
||||||
|
| [options.autoOrient] | <code>boolean</code> | <code>false</code> | Set this to `true` to rotate/flip the image to match EXIF `Orientation`, if any. |
|
||||||
| [options.sequentialRead] | <code>boolean</code> | <code>true</code> | Set this to `false` to use random access rather than sequential read. Some operations will do this automatically. |
|
| [options.sequentialRead] | <code>boolean</code> | <code>true</code> | Set this to `false` to use random access rather than sequential read. Some operations will do this automatically. |
|
||||||
| [options.density] | <code>number</code> | <code>72</code> | number representing the DPI for vector images in the range 1 to 100000. |
|
| [options.density] | <code>number</code> | <code>72</code> | number representing the DPI for vector images in the range 1 to 100000. |
|
||||||
| [options.ignoreIcc] | <code>number</code> | <code>false</code> | should the embedded ICC profile, if any, be ignored. |
|
| [options.ignoreIcc] | <code>number</code> | <code>false</code> | should the embedded ICC profile, if any, be ignored. |
|
||||||
@@ -36,6 +46,7 @@ Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_st
|
|||||||
| [options.page] | <code>number</code> | <code>0</code> | Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based. |
|
| [options.page] | <code>number</code> | <code>0</code> | Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based. |
|
||||||
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
|
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
|
||||||
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
|
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
|
||||||
|
| [options.pdfBackground] | <code>string</code> \| <code>Object</code> | | Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. |
|
||||||
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`. |
|
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`. |
|
||||||
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
|
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
|
||||||
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
|
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
|
||||||
@@ -62,7 +73,14 @@ Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_st
|
|||||||
| [options.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
| [options.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
||||||
| [options.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. |
|
| [options.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. |
|
||||||
| [options.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
| [options.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
||||||
| [options.text.wrap] | <code>string</code> | <code>"'word'"</code> | word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'. |
|
| [options.text.wrap] | <code>string</code> | <code>"'word'"</code> | word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'. |
|
||||||
|
| [options.join] | <code>Object</code> | | describes how an array of input images should be joined. |
|
||||||
|
| [options.join.across] | <code>number</code> | <code>1</code> | number of images to join horizontally. |
|
||||||
|
| [options.join.animated] | <code>boolean</code> | <code>false</code> | set this to `true` to join the images as an animated image. |
|
||||||
|
| [options.join.shim] | <code>number</code> | <code>0</code> | number of pixels to insert between joined images. |
|
||||||
|
| [options.join.background] | <code>string</code> \| <code>Object</code> | | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||||
|
| [options.join.halign] | <code>string</code> | <code>"'left'"</code> | horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`). |
|
||||||
|
| [options.join.valign] | <code>string</code> | <code>"'top'"</code> | vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`). |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -75,14 +93,16 @@ sharp('input.jpg')
|
|||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
// Read image data from readableStream,
|
// Read image data from remote URL,
|
||||||
// resize to 300 pixels wide,
|
// resize to 300 pixels wide,
|
||||||
// emit an 'info' event with calculated dimensions
|
// emit an 'info' event with calculated dimensions
|
||||||
// and finally write image data to writableStream
|
// and finally write image data to writableStream
|
||||||
var transformer = sharp()
|
const { body } = fetch('https://...');
|
||||||
|
const readableStream = Readable.fromWeb(body);
|
||||||
|
const transformer = sharp()
|
||||||
.resize(300)
|
.resize(300)
|
||||||
.on('info', function(info) {
|
.on('info', ({ height }) => {
|
||||||
console.log('Image height is ' + info.height);
|
console.log(`Image height is ${height}`);
|
||||||
});
|
});
|
||||||
readableStream.pipe(transformer).pipe(writableStream);
|
readableStream.pipe(transformer).pipe(writableStream);
|
||||||
```
|
```
|
||||||
@@ -160,6 +180,22 @@ await sharp({
|
|||||||
}
|
}
|
||||||
}).toFile('text_rgba.png');
|
}).toFile('text_rgba.png');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
// Join four input images as a 2x2 grid with a 4 pixel gutter
|
||||||
|
const data = await sharp(
|
||||||
|
[image1, image2, image3, image4],
|
||||||
|
{ join: { across: 2, shim: 4 } }
|
||||||
|
).toBuffer();
|
||||||
|
```
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
// Generate a two-frame animated image from emoji
|
||||||
|
const images = ['😀', '😛'].map(text => ({
|
||||||
|
text: { text, width: 64, height: 64, channels: 4, rgba: true }
|
||||||
|
}));
|
||||||
|
await sharp(images, { join: { animated: true } }).toFile('out.gif');
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## clone
|
## clone
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/input.js
|
||||||
|
title: Input metadata
|
||||||
|
---
|
||||||
|
|
||||||
## metadata
|
## metadata
|
||||||
> metadata([callback]) ⇒ <code>Promise.<Object></code> \| <code>Sharp</code>
|
> metadata([callback]) ⇒ <code>Promise.<Object></code> \| <code>Sharp</code>
|
||||||
|
|
||||||
@@ -22,15 +27,16 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
- `density`: Number of pixels per inch (DPI), if present
|
- `density`: Number of pixels per inch (DPI), if present
|
||||||
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||||
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
|
- `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
||||||
|
- `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
||||||
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||||
- `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
|
||||||
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||||
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||||
- `pagePrimary`: Number of the primary page in a HEIF image
|
- `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
- `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
- `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||||
- `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
- `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||||
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images
|
||||||
- `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
- `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||||
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||||
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
@@ -42,6 +48,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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -70,15 +77,9 @@ image
|
|||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
// Based on EXIF rotation metadata, get the right-side-up width and height:
|
// Get dimensions taking EXIF Orientation into account.
|
||||||
|
const { autoOrient } = await sharp(input).metadata();
|
||||||
const size = getNormalSize(await sharp(input).metadata());
|
const { width, height } = autoOrient;
|
||||||
|
|
||||||
function getNormalSize({ width, height, orientation }) {
|
|
||||||
return (orientation || 0) >= 5
|
|
||||||
? { width: height, height: width }
|
|
||||||
: { width, height };
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -1,22 +1,26 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/operation.js
|
||||||
|
title: Image operations
|
||||||
|
---
|
||||||
|
|
||||||
## rotate
|
## rotate
|
||||||
> rotate([angle], [options]) ⇒ <code>Sharp</code>
|
> rotate([angle], [options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
Rotate the output image by either an explicit angle
|
Rotate the output image.
|
||||||
or auto-orient based on the EXIF `Orientation` tag.
|
|
||||||
|
|
||||||
If an angle is provided, it is converted to a valid positive degree rotation.
|
The provided angle is converted to a valid positive degree rotation.
|
||||||
For example, `-450` will produce a 270 degree rotation.
|
For example, `-450` will produce a 270 degree rotation.
|
||||||
|
|
||||||
When rotating by an angle other than a multiple of 90,
|
When rotating by an angle other than a multiple of 90,
|
||||||
the background colour can be provided with the `background` option.
|
the background colour can be provided with the `background` option.
|
||||||
|
|
||||||
If no angle is provided, it is determined from the EXIF data.
|
For backwards compatibility, if no angle is provided, `.autoOrient()` will be called.
|
||||||
Mirroring is supported and may infer the use of a flip operation.
|
|
||||||
|
|
||||||
The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
Only one rotation can occur per pipeline (aside from an initial call without
|
||||||
|
arguments to orient via EXIF data). Previous calls to `rotate` in the same
|
||||||
|
pipeline will be ignored.
|
||||||
|
|
||||||
Only one rotation can occur per pipeline.
|
Multi-page images can only be rotated by 180 degrees.
|
||||||
Previous calls to `rotate` in the same pipeline will be ignored.
|
|
||||||
|
|
||||||
Method order is important when rotating, resizing and/or extracting regions,
|
Method order is important when rotating, resizing and/or extracting regions,
|
||||||
for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
||||||
@@ -33,18 +37,6 @@ for example `.rotate(x).extract(y)` will produce a different result to `.extract
|
|||||||
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"\"#000000\""</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"\"#000000\""</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||||
|
|
||||||
**Example**
|
|
||||||
```js
|
|
||||||
const pipeline = sharp()
|
|
||||||
.rotate()
|
|
||||||
.resize(null, 200)
|
|
||||||
.toBuffer(function (err, outputBuffer, info) {
|
|
||||||
// outputBuffer contains 200px high JPEG image data,
|
|
||||||
// auto-rotated using EXIF Orientation tag
|
|
||||||
// info.width and info.height contain the dimensions of the resized image
|
|
||||||
});
|
|
||||||
readableStream.pipe(pipeline);
|
|
||||||
```
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
const rotateThenResize = await sharp(input)
|
const rotateThenResize = await sharp(input)
|
||||||
@@ -58,6 +50,34 @@ const resizeThenRotate = await sharp(input)
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## autoOrient
|
||||||
|
> autoOrient() ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Auto-orient based on the EXIF `Orientation` tag, then remove the tag.
|
||||||
|
Mirroring is supported and may infer the use of a flip operation.
|
||||||
|
|
||||||
|
Previous or subsequent use of `rotate(angle)` and either `flip()` or `flop()`
|
||||||
|
will logically occur after auto-orientation, regardless of call order.
|
||||||
|
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const output = await sharp(input).autoOrient().toBuffer();
|
||||||
|
```
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const pipeline = sharp()
|
||||||
|
.autoOrient()
|
||||||
|
.resize(null, 200)
|
||||||
|
.toBuffer(function (err, outputBuffer, info) {
|
||||||
|
// outputBuffer contains 200px high JPEG image data,
|
||||||
|
// auto-oriented using EXIF Orientation tag
|
||||||
|
// info.width and info.height contain the dimensions of the resized image
|
||||||
|
});
|
||||||
|
readableStream.pipe(pipeline);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## flip
|
## flip
|
||||||
> flip([flip]) ⇒ <code>Sharp</code>
|
> flip([flip]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
@@ -102,7 +122,7 @@ const output = await sharp(input).flop().toBuffer();
|
|||||||
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||||
|
|
||||||
You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||||
By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
||||||
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||||
|
|
||||||
In the case of a 2x2 matrix, the transform is:
|
In the case of a 2x2 matrix, the transform is:
|
||||||
@@ -229,7 +249,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.
|
||||||
|
|
||||||
@@ -243,9 +263,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
|
||||||
@@ -261,6 +284,52 @@ const gaussianBlurred = await sharp(input)
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## dilate
|
||||||
|
> dilate([width]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Expand foreground objects using the dilate morphological operator.
|
||||||
|
|
||||||
|
|
||||||
|
**Throws**:
|
||||||
|
|
||||||
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [width] | <code>Number</code> | <code>1</code> | dilation width in pixels. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const output = await sharp(input)
|
||||||
|
.dilate()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## erode
|
||||||
|
> erode([width]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Shrink foreground objects using the erode morphological operator.
|
||||||
|
|
||||||
|
|
||||||
|
**Throws**:
|
||||||
|
|
||||||
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [width] | <code>Number</code> | <code>1</code> | erosion width in pixels. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const output = await sharp(input)
|
||||||
|
.erode()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## flatten
|
## flatten
|
||||||
> flatten([options]) ⇒ <code>Sharp</code>
|
> flatten([options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
@@ -578,7 +647,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
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/output.js
|
||||||
|
title: Output options
|
||||||
|
---
|
||||||
|
|
||||||
## toFile
|
## toFile
|
||||||
> toFile(fileOut, [callback]) ⇒ <code>Promise.<Object></code>
|
> toFile(fileOut, [callback]) ⇒ <code>Promise.<Object></code>
|
||||||
|
|
||||||
@@ -24,7 +29,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 +64,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.
|
||||||
@@ -111,17 +117,157 @@ await sharp(pixelArray, { raw: { width, height, channels } })
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## keepExif
|
||||||
|
> keepExif() ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Keep all EXIF metadata from the input image in the output image.
|
||||||
|
|
||||||
|
EXIF metadata is unsupported for TIFF output.
|
||||||
|
|
||||||
|
|
||||||
|
**Since**: 0.33.0
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const outputWithExif = await sharp(inputWithExif)
|
||||||
|
.keepExif()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## withExif
|
||||||
|
> withExif(exif) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Set EXIF metadata in the output image, ignoring any EXIF in the input image.
|
||||||
|
|
||||||
|
|
||||||
|
**Throws**:
|
||||||
|
|
||||||
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
**Since**: 0.33.0
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| exif | <code>Object.<string, Object.<string, string>></code> | Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const dataWithExif = await sharp(input)
|
||||||
|
.withExif({
|
||||||
|
IFD0: {
|
||||||
|
Copyright: 'The National Gallery'
|
||||||
|
},
|
||||||
|
IFD3: {
|
||||||
|
GPSLatitudeRef: 'N',
|
||||||
|
GPSLatitude: '51/1 30/1 3230/100',
|
||||||
|
GPSLongitudeRef: 'W',
|
||||||
|
GPSLongitude: '0/1 7/1 4366/100'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## withExifMerge
|
||||||
|
> withExifMerge(exif) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Update EXIF metadata from the input image in the output image.
|
||||||
|
|
||||||
|
|
||||||
|
**Throws**:
|
||||||
|
|
||||||
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
**Since**: 0.33.0
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| exif | <code>Object.<string, Object.<string, string>></code> | Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const dataWithMergedExif = await sharp(inputWithExif)
|
||||||
|
.withExifMerge({
|
||||||
|
IFD0: {
|
||||||
|
Copyright: 'The National Gallery'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## keepIccProfile
|
||||||
|
> keepIccProfile() ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Keep ICC profile from the input image in the output image.
|
||||||
|
|
||||||
|
Where necessary, will attempt to convert the output colour space to match the profile.
|
||||||
|
|
||||||
|
|
||||||
|
**Since**: 0.33.0
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const outputWithIccProfile = await sharp(inputWithIccProfile)
|
||||||
|
.keepIccProfile()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## withIccProfile
|
||||||
|
> withIccProfile(icc, [options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Transform using an ICC profile and attach to the output image.
|
||||||
|
|
||||||
|
This can either be an absolute filesystem path or
|
||||||
|
built-in profile name (`srgb`, `p3`, `cmyk`).
|
||||||
|
|
||||||
|
|
||||||
|
**Throws**:
|
||||||
|
|
||||||
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
**Since**: 0.33.0
|
||||||
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| icc | <code>string</code> | | Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk). |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.attach] | <code>number</code> | <code>true</code> | Should the ICC profile be included in the output image metadata? |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const outputWithP3 = await sharp(input)
|
||||||
|
.withIccProfile('p3')
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## keepMetadata
|
||||||
|
> keepMetadata() ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
|
Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
|
||||||
|
|
||||||
|
The default behaviour, when `keepMetadata` is not used, is to convert to the device-independent
|
||||||
|
sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
||||||
|
|
||||||
|
|
||||||
|
**Since**: 0.33.0
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
const outputWithMetadata = await sharp(inputWithMetadata)
|
||||||
|
.keepMetadata()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
> withMetadata([options]) ⇒ <code>Sharp</code>
|
> withMetadata([options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
Keep most metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
||||||
This will also convert to and add a web-friendly sRGB ICC profile if appropriate,
|
|
||||||
unless a custom output profile is provided.
|
|
||||||
|
|
||||||
The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
|
This will also convert to and add a web-friendly sRGB ICC profile if appropriate.
|
||||||
sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
|
||||||
|
|
||||||
EXIF metadata is unsupported for TIFF output.
|
Allows orientation and density to be set or updated.
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
@@ -129,38 +275,16 @@ EXIF metadata is unsupported for TIFF output.
|
|||||||
- <code>Error</code> Invalid parameters
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
| Param | Type | Default | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| [options] | <code>Object</code> | | |
|
| [options] | <code>Object</code> | |
|
||||||
| [options.orientation] | <code>number</code> | | value between 1 and 8, used to update the EXIF `Orientation` tag. |
|
| [options.orientation] | <code>number</code> | Used to update the EXIF `Orientation` tag, integer between 1 and 8. |
|
||||||
| [options.icc] | <code>string</code> | <code>"'srgb'"</code> | Filesystem path to output ICC profile, relative to `process.cwd()`, defaults to built-in sRGB. |
|
| [options.density] | <code>number</code> | Number of pixels per inch (DPI). |
|
||||||
| [options.exif] | <code>Object.<Object></code> | <code>{}</code> | Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. |
|
|
||||||
| [options.density] | <code>number</code> | | Number of pixels per inch (DPI). |
|
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
sharp('input.jpg')
|
const outputSrgbWithMetadata = await sharp(inputRgbWithMetadata)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toFile('output-with-metadata.jpg')
|
|
||||||
.then(info => { ... });
|
|
||||||
```
|
|
||||||
**Example**
|
|
||||||
```js
|
|
||||||
// Set output EXIF metadata
|
|
||||||
const data = await sharp(input)
|
|
||||||
.withMetadata({
|
|
||||||
exif: {
|
|
||||||
IFD0: {
|
|
||||||
Copyright: 'The National Gallery'
|
|
||||||
},
|
|
||||||
IFD3: {
|
|
||||||
GPSLatitudeRef: 'N',
|
|
||||||
GPSLatitude: '51/1 30/1 3230/100',
|
|
||||||
GPSLongitudeRef: 'W',
|
|
||||||
GPSLongitude: '0/1 7/1 4366/100'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
@@ -249,10 +373,14 @@ const data = await sharp(input)
|
|||||||
|
|
||||||
Use these PNG options for output image.
|
Use these PNG options for output image.
|
||||||
|
|
||||||
By default, PNG output is full colour at 8 or 16 bits per pixel.
|
By default, PNG output is full colour at 8 bits per pixel.
|
||||||
|
|
||||||
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||||
Set `palette` to `true` for slower, indexed PNG output.
|
Set `palette` to `true` for slower, indexed PNG output.
|
||||||
|
|
||||||
|
For 16 bits per pixel output, convert to `rgb16` via
|
||||||
|
[toColourspace](/api-colour#tocolourspace).
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
|
|
||||||
@@ -287,6 +415,14 @@ const data = await sharp(input)
|
|||||||
.png({ palette: true })
|
.png({ palette: true })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
// Output 16 bits per pixel RGB(A)
|
||||||
|
const data = await sharp(input)
|
||||||
|
.toColourspace('rgb16')
|
||||||
|
.png()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## webp
|
## webp
|
||||||
@@ -308,6 +444,7 @@ Use these WebP options for output image.
|
|||||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression mode |
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression mode |
|
||||||
| [options.nearLossless] | <code>boolean</code> | <code>false</code> | use near_lossless compression mode |
|
| [options.nearLossless] | <code>boolean</code> | <code>false</code> | use near_lossless compression mode |
|
||||||
| [options.smartSubsample] | <code>boolean</code> | <code>false</code> | use high quality chroma subsampling |
|
| [options.smartSubsample] | <code>boolean</code> | <code>false</code> | use high quality chroma subsampling |
|
||||||
|
| [options.smartDeblock] | <code>boolean</code> | <code>false</code> | auto-adjust the deblocking filter, can improve low contrast edges (slow) |
|
||||||
| [options.preset] | <code>string</code> | <code>"'default'"</code> | named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text |
|
| [options.preset] | <code>string</code> | <code>"'default'"</code> | named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text |
|
||||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 6 (slowest) |
|
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 6 (slowest) |
|
||||||
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||||
@@ -466,6 +603,7 @@ instead of providing `xres` and `yres` in pixels/mm.
|
|||||||
| [options.yres] | <code>number</code> | <code>1.0</code> | vertical resolution in pixels/mm |
|
| [options.yres] | <code>number</code> | <code>1.0</code> | vertical resolution in pixels/mm |
|
||||||
| [options.resolutionUnit] | <code>string</code> | <code>"'inch'"</code> | resolution unit options: inch, cm |
|
| [options.resolutionUnit] | <code>string</code> | <code>"'inch'"</code> | resolution unit options: inch, cm |
|
||||||
| [options.bitdepth] | <code>number</code> | <code>8</code> | reduce bitdepth to 1, 2 or 4 bit |
|
| [options.bitdepth] | <code>number</code> | <code>8</code> | reduce bitdepth to 1, 2 or 4 bit |
|
||||||
|
| [options.miniswhite] | <code>boolean</code> | <code>false</code> | write 1-bit images as miniswhite |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -486,6 +624,7 @@ sharp('input.svg')
|
|||||||
Use these AVIF options for output image.
|
Use these AVIF options for output image.
|
||||||
|
|
||||||
AVIF image sequences are not supported.
|
AVIF image sequences are not supported.
|
||||||
|
Prebuilt binaries support a bitdepth of 8 only.
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
@@ -501,6 +640,7 @@ AVIF image sequences are not supported.
|
|||||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
||||||
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||||
|
| [options.bitdepth] | <code>number</code> | <code>8</code> | set bitdepth to 8, 10 or 12 bit |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -539,6 +679,7 @@ globally-installed libvips compiled with support for libheif, libde265 and x265.
|
|||||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
||||||
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||||
|
| [options.bitdepth] | <code>number</code> | <code>8</code> | set bitdepth to 8, 10 or 12 bit |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
@@ -559,8 +700,6 @@ Requires libvips compiled with support for libjxl.
|
|||||||
The prebuilt binaries do not include this - see
|
The prebuilt binaries do not include this - see
|
||||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||||
|
|
||||||
Image metadata (EXIF, XMP) is unsupported.
|
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
|
|
||||||
@@ -575,7 +714,9 @@ Image metadata (EXIF, XMP) is unsupported.
|
|||||||
| [options.quality] | <code>number</code> | | calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified |
|
| [options.quality] | <code>number</code> | | calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified |
|
||||||
| [options.decodingTier] | <code>number</code> | <code>0</code> | target decode speed tier, between 0 (highest quality) and 4 (lowest quality) |
|
| [options.decodingTier] | <code>number</code> | <code>0</code> | target decode speed tier, between 0 (highest quality) and 4 (lowest quality) |
|
||||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||||
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 3 (fastest) and 9 (slowest) |
|
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 9 (slowest) |
|
||||||
|
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||||
|
| [options.delay] | <code>number</code> \| <code>Array.<number></code> | | delay(s) between animation frames (in milliseconds) |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -626,10 +767,6 @@ Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed arc
|
|||||||
|
|
||||||
The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
||||||
|
|
||||||
Requires libvips compiled with support for libgsf.
|
|
||||||
The prebuilt binaries do not include this - see
|
|
||||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
|
|
||||||
@@ -644,7 +781,7 @@ The prebuilt binaries do not include this - see
|
|||||||
| [options.angle] | <code>number</code> | <code>0</code> | tile angle of rotation, must be a multiple of 90. |
|
| [options.angle] | <code>number</code> | <code>0</code> | tile angle of rotation, must be a multiple of 90. |
|
||||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"{r: 255, g: 255, b: 255, alpha: 1}"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency. |
|
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"{r: 255, g: 255, b: 255, alpha: 1}"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency. |
|
||||||
| [options.depth] | <code>string</code> | | how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout. |
|
| [options.depth] | <code>string</code> | | how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout. |
|
||||||
| [options.skipBlanks] | <code>number</code> | <code>-1</code> | threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images |
|
| [options.skipBlanks] | <code>number</code> | <code>-1</code> | Threshold to skip tile generation. Range is 0-255 for 8-bit images, 0-65535 for 16-bit images. Default is 5 for `google` layout, -1 (no skip) otherwise. |
|
||||||
| [options.container] | <code>string</code> | <code>"'fs'"</code> | tile container, with value `fs` (filesystem) or `zip` (compressed file). |
|
| [options.container] | <code>string</code> | <code>"'fs'"</code> | tile container, with value `fs` (filesystem) or `zip` (compressed file). |
|
||||||
| [options.layout] | <code>string</code> | <code>"'dz'"</code> | filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`. |
|
| [options.layout] | <code>string</code> | <code>"'dz'"</code> | filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`. |
|
||||||
| [options.centre] | <code>boolean</code> | <code>false</code> | centre image in tile. |
|
| [options.centre] | <code>boolean</code> | <code>false</code> | centre image in tile. |
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/resize.js
|
||||||
|
title: Resizing images
|
||||||
|
---
|
||||||
|
|
||||||
## resize
|
## resize
|
||||||
> resize([width], [height], [options]) ⇒ <code>Sharp</code>
|
> resize([width], [height], [options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
@@ -21,18 +26,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 +61,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. |
|
||||||
@@ -251,7 +260,7 @@ sharp(input)
|
|||||||
|
|
||||||
|
|
||||||
## trim
|
## trim
|
||||||
> trim(trim) ⇒ <code>Sharp</code>
|
> trim([options]) ⇒ <code>Sharp</code>
|
||||||
|
|
||||||
Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
||||||
|
|
||||||
@@ -259,8 +268,7 @@ Images with an alpha channel will use the combined bounding box of alpha and non
|
|||||||
|
|
||||||
If the result of this operation would trim an image to nothing then no change is made.
|
If the result of this operation would trim an image to nothing then no change is made.
|
||||||
|
|
||||||
The `info` response Object, obtained from callback of `.toFile()` or `.toBuffer()`,
|
The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
|
||||||
|
|
||||||
|
|
||||||
**Throws**:
|
**Throws**:
|
||||||
@@ -270,46 +278,44 @@ will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
|||||||
|
|
||||||
| Param | Type | Default | Description |
|
| Param | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| trim | <code>string</code> \| <code>number</code> \| <code>Object</code> | | the specific background colour to trim, the threshold for doing so or an Object with both. |
|
| [options] | <code>Object</code> | | |
|
||||||
| [trim.background] | <code>string</code> \| <code>Object</code> | <code>"'top-left pixel'"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel. |
|
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"'top-left pixel'"</code> | Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel. |
|
||||||
| [trim.threshold] | <code>number</code> | <code>10</code> | the allowed difference from the above colour, a positive number. |
|
| [options.threshold] | <code>number</code> | <code>10</code> | Allowed difference from the above colour, a positive number. |
|
||||||
|
| [options.lineArt] | <code>boolean</code> | <code>false</code> | Does the input more closely resemble line art (e.g. vector) rather than being photographic? |
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
// Trim pixels with a colour similar to that of the top-left pixel.
|
// Trim pixels with a colour similar to that of the top-left pixel.
|
||||||
sharp(input)
|
await sharp(input)
|
||||||
.trim()
|
.trim()
|
||||||
.toFile(output, function(err, info) {
|
.toFile(output);
|
||||||
...
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
// Trim pixels with the exact same colour as that of the top-left pixel.
|
// Trim pixels with the exact same colour as that of the top-left pixel.
|
||||||
sharp(input)
|
await sharp(input)
|
||||||
.trim(0)
|
.trim({
|
||||||
.toFile(output, function(err, info) {
|
threshold: 0
|
||||||
...
|
})
|
||||||
});
|
.toFile(output);
|
||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
// Trim only pixels with a similar colour to red.
|
// Assume input is line art and trim only pixels with a similar colour to red.
|
||||||
sharp(input)
|
const output = await sharp(input)
|
||||||
.trim("#FF0000")
|
.trim({
|
||||||
.toFile(output, function(err, info) {
|
background: "#FF0000",
|
||||||
...
|
lineArt: true
|
||||||
});
|
})
|
||||||
|
.toBuffer();
|
||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
// Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
// Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
||||||
sharp(input)
|
const output = await sharp(input)
|
||||||
.trim({
|
.trim({
|
||||||
background: "yellow",
|
background: "yellow",
|
||||||
threshold: 42,
|
threshold: 42,
|
||||||
})
|
})
|
||||||
.toFile(output, function(err, info) {
|
.toBuffer();
|
||||||
...
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
|
---
|
||||||
|
# This file was auto-generated from JSDoc in lib/utility.js
|
||||||
|
title: Global properties
|
||||||
|
---
|
||||||
|
|
||||||
## versions
|
## versions
|
||||||
> versions
|
> versions
|
||||||
|
|
||||||
An Object containing the version numbers of sharp, libvips and its dependencies.
|
An Object containing the version numbers of sharp, libvips
|
||||||
|
and (when using prebuilt binaries) its dependencies.
|
||||||
|
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
@@ -150,7 +156,7 @@ const counters = sharp.counters(); // { queue: 2, process: 4 }
|
|||||||
> simd([simd]) ⇒ <code>boolean</code>
|
> simd([simd]) ⇒ <code>boolean</code>
|
||||||
|
|
||||||
Get and set use of SIMD vector unit instructions.
|
Get and set use of SIMD vector unit instructions.
|
||||||
Requires libvips to have been compiled with liborc support.
|
Requires libvips to have been compiled with highway support.
|
||||||
|
|
||||||
Improves the performance of `resize`, `blur` and `sharpen` operations
|
Improves the performance of `resize`, `blur` and `sharpen` operations
|
||||||
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||||
@@ -164,12 +170,12 @@ by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM N
|
|||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
const simd = sharp.simd();
|
const simd = sharp.simd();
|
||||||
// simd is `true` if the runtime use of liborc is currently enabled
|
// simd is `true` if the runtime use of highway is currently enabled
|
||||||
```
|
```
|
||||||
**Example**
|
**Example**
|
||||||
```js
|
```js
|
||||||
const simd = sharp.simd(false);
|
const simd = sharp.simd(false);
|
||||||
// prevent libvips from using liborc at runtime
|
// prevent libvips from using highway at runtime
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -1,12 +1,186 @@
|
|||||||
# Changelog
|
---
|
||||||
|
title: Changelog
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.34 - *hat*
|
||||||
|
|
||||||
|
Requires libvips v8.16.1
|
||||||
|
|
||||||
|
### v0.34.1 - 7th April 2025
|
||||||
|
|
||||||
|
* TypeScript: Ensure new `autoOrient` property is optional.
|
||||||
|
[#4362](https://github.com/lovell/sharp/pull/4362)
|
||||||
|
[@styfle](https://github.com/styfle)
|
||||||
|
|
||||||
|
### v0.34.0 - 4th April 2025
|
||||||
|
|
||||||
|
* Breaking: Support array of input images to be joined or animated.
|
||||||
|
[#1580](https://github.com/lovell/sharp/issues/1580)
|
||||||
|
|
||||||
|
* Breaking: Ensure `removeAlpha` removes all alpha channels.
|
||||||
|
[#2266](https://github.com/lovell/sharp/issues/2266)
|
||||||
|
|
||||||
|
* Breaking: Non-animated GIF output defaults to no-loop instead of loop-forever.
|
||||||
|
[#3394](https://github.com/lovell/sharp/issues/3394)
|
||||||
|
|
||||||
|
* Breaking: Support `info.size` on wide-character systems via upgrade to C++17.
|
||||||
|
[#3943](https://github.com/lovell/sharp/issues/3943)
|
||||||
|
|
||||||
|
* Breaking: Ensure `background` metadata can be parsed by `color` package.
|
||||||
|
[#4090](https://github.com/lovell/sharp/issues/4090)
|
||||||
|
|
||||||
|
* Add `isPalette` and `bitsPerSample` to metadata, deprecate `paletteBitDepth`.
|
||||||
|
|
||||||
|
* Expose WebP `smartDeblock` output option.
|
||||||
|
|
||||||
|
* Prevent use of linux-x64 binaries with v1 microarchitecture.
|
||||||
|
|
||||||
|
* Add `autoOrient` operation and constructor option.
|
||||||
|
[#4151](https://github.com/lovell/sharp/pull/4151)
|
||||||
|
[@happycollision](https://github.com/happycollision)
|
||||||
|
|
||||||
|
* TypeScript: Ensure channel counts use the correct range.
|
||||||
|
[#4197](https://github.com/lovell/sharp/pull/4197)
|
||||||
|
[@DavidVaness](https://github.com/DavidVaness)
|
||||||
|
|
||||||
|
* Improve support for ppc64le architecture.
|
||||||
|
[#4203](https://github.com/lovell/sharp/pull/4203)
|
||||||
|
[@sumitd2](https://github.com/sumitd2)
|
||||||
|
|
||||||
|
* Add `pdfBackground` constructor property.
|
||||||
|
[#4207](https://github.com/lovell/sharp/pull/4207)
|
||||||
|
[@calebmer](https://github.com/calebmer)
|
||||||
|
|
||||||
|
* Expose erode and dilate operations.
|
||||||
|
[#4243](https://github.com/lovell/sharp/pull/4243)
|
||||||
|
[@qpincon](https://github.com/qpincon)
|
||||||
|
|
||||||
|
* Add support for RGBE images. Requires libvips compiled with radiance support.
|
||||||
|
[#4316](https://github.com/lovell/sharp/pull/4316)
|
||||||
|
[@florentzabera](https://github.com/florentzabera)
|
||||||
|
|
||||||
|
* Allow wide-gamut HEIF output at higher bitdepths.
|
||||||
|
[#4344](https://github.com/lovell/sharp/issues/4344)
|
||||||
|
|
||||||
## v0.33 - *gauge*
|
## v0.33 - *gauge*
|
||||||
|
|
||||||
Requires libvips v8.14.5
|
Requires libvips v8.15.3
|
||||||
|
|
||||||
### v0.33.0 - TBD
|
### v0.33.5 - 16th August 2024
|
||||||
|
|
||||||
* Drop support for Node.js 14 and 16, now requires Node.js >= 18.17.0
|
* 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)
|
||||||
|
|
||||||
|
* TypeScript: `chromaSubsampling` metadata is optional.
|
||||||
|
[#4191](https://github.com/lovell/sharp/pull/4191)
|
||||||
|
[@DavidVaness](https://github.com/DavidVaness)
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
* Upgrade to libvips v8.15.2 for upstream bug fixes.
|
||||||
|
|
||||||
|
* Ensure `keepIccProfile` retains P3 and CMYK input profiles.
|
||||||
|
[#3906](https://github.com/lovell/sharp/issues/3906)
|
||||||
|
[#4008](https://github.com/lovell/sharp/issues/4008)
|
||||||
|
|
||||||
|
* Ensure `text.wrap` property can accept `word-char` as value.
|
||||||
|
[#4028](https://github.com/lovell/sharp/pull/4028)
|
||||||
|
[@yolopunk](https://github.com/yolopunk)
|
||||||
|
|
||||||
|
* Ensure `clone` takes a deep copy of existing options.
|
||||||
|
[#4029](https://github.com/lovell/sharp/issues/4029)
|
||||||
|
|
||||||
|
* Add `bitdepth` option to `heif` output (prebuilt binaries support 8-bit only).
|
||||||
|
[#4036](https://github.com/lovell/sharp/pull/4036)
|
||||||
|
[@mertalev](https://github.com/mertalev)
|
||||||
|
|
||||||
|
### v0.33.2 - 12th January 2024
|
||||||
|
|
||||||
|
* Upgrade to libvips v8.15.1 for upstream bug fixes.
|
||||||
|
|
||||||
|
* TypeScript: add definition for `keepMetadata`.
|
||||||
|
[#3914](https://github.com/lovell/sharp/pull/3914)
|
||||||
|
[@abhi0498](https://github.com/abhi0498)
|
||||||
|
|
||||||
|
* Ensure `extend` operation stays sequential when copying (regression in 0.32.0).
|
||||||
|
[#3928](https://github.com/lovell/sharp/issues/3928)
|
||||||
|
|
||||||
|
* Improve error handling for unsupported multi-page rotation.
|
||||||
|
[#3940](https://github.com/lovell/sharp/issues/3940)
|
||||||
|
|
||||||
|
### v0.33.1 - 17th December 2023
|
||||||
|
|
||||||
|
* Add support for Yarn Plug'n'Play filesystem layout.
|
||||||
|
[#3888](https://github.com/lovell/sharp/issues/3888)
|
||||||
|
|
||||||
|
* Emit warning when attempting to use invalid ICC profiles.
|
||||||
|
[#3895](https://github.com/lovell/sharp/issues/3895)
|
||||||
|
|
||||||
|
* Ensure `VIPS_NOVECTOR` environment variable is respected.
|
||||||
|
[#3897](https://github.com/lovell/sharp/pull/3897)
|
||||||
|
[@icetee](https://github.com/icetee)
|
||||||
|
|
||||||
|
### v0.33.0 - 29th November 2023
|
||||||
|
|
||||||
|
* Drop support for Node.js 14 and 16, now requires Node.js ^18.17.0 or >= 20.3.0
|
||||||
|
|
||||||
* Prebuilt binaries distributed via npm registry and installed via package manager.
|
* Prebuilt binaries distributed via npm registry and installed via package manager.
|
||||||
|
|
||||||
@@ -14,12 +188,41 @@ Requires libvips v8.14.5
|
|||||||
|
|
||||||
* Remove `sharp.vendor`.
|
* Remove `sharp.vendor`.
|
||||||
|
|
||||||
|
* Partially deprecate `withMetadata()`, use `withExif()` and `withIccProfile()`.
|
||||||
|
|
||||||
|
* Add experimental support for WebAssembly-based runtimes.
|
||||||
|
[@RReverser](https://github.com/RReverser)
|
||||||
|
|
||||||
|
* Options for `trim` operation must be an Object, add new `lineArt` option.
|
||||||
|
[#2363](https://github.com/lovell/sharp/issues/2363)
|
||||||
|
|
||||||
|
* Improve luminance of `tint` operation with weighting function.
|
||||||
|
[#3338](https://github.com/lovell/sharp/issues/3338)
|
||||||
|
[@jcupitt](https://github.com/jcupitt)
|
||||||
|
|
||||||
|
* Ensure all `Error` objects contain a `stack` property.
|
||||||
|
[#3653](https://github.com/lovell/sharp/issues/3653)
|
||||||
|
|
||||||
* Make `compression` option of `heif` mandatory to help reduce HEIF vs HEIC confusion.
|
* Make `compression` option of `heif` mandatory to help reduce HEIF vs HEIC confusion.
|
||||||
[#3740](https://github.com/lovell/sharp/issues/3740)
|
[#3740](https://github.com/lovell/sharp/issues/3740)
|
||||||
|
|
||||||
* Ensure correct interpretation of 16-bit raw input.
|
* Ensure correct interpretation of 16-bit raw input.
|
||||||
[#3808](https://github.com/lovell/sharp/issues/3808)
|
[#3808](https://github.com/lovell/sharp/issues/3808)
|
||||||
|
|
||||||
|
* Add support for `miniswhite` when using TIFF output.
|
||||||
|
[#3812](https://github.com/lovell/sharp/pull/3812)
|
||||||
|
[@dnsbty](https://github.com/dnsbty)
|
||||||
|
|
||||||
|
* TypeScript: add missing definition for `withMetadata` boolean.
|
||||||
|
[#3823](https://github.com/lovell/sharp/pull/3823)
|
||||||
|
[@uhthomas](https://github.com/uhthomas)
|
||||||
|
|
||||||
|
* Add more fine-grained control over output metadata.
|
||||||
|
[#3824](https://github.com/lovell/sharp/issues/3824)
|
||||||
|
|
||||||
|
* Ensure multi-page extract remains sequential.
|
||||||
|
[#3837](https://github.com/lovell/sharp/issues/3837)
|
||||||
|
|
||||||
## v0.32 - *flow*
|
## v0.32 - *flow*
|
||||||
|
|
||||||
Requires libvips v8.14.5
|
Requires libvips v8.14.5
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
# sharp
|
---
|
||||||
|
title: "High performance Node.js image processing"
|
||||||
|
---
|
||||||
|
|
||||||
<img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
<img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/public/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
||||||
|
|
||||||
The typical use case for this high speed Node.js module
|
The typical use case for this high speed Node-API module
|
||||||
is to convert large images in common formats to
|
is to convert large images in common formats to
|
||||||
smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
|
smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
|
||||||
|
|
||||||
|
It can be used with all JavaScript runtimes
|
||||||
|
that provide support for Node-API v9, including
|
||||||
|
Node.js >= 18.17.0, Deno and Bun.
|
||||||
|
|
||||||
Resizing an image is typically 4x-5x faster than using the
|
Resizing an image is typically 4x-5x faster than using the
|
||||||
quickest ImageMagick and GraphicsMagick settings
|
quickest ImageMagick and GraphicsMagick settings
|
||||||
due to its use of [libvips](https://github.com/libvips/libvips).
|
due to its use of [libvips](https://github.com/libvips/libvips).
|
||||||
@@ -16,10 +22,14 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|||||||
As well as image resizing, operations such as
|
As well as image resizing, operations such as
|
||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern macOS, Windows and Linux systems running Node.js >= 14.15.0
|
Most modern macOS, Windows and Linux systems
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
### Formats
|
```sh
|
||||||
|
npm install sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
## Formats
|
||||||
|
|
||||||
This module supports reading JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG images.
|
This module supports reading JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG images.
|
||||||
|
|
||||||
@@ -33,7 +43,7 @@ Deep Zoom image pyramids can be generated,
|
|||||||
suitable for use with "slippy map" tile viewers like
|
suitable for use with "slippy map" tile viewers like
|
||||||
[OpenSeadragon](https://github.com/openseadragon/openseadragon).
|
[OpenSeadragon](https://github.com/openseadragon/openseadragon).
|
||||||
|
|
||||||
### Fast
|
## Fast
|
||||||
|
|
||||||
This module is powered by the blazingly fast
|
This module is powered by the blazingly fast
|
||||||
[libvips](https://github.com/libvips/libvips) image processing library,
|
[libvips](https://github.com/libvips/libvips) image processing library,
|
||||||
@@ -48,7 +58,7 @@ taking full advantage of multiple CPU cores and L1/L2/L3 cache.
|
|||||||
Everything remains non-blocking thanks to _libuv_,
|
Everything remains non-blocking thanks to _libuv_,
|
||||||
no child processes are spawned and Promises/async/await are supported.
|
no child processes are spawned and Promises/async/await are supported.
|
||||||
|
|
||||||
### Optimal
|
## Optimal
|
||||||
|
|
||||||
The features of `mozjpeg` and `pngquant` can be used
|
The features of `mozjpeg` and `pngquant` can be used
|
||||||
to optimise the file size of JPEG and PNG images respectively,
|
to optimise the file size of JPEG and PNG images respectively,
|
||||||
@@ -67,12 +77,12 @@ The file size of animated GIF output is optimised
|
|||||||
without having to use separate command line tools such as
|
without having to use separate command line tools such as
|
||||||
[gifsicle](https://www.lcdf.org/gifsicle/).
|
[gifsicle](https://www.lcdf.org/gifsicle/).
|
||||||
|
|
||||||
### Contributing
|
## Contributing
|
||||||
|
|
||||||
A [guide for contributors](https://github.com/lovell/sharp/blob/main/.github/CONTRIBUTING.md)
|
A [guide for contributors](https://github.com/lovell/sharp/blob/main/.github/CONTRIBUTING.md)
|
||||||
covers reporting bugs, requesting features and submitting code changes.
|
covers reporting bugs, requesting features and submitting code changes.
|
||||||
|
|
||||||
### Licensing
|
## Licensing
|
||||||
|
|
||||||
Copyright 2013 Lovell Fuller and others.
|
Copyright 2013 Lovell Fuller and others.
|
||||||
|
|
||||||
@@ -1,40 +1,104 @@
|
|||||||
# Installation
|
---
|
||||||
|
title: Installation
|
||||||
|
---
|
||||||
|
|
||||||
|
Works with your choice of JavaScript package manager.
|
||||||
|
|
||||||
|
:::caution
|
||||||
|
Please ensure your package manager is configured to install optional dependencies
|
||||||
|
:::
|
||||||
|
|
||||||
|
If a package manager lockfile must support multiple platforms,
|
||||||
|
please see the [cross-platform](#cross-platform) section
|
||||||
|
to help decide which package manager is appropriate.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install sharp
|
npm install sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pnpm add sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
When using `pnpm`, you may need to add `sharp` to
|
||||||
|
[ignoredBuiltDependencies](https://pnpm.io/package_json#pnpmignoredbuiltdependencies)
|
||||||
|
to silence warnings.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add sharp
|
yarn add sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pnpm add sharp
|
bun add sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
deno run --allow-ffi ...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* Node.js >= 18.17.0
|
* Node-API v9 compatible runtime e.g. Node.js ^18.17.0 or >=20.3.0.
|
||||||
|
|
||||||
## Prebuilt binaries
|
## Prebuilt binaries
|
||||||
|
|
||||||
Ready-compiled sharp and libvips binaries are provided for use on the most common platforms:
|
Ready-compiled sharp and libvips binaries are provided for use on the most common platforms:
|
||||||
|
|
||||||
* macOS x64 (>= 10.13)
|
* macOS x64 (>= 10.15)
|
||||||
* macOS ARM64
|
* macOS ARM64
|
||||||
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
|
* Linux ARM (glibc >= 2.31)
|
||||||
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
|
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
|
||||||
* Linux ARM (glibc >= 2.28)
|
* Linux ppc64 (glibc >= 2.31)
|
||||||
|
* Linux s390x (glibc >= 2.31)
|
||||||
|
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
|
||||||
* Windows x64
|
* Windows x64
|
||||||
* Windows x86
|
* Windows x86
|
||||||
|
|
||||||
This provides support for the
|
This provides support for the
|
||||||
JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats.
|
JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats.
|
||||||
|
|
||||||
|
## Cross-platform
|
||||||
|
|
||||||
|
At install time, package managers will automatically select prebuilt binaries
|
||||||
|
for the current OS platform and CPU architecture, where available.
|
||||||
|
|
||||||
|
Some package managers support multiple platforms and architectures
|
||||||
|
within the same installation tree and/or using the same lockfile.
|
||||||
|
|
||||||
|
### npm v10+
|
||||||
|
|
||||||
|
:::caution
|
||||||
|
npm `package-lock.json` files shared by multiple platforms can cause installation problems due to [npm bug #4828](https://github.com/npm/cli/issues/4828)
|
||||||
|
:::
|
||||||
|
|
||||||
|
Provides limited support via `--os`, `--cpu` and `--libc` flags.
|
||||||
|
|
||||||
|
To support macOS with Intel x64 and ARM64 CPUs:
|
||||||
|
```sh
|
||||||
|
npm install --cpu=x64 --os=darwin sharp
|
||||||
|
npm install --cpu=arm64 --os=darwin sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
npm install --cpu=x64 --os=linux --libc=glibc sharp
|
||||||
|
npm install --cpu=x64 --os=linux --libc=musl sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
### yarn v3+
|
||||||
|
|
||||||
|
Use the [supportedArchitectures](https://yarnpkg.com/configuration/yarnrc#supportedArchitectures) configuration.
|
||||||
|
|
||||||
|
### pnpm v8+
|
||||||
|
|
||||||
|
Use the [supportedArchitectures](https://pnpm.io/package_json#pnpmsupportedarchitectures) configuration.
|
||||||
|
|
||||||
## Custom libvips
|
## Custom libvips
|
||||||
|
|
||||||
To use a custom, globally-installed version of libvips instead of the provided binaries,
|
To use a custom, globally-installed version of libvips instead of the provided binaries,
|
||||||
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
|
||||||
@@ -47,14 +111,19 @@ 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++17 compiler
|
||||||
* [node-addon-api](https://www.npmjs.com/package/node-addon-api)
|
* [node-addon-api](https://www.npmjs.com/package/node-addon-api) version 7+
|
||||||
* [node-gyp](https://github.com/nodejs/node-gyp#installation) and its dependencies
|
* [node-gyp](https://github.com/nodejs/node-gyp#installation) version 9+ and its dependencies
|
||||||
|
|
||||||
There is an install-time check for these dependencies.
|
There is an install-time check for these dependencies.
|
||||||
If `node-addon-api` or `node-gyp` cannot be found, try adding them via:
|
If `node-addon-api` or `node-gyp` cannot be found, try adding them via:
|
||||||
@@ -63,10 +132,29 @@ If `node-addon-api` or `node-gyp` cannot be found, try adding them via:
|
|||||||
npm install --save node-addon-api node-gyp
|
npm install --save node-addon-api node-gyp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When using `pnpm`, you may need to add `sharp` to
|
||||||
|
[onlyBuiltDependencies](https://pnpm.io/package_json#pnpmonlybuiltdependencies)
|
||||||
|
to ensure the installation script can be run.
|
||||||
|
|
||||||
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags
|
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags
|
||||||
(or the `npm_config_platform`, `npm_config_arch` and `npm_config_libc` environment variables)
|
(or the `npm_config_platform`, `npm_config_arch` and `npm_config_libc` environment variables)
|
||||||
can be used to configure the target environment.
|
can be used to configure the target environment.
|
||||||
|
|
||||||
|
## WebAssembly
|
||||||
|
|
||||||
|
Experimental support is provided for runtime environments that provide
|
||||||
|
multi-threaded Wasm via Workers.
|
||||||
|
|
||||||
|
Use in web browsers is unsupported.
|
||||||
|
|
||||||
|
Native text rendering is unsupported.
|
||||||
|
|
||||||
|
[Tile-based output](/api-output#tile) is unsupported.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --cpu=wasm32 sharp
|
||||||
|
```
|
||||||
|
|
||||||
## FreeBSD
|
## FreeBSD
|
||||||
|
|
||||||
The `vips` package must be installed before `npm install` is run.
|
The `vips` package must be installed before `npm install` is run.
|
||||||
@@ -104,15 +192,11 @@ must include binaries for either the linux-x64 or linux-arm64 platforms
|
|||||||
depending on the chosen architecture.
|
depending on the chosen architecture.
|
||||||
|
|
||||||
When building your deployment package on a machine that differs from the target architecture,
|
When building your deployment package on a machine that differs from the target architecture,
|
||||||
you will need to install either `@sharpen/sharp-linux-x64` or `@sharpen/sharp-linux-arm64` package.
|
see the [cross-platform](#cross-platform) section to help decide which package manager is appropriate
|
||||||
|
and how to configure it.
|
||||||
|
|
||||||
```sh
|
Some package managers use symbolic links
|
||||||
npm install --force @sharpen/sharp-linux-x64
|
but AWS Lambda does not support these within deployment packages.
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install --force @sharpen/sharp-linux-arm64
|
|
||||||
```
|
|
||||||
|
|
||||||
To get the best performance select the largest memory available.
|
To get the best performance select the largest memory available.
|
||||||
A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
||||||
@@ -163,7 +247,67 @@ custom:
|
|||||||
- sharp
|
- sharp
|
||||||
packagerOptions:
|
packagerOptions:
|
||||||
scripts:
|
scripts:
|
||||||
- npm install --force @sharpen/sharp-linux-x64
|
- npm install --os=linux --cpu=x64 sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
### electron
|
||||||
|
|
||||||
|
#### electron-builder
|
||||||
|
|
||||||
|
Ensure `sharp` is unpacked from the ASAR archive file using the
|
||||||
|
[asarUnpack](https://www.electron.build/app-builder-lib.interface.platformspecificbuildoptions#asarunpack)
|
||||||
|
option.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"asar": true,
|
||||||
|
"asarUnpack": [
|
||||||
|
"**/node_modules/sharp/**/*",
|
||||||
|
"**/node_modules/@img/**/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### electron-forge
|
||||||
|
|
||||||
|
Ensure `sharp` is unpacked from the ASAR archive file using the
|
||||||
|
[unpack](https://js.electronforge.io/interfaces/_electron_forge_maker_squirrel.InternalOptions.Options.html#asar)
|
||||||
|
option.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"packagerConfig": {
|
||||||
|
"asar": {
|
||||||
|
"unpack": "**/node_modules/{sharp,@img}/**/*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When using `electron-forge` with [Webpack](#webpack),
|
||||||
|
you may also need to add
|
||||||
|
[forge-externals-plugin](https://www.npmjs.com/package/@timfish/forge-externals-plugin).
|
||||||
|
|
||||||
|
### vite
|
||||||
|
|
||||||
|
Ensure `sharp` is excluded from bundling via the
|
||||||
|
[build.rollupOptions](https://vitejs.dev/config/build-options.html)
|
||||||
|
configuration.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
external: [
|
||||||
|
"sharp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## TypeScript
|
## TypeScript
|
||||||
@@ -202,19 +346,6 @@ use the `FONTCONFIG_PATH` environment variable to point to a custom location.
|
|||||||
|
|
||||||
Embedded SVG fonts are unsupported.
|
Embedded SVG fonts are unsupported.
|
||||||
|
|
||||||
## Worker threads
|
|
||||||
|
|
||||||
On some platforms, including glibc-based Linux,
|
|
||||||
the main thread must call `require('sharp')`
|
|
||||||
_before_ worker threads are created.
|
|
||||||
This is to ensure shared libraries remain loaded in memory
|
|
||||||
until after all threads are complete.
|
|
||||||
|
|
||||||
Without this, the following error may occur:
|
|
||||||
```
|
|
||||||
Module did not self-register
|
|
||||||
```
|
|
||||||
|
|
||||||
## Known conflicts
|
## Known conflicts
|
||||||
|
|
||||||
### Canvas and Windows
|
### Canvas and Windows
|
||||||
103
docs/src/content/docs/performance.md
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
---
|
||||||
|
title: Performance
|
||||||
|
---
|
||||||
|
|
||||||
|
A test to benchmark the performance of this module relative to alternatives.
|
||||||
|
|
||||||
|
Greater libvips performance can be expected with caching enabled (default)
|
||||||
|
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
||||||
|
|
||||||
|
The I/O limits of the relevant (de)compression library will generally determine maximum throughput.
|
||||||
|
|
||||||
|
## Contenders
|
||||||
|
|
||||||
|
* [jimp](https://www.npmjs.com/package/jimp) v1.6.0 - Image processing in pure JavaScript.
|
||||||
|
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
||||||
|
* [gm](https://www.npmjs.com/package/gm) v1.25.1 - Fully featured wrapper around GraphicsMagick's `gm` command line utility, but "*has been sunset*".
|
||||||
|
* sharp v0.34.0 / libvips v8.16.1 - Caching within libvips disabled to ensure a fair comparison.
|
||||||
|
|
||||||
|
## Environment
|
||||||
|
|
||||||
|
### AMD64
|
||||||
|
|
||||||
|
* AWS EC2 us-west-2 [c7a.xlarge](https://aws.amazon.com/ec2/instance-types/c7a/) (4x AMD EPYC 9R14)
|
||||||
|
* Ubuntu 24.10 [fad5ba7223f8](https://hub.docker.com/layers/library/ubuntu/24.10/images/sha256-fad5ba7223f8d87179dfa23211d31845d47e07a474ac31ad5258afb606523c0d)
|
||||||
|
* Node.js 22.14.0
|
||||||
|
|
||||||
|
### ARM64
|
||||||
|
|
||||||
|
* AWS EC2 us-west-2 [c8g.xlarge](https://aws.amazon.com/ec2/instance-types/c8g/) (4x ARM Graviton4)
|
||||||
|
* Ubuntu 24.10 [133f2e05cb69](https://hub.docker.com/layers/library/ubuntu/24.10/images/sha256-133f2e05cb6958c3ce7ec870fd5a864558ba780fb7062315b51a23670bff7e76)
|
||||||
|
* Node.js 22.14.0
|
||||||
|
|
||||||
|
## Task: JPEG
|
||||||
|
|
||||||
|
Decompress a 2725x2225 JPEG image,
|
||||||
|
resize to 720x588 using Lanczos 3 resampling (where available),
|
||||||
|
then compress to JPEG at a "quality" setting of 80.
|
||||||
|
|
||||||
|
Note: jimp does not support Lanczos 3, bicubic resampling used instead.
|
||||||
|
|
||||||
|
#### Results: JPEG (AMD64)
|
||||||
|
|
||||||
|
| Module | Input | Output | Ops/sec | Speed-up |
|
||||||
|
| :----------------- | :----- | :----- | ------: | -------: |
|
||||||
|
| jimp | buffer | buffer | 2.35 | 1.0 |
|
||||||
|
| imagemagick | file | file | 10.51 | 4.5 |
|
||||||
|
| gm | buffer | buffer | 11.67 | 5.0 |
|
||||||
|
| gm | file | file | 11.75 | 5.1 |
|
||||||
|
| sharp | stream | stream | 60.72 | 25.8 |
|
||||||
|
| sharp | file | file | 62.37 | 26.5 |
|
||||||
|
| sharp | buffer | buffer | 65.15 | 27.7 |
|
||||||
|
|
||||||
|
#### Results: JPEG (ARM64)
|
||||||
|
|
||||||
|
| Module | Input | Output | Ops/sec | Speed-up |
|
||||||
|
| :----------------- | :----- | :----- | ------: | -------: |
|
||||||
|
| jimp | buffer | buffer | 2.13 | 1.0 |
|
||||||
|
| imagemagick | file | file | 12.95 | 6.1 |
|
||||||
|
| gm | buffer | buffer | 13.53 | 6.4 |
|
||||||
|
| gm | file | file | 13.52 | 6.4 |
|
||||||
|
| sharp | stream | stream | 46.58 | 21.9 |
|
||||||
|
| sharp | file | file | 48.42 | 22.7 |
|
||||||
|
| sharp | buffer | buffer | 50.16 | 23.6 |
|
||||||
|
|
||||||
|
## Task: PNG
|
||||||
|
|
||||||
|
Decompress a 2048x1536 RGBA PNG image,
|
||||||
|
premultiply the alpha channel,
|
||||||
|
resize to 720x540 using Lanczos 3 resampling (where available),
|
||||||
|
unpremultiply then compress as PNG with a "default" zlib compression level of 6
|
||||||
|
and without adaptive filtering.
|
||||||
|
|
||||||
|
Note: jimp does not support premultiply/unpremultiply.
|
||||||
|
|
||||||
|
### Results: PNG (AMD64)
|
||||||
|
|
||||||
|
| Module | Input | Output | Ops/sec | Speed-up |
|
||||||
|
| :----------------- | :----- | :----- | ------: | -------: |
|
||||||
|
| gm | file | file | 8.66 | 1.0 |
|
||||||
|
| imagemagick | file | file | 8.79 | 1.0 |
|
||||||
|
| jimp | buffer | buffer | 11.26 | 1.3 |
|
||||||
|
| sharp | file | file | 27.93 | 3.2 |
|
||||||
|
| sharp | buffer | buffer | 28.69 | 3.3 |
|
||||||
|
|
||||||
|
### Results: PNG (ARM64)
|
||||||
|
|
||||||
|
| Module | Input | Output | Ops/sec | Speed-up |
|
||||||
|
| :----------------- | :----- | :----- | ------: | -------: |
|
||||||
|
| gm | file | file | 9.65 | 1.0 |
|
||||||
|
| imagemagick | file | file | 9.72 | 1.0 |
|
||||||
|
| jimp | buffer | buffer | 10.68 | 1.1 |
|
||||||
|
| sharp | file | file | 23.90 | 2.5 |
|
||||||
|
| sharp | buffer | buffer | 24.48 | 2.5 |
|
||||||
|
|
||||||
|
## Running the benchmark test
|
||||||
|
|
||||||
|
Requires Docker.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/lovell/sharp.git
|
||||||
|
cd sharp/test/bench
|
||||||
|
./run-with-docker.sh
|
||||||
|
```
|
||||||
45
docs/src/styles/custom.css
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
@view-transition {
|
||||||
|
navigation: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--sl-content-width: 60rem;
|
||||||
|
--sl-color-accent-low: #072d00;
|
||||||
|
--sl-color-accent: #247f00;
|
||||||
|
--sl-color-accent-high: #aad7a0;
|
||||||
|
--sl-color-white: #ffffff;
|
||||||
|
--sl-color-gray-1: #eaf0e8;
|
||||||
|
--sl-color-gray-2: #c5cdc3;
|
||||||
|
--sl-color-gray-3: #99a796;
|
||||||
|
--sl-color-gray-4: #4f5c4d;
|
||||||
|
--sl-color-gray-5: #303c2d;
|
||||||
|
--sl-color-gray-6: #1f2a1c;
|
||||||
|
--sl-color-black: #151a13;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-theme="light"] {
|
||||||
|
--sl-color-accent-low: #c0e2b8;
|
||||||
|
--sl-color-accent: #165800;
|
||||||
|
--sl-color-accent-high: #0d3e00;
|
||||||
|
--sl-color-white: #151a13;
|
||||||
|
--sl-color-gray-1: #1f2a1c;
|
||||||
|
--sl-color-gray-2: #303c2d;
|
||||||
|
--sl-color-gray-3: #4f5c4d;
|
||||||
|
--sl-color-gray-4: #82907f;
|
||||||
|
--sl-color-gray-5: #bdc4bb;
|
||||||
|
--sl-color-gray-6: #eaf0e8;
|
||||||
|
--sl-color-gray-7: #f4f7f3;
|
||||||
|
--sl-color-black: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
background-color: var(--sl-color-gray-6);
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-title::after {
|
||||||
|
content: "High performance Node.js image processing";
|
||||||
|
color: var(--sl-color-text);
|
||||||
|
font-size: var(--sl-text-sm);
|
||||||
|
padding-top: 0.3rem;
|
||||||
|
}
|
||||||
5
docs/tsconfig.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extends": "astro/tsconfigs/strict",
|
||||||
|
"include": [".astro/types.d.ts", "**/*"],
|
||||||
|
"exclude": ["dist"]
|
||||||
|
}
|
||||||
@@ -3,34 +3,39 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
|
try {
|
||||||
|
const { useGlobalLibvips, globalLibvipsVersion, log, spawnRebuild } = require('../lib/libvips');
|
||||||
|
|
||||||
const buildFromSource = (msg) => {
|
const buildFromSource = (msg) => {
|
||||||
log(msg);
|
log(msg);
|
||||||
log('Attempting to build from source via node-gyp');
|
log('Attempting to build from source via node-gyp');
|
||||||
try {
|
try {
|
||||||
require('node-addon-api');
|
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;
|
||||||
}
|
}
|
||||||
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
log('See https://sharp.pixelplumbing.com/install#building-from-source');
|
||||||
const status = spawnRebuild();
|
const status = spawnRebuild();
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
process.exit(status);
|
process.exit(status);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (useGlobalLibvips()) {
|
if (useGlobalLibvips(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');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const summary = err.message.split(/\n/).slice(0, 1);
|
||||||
|
console.log(`sharp: skipping install check: ${summary}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const bool = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
* Remove alpha channels, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
*
|
*
|
||||||
* See also {@link /api-operation#flatten|flatten}.
|
* See also {@link /api-operation#flatten|flatten}.
|
||||||
*
|
*
|
||||||
@@ -158,6 +158,7 @@ function bandbool (boolOp) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with channel-related functions.
|
* Decorate the Sharp prototype with channel-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const colourspace = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tint the image using the provided chroma while preserving the image luminance.
|
* Tint the image using the provided colour.
|
||||||
* An alpha channel may be present and will be unchanged by the operation.
|
* An alpha channel may be present and will be unchanged by the operation.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -27,23 +27,21 @@ const colourspace = {
|
|||||||
* .tint({ r: 255, g: 240, b: 16 })
|
* .tint({ r: 255, g: 240, b: 16 })
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @param {string|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
|
* @param {string|Object} tint - Parsed by the [color](https://www.npmjs.org/package/color) module.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameter
|
* @throws {Error} Invalid parameter
|
||||||
*/
|
*/
|
||||||
function tint (rgb) {
|
function tint (tint) {
|
||||||
const colour = color(rgb);
|
this._setBackgroundColourOption('tint', tint);
|
||||||
this.options.tintA = colour.a();
|
|
||||||
this.options.tintB = colour.b();
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to 8-bit greyscale; 256 shades of grey.
|
* Convert to 8-bit greyscale; 256 shades of grey.
|
||||||
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||||
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
||||||
* This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
* This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
||||||
* which will produce an output image containing one color channel.
|
* which will produce an output image containing one colour channel.
|
||||||
* An alpha channel may be present, and will be unchanged by the operation.
|
* An alpha channel may be present, and will be unchanged by the operation.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -73,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
|
||||||
@@ -92,7 +88,7 @@ function pipelineColourspace (colourspace) {
|
|||||||
if (!is.string(colourspace)) {
|
if (!is.string(colourspace)) {
|
||||||
throw is.invalidParameterError('colourspace', 'string', colourspace);
|
throw is.invalidParameterError('colourspace', 'string', colourspace);
|
||||||
}
|
}
|
||||||
this.options.colourspaceInput = colourspace;
|
this.options.colourspacePipeline = colourspace;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +159,7 @@ function _setBackgroundColourOption (key, value) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with colour-related functions.
|
* Decorate the Sharp prototype with colour-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ const blend = {
|
|||||||
* The images to composite must be the same size or smaller than the processed image.
|
* The images to composite must be the same size or smaller than the processed image.
|
||||||
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||||
*
|
*
|
||||||
* Any resize, rotate or extract operations in the same processing pipeline
|
* Other operations in the same processing pipeline (e.g. resize, rotate, flip,
|
||||||
* will always be applied to the input image before composition.
|
* flop, extract) will always be applied to the input image before composition.
|
||||||
*
|
*
|
||||||
* The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
* The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||||
* `dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
* `dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||||
@@ -110,6 +110,7 @@ const blend = {
|
|||||||
* @param {number} [images[].input.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
* @param {number} [images[].input.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
||||||
* @param {boolean} [images[].input.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`.
|
* @param {boolean} [images[].input.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for Pango markup features like `<span foreground="red">Red!</span>`.
|
||||||
* @param {number} [images[].input.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
* @param {number} [images[].input.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
||||||
|
* @param {Boolean} [images[].autoOrient=false] - set to true to use EXIF orientation data, if present, to orient the image.
|
||||||
* @param {String} [images[].blend='over'] - how to blend this image with the image below.
|
* @param {String} [images[].blend='over'] - how to blend this image with the image below.
|
||||||
* @param {String} [images[].gravity='centre'] - gravity at which to place the overlay.
|
* @param {String} [images[].gravity='centre'] - gravity at which to place the overlay.
|
||||||
* @param {Number} [images[].top] - the pixel offset from the top edge.
|
* @param {Number} [images[].top] - the pixel offset from the top edge.
|
||||||
@@ -202,6 +203,7 @@ function composite (images) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with composite-related functions.
|
* Decorate the Sharp prototype with composite-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ const debuglog = util.debuglog('sharp');
|
|||||||
*
|
*
|
||||||
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||||
*
|
*
|
||||||
|
* When loading more than one page/frame of an animated image,
|
||||||
|
* these are combined as a vertically-stacked "toilet roll" image
|
||||||
|
* where the overall height is the `pageHeight` multiplied by the number of `pages`.
|
||||||
|
*
|
||||||
* @constructs Sharp
|
* @constructs Sharp
|
||||||
*
|
*
|
||||||
* @emits Sharp#info
|
* @emits Sharp#info
|
||||||
@@ -36,14 +40,16 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Read image data from readableStream,
|
* // Read image data from remote URL,
|
||||||
* // resize to 300 pixels wide,
|
* // resize to 300 pixels wide,
|
||||||
* // emit an 'info' event with calculated dimensions
|
* // emit an 'info' event with calculated dimensions
|
||||||
* // and finally write image data to writableStream
|
* // and finally write image data to writableStream
|
||||||
* var transformer = sharp()
|
* const { body } = fetch('https://...');
|
||||||
|
* const readableStream = Readable.fromWeb(body);
|
||||||
|
* const transformer = sharp()
|
||||||
* .resize(300)
|
* .resize(300)
|
||||||
* .on('info', function(info) {
|
* .on('info', ({ height }) => {
|
||||||
* console.log('Image height is ' + info.height);
|
* console.log(`Image height is ${height}`);
|
||||||
* });
|
* });
|
||||||
* readableStream.pipe(transformer).pipe(writableStream);
|
* readableStream.pipe(transformer).pipe(writableStream);
|
||||||
*
|
*
|
||||||
@@ -115,17 +121,33 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* }
|
* }
|
||||||
* }).toFile('text_rgba.png');
|
* }).toFile('text_rgba.png');
|
||||||
*
|
*
|
||||||
* @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string)} [input] - if present, can be
|
* @example
|
||||||
|
* // Join four input images as a 2x2 grid with a 4 pixel gutter
|
||||||
|
* const data = await sharp(
|
||||||
|
* [image1, image2, image3, image4],
|
||||||
|
* { join: { across: 2, shim: 4 } }
|
||||||
|
* ).toBuffer();
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Generate a two-frame animated image from emoji
|
||||||
|
* const images = ['😀', '😛'].map(text => ({
|
||||||
|
* text: { text, width: 64, height: 64, channels: 4, rgba: true }
|
||||||
|
* }));
|
||||||
|
* await sharp(images, { join: { animated: true } }).toFile('out.gif');
|
||||||
|
*
|
||||||
|
* @param {(Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string|Array)} [input] - if present, can be
|
||||||
* a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
|
* a Buffer / ArrayBuffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
|
||||||
* a TypedArray containing raw pixel image data, or
|
* a TypedArray containing raw pixel image data, or
|
||||||
* a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
|
* a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
|
||||||
|
* An array of inputs can be provided, and these will be joined together.
|
||||||
* JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
* JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||||
* @param {string} [options.failOn='warning'] - when to abort processing of invalid pixel data, one of (in order of sensitivity): 'none' (least), 'truncated', 'error' or 'warning' (most), higher levels imply lower levels, invalid metadata will always abort.
|
* @param {string} [options.failOn='warning'] - When to abort processing of invalid pixel data, one of (in order of sensitivity, least to most): 'none', 'truncated', 'error', 'warning'. Higher levels imply lower levels. Invalid metadata will always abort.
|
||||||
* @param {number|boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
|
* @param {number|boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
|
||||||
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
||||||
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
|
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
|
||||||
* @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
|
* @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
|
||||||
|
* @param {boolean} [options.autoOrient=false] - Set this to `true` to rotate/flip the image to match EXIF `Orientation`, if any.
|
||||||
* @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
|
* @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
|
||||||
* @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
|
* @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
|
||||||
* @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
|
* @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
|
||||||
@@ -133,6 +155,7 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
|
* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
|
||||||
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
|
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
|
||||||
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
|
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
|
||||||
|
* @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
|
||||||
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
|
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
|
||||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
* @param {number} [options.raw.width] - integral number of pixels wide.
|
* @param {number} [options.raw.width] - integral number of pixels wide.
|
||||||
@@ -160,7 +183,15 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
* @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
|
||||||
* @param {boolean} [options.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`.
|
* @param {boolean} [options.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`.
|
||||||
* @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
* @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
|
||||||
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'.
|
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'.
|
||||||
|
* @param {Object} [options.join] - describes how an array of input images should be joined.
|
||||||
|
* @param {number} [options.join.across=1] - number of images to join horizontally.
|
||||||
|
* @param {boolean} [options.join.animated=false] - set this to `true` to join the images as an animated image.
|
||||||
|
* @param {number} [options.join.shim=0] - number of pixels to insert between joined images.
|
||||||
|
* @param {string|Object} [options.join.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||||
|
* @param {string} [options.join.halign='left'] - horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`).
|
||||||
|
* @param {string} [options.join.valign='top'] - vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`).
|
||||||
|
*
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -187,7 +218,6 @@ const Sharp = function (input, options) {
|
|||||||
canvas: 'crop',
|
canvas: 'crop',
|
||||||
position: 0,
|
position: 0,
|
||||||
resizeBackground: [0, 0, 0, 255],
|
resizeBackground: [0, 0, 0, 255],
|
||||||
useExifOrientation: false,
|
|
||||||
angle: 0,
|
angle: 0,
|
||||||
rotationAngle: 0,
|
rotationAngle: 0,
|
||||||
rotationBackground: [0, 0, 0, 255],
|
rotationBackground: [0, 0, 0, 255],
|
||||||
@@ -212,8 +242,7 @@ const Sharp = function (input, options) {
|
|||||||
kernel: 'lanczos3',
|
kernel: 'lanczos3',
|
||||||
fastShrinkOnLoad: true,
|
fastShrinkOnLoad: true,
|
||||||
// operations
|
// operations
|
||||||
tintA: 128,
|
tint: [-1, 0, 0, 0],
|
||||||
tintB: 128,
|
|
||||||
flatten: false,
|
flatten: false,
|
||||||
flattenBackground: [0, 0, 0],
|
flattenBackground: [0, 0, 0],
|
||||||
unflatten: false,
|
unflatten: false,
|
||||||
@@ -221,6 +250,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,
|
||||||
@@ -230,7 +261,10 @@ const Sharp = function (input, options) {
|
|||||||
threshold: 0,
|
threshold: 0,
|
||||||
thresholdGrayscale: true,
|
thresholdGrayscale: true,
|
||||||
trimBackground: [],
|
trimBackground: [],
|
||||||
trimThreshold: 0,
|
trimThreshold: -1,
|
||||||
|
trimLineArt: false,
|
||||||
|
dilateWidth: 0,
|
||||||
|
erodeWidth: 0,
|
||||||
gamma: 0,
|
gamma: 0,
|
||||||
gammaOut: 0,
|
gammaOut: 0,
|
||||||
greyscale: false,
|
greyscale: false,
|
||||||
@@ -251,18 +285,21 @@ const Sharp = function (input, options) {
|
|||||||
removeAlpha: false,
|
removeAlpha: false,
|
||||||
ensureAlpha: -1,
|
ensureAlpha: -1,
|
||||||
colourspace: 'srgb',
|
colourspace: 'srgb',
|
||||||
colourspaceInput: 'last',
|
colourspacePipeline: 'last',
|
||||||
composite: [],
|
composite: [],
|
||||||
// output
|
// output
|
||||||
fileOut: '',
|
fileOut: '',
|
||||||
formatOut: 'input',
|
formatOut: 'input',
|
||||||
streamOut: false,
|
streamOut: false,
|
||||||
withMetadata: false,
|
keepMetadata: 0,
|
||||||
withMetadataOrientation: -1,
|
withMetadataOrientation: -1,
|
||||||
withMetadataDensity: 0,
|
withMetadataDensity: 0,
|
||||||
withMetadataIcc: '',
|
withIccProfile: '',
|
||||||
withMetadataStrs: {},
|
withExif: {},
|
||||||
|
withExifMerge: true,
|
||||||
resolveWithObject: false,
|
resolveWithObject: false,
|
||||||
|
loop: 1,
|
||||||
|
delay: [],
|
||||||
// output format
|
// output format
|
||||||
jpegQuality: 80,
|
jpegQuality: 80,
|
||||||
jpegProgressive: false,
|
jpegProgressive: false,
|
||||||
@@ -290,6 +327,7 @@ const Sharp = function (input, options) {
|
|||||||
webpLossless: false,
|
webpLossless: false,
|
||||||
webpNearLossless: false,
|
webpNearLossless: false,
|
||||||
webpSmartSubsample: false,
|
webpSmartSubsample: false,
|
||||||
|
webpSmartDeblock: false,
|
||||||
webpPreset: 'default',
|
webpPreset: 'default',
|
||||||
webpEffort: 4,
|
webpEffort: 4,
|
||||||
webpMinSize: false,
|
webpMinSize: false,
|
||||||
@@ -305,6 +343,7 @@ const Sharp = function (input, options) {
|
|||||||
tiffCompression: 'jpeg',
|
tiffCompression: 'jpeg',
|
||||||
tiffPredictor: 'horizontal',
|
tiffPredictor: 'horizontal',
|
||||||
tiffPyramid: false,
|
tiffPyramid: false,
|
||||||
|
tiffMiniswhite: false,
|
||||||
tiffBitdepth: 8,
|
tiffBitdepth: 8,
|
||||||
tiffTile: false,
|
tiffTile: false,
|
||||||
tiffTileHeight: 256,
|
tiffTileHeight: 256,
|
||||||
@@ -317,6 +356,7 @@ const Sharp = function (input, options) {
|
|||||||
heifCompression: 'av1',
|
heifCompression: 'av1',
|
||||||
heifEffort: 4,
|
heifEffort: 4,
|
||||||
heifChromaSubsampling: '4:4:4',
|
heifChromaSubsampling: '4:4:4',
|
||||||
|
heifBitdepth: 8,
|
||||||
jxlDistance: 1,
|
jxlDistance: 1,
|
||||||
jxlDecodingTier: 0,
|
jxlDecodingTier: 0,
|
||||||
jxlEffort: 7,
|
jxlEffort: 7,
|
||||||
@@ -337,6 +377,7 @@ const Sharp = function (input, options) {
|
|||||||
timeoutSeconds: 0,
|
timeoutSeconds: 0,
|
||||||
linearA: [],
|
linearA: [],
|
||||||
linearB: [],
|
linearB: [],
|
||||||
|
pdfBackground: [255, 255, 255, 255],
|
||||||
// Function to notify of libvips warnings
|
// Function to notify of libvips warnings
|
||||||
debuglog: warning => {
|
debuglog: warning => {
|
||||||
this.emit('warning', warning);
|
this.emit('warning', warning);
|
||||||
@@ -417,13 +458,16 @@ Object.setPrototypeOf(Sharp, stream.Duplex);
|
|||||||
function clone () {
|
function clone () {
|
||||||
// Clone existing options
|
// Clone existing options
|
||||||
const clone = this.constructor.call();
|
const clone = this.constructor.call();
|
||||||
clone.options = Object.assign({}, this.options);
|
const { debuglog, queueListener, ...options } = this.options;
|
||||||
|
clone.options = structuredClone(options);
|
||||||
|
clone.options.debuglog = debuglog;
|
||||||
|
clone.options.queueListener = queueListener;
|
||||||
// Pass 'finish' event to clone for Stream-based input
|
// Pass 'finish' event to clone for Stream-based input
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', () => {
|
this.on('finish', () => {
|
||||||
// Clone inherits input data
|
// Clone inherits input data
|
||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
clone.options.bufferIn = this.options.bufferIn;
|
clone.options.input.buffer = this.options.input.buffer;
|
||||||
clone.emit('finish');
|
clone.emit('finish');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -433,6 +477,7 @@ Object.assign(Sharp.prototype, { clone });
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Export constructor.
|
* Export constructor.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = Sharp;
|
module.exports = Sharp;
|
||||||
|
|||||||
367
lib/index.d.ts
vendored
@@ -40,19 +40,7 @@ import { Duplex } from 'stream';
|
|||||||
*/
|
*/
|
||||||
declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;
|
declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;
|
||||||
declare function sharp(
|
declare function sharp(
|
||||||
input?:
|
input?: sharp.SharpInput | Array<sharp.SharpInput>,
|
||||||
| Buffer
|
|
||||||
| ArrayBuffer
|
|
||||||
| Uint8Array
|
|
||||||
| Uint8ClampedArray
|
|
||||||
| Int8Array
|
|
||||||
| Uint16Array
|
|
||||||
| Int16Array
|
|
||||||
| Uint32Array
|
|
||||||
| Int32Array
|
|
||||||
| Float32Array
|
|
||||||
| Float64Array
|
|
||||||
| string,
|
|
||||||
options?: sharp.SharpOptions,
|
options?: sharp.SharpOptions,
|
||||||
): sharp.Sharp;
|
): sharp.Sharp;
|
||||||
|
|
||||||
@@ -62,33 +50,35 @@ declare namespace sharp {
|
|||||||
|
|
||||||
/** An Object containing the version numbers of sharp, libvips and its dependencies. */
|
/** An Object containing the version numbers of sharp, libvips and its dependencies. */
|
||||||
const versions: {
|
const versions: {
|
||||||
vips: string;
|
aom?: string | undefined;
|
||||||
|
archive?: string | undefined;
|
||||||
cairo?: string | undefined;
|
cairo?: string | undefined;
|
||||||
croco?: string | undefined;
|
cgif?: string | undefined;
|
||||||
exif?: string | undefined;
|
exif?: string | undefined;
|
||||||
expat?: string | undefined;
|
expat?: string | undefined;
|
||||||
ffi?: string | undefined;
|
ffi?: string | undefined;
|
||||||
fontconfig?: string | undefined;
|
fontconfig?: string | undefined;
|
||||||
freetype?: string | undefined;
|
freetype?: string | undefined;
|
||||||
gdkpixbuf?: string | undefined;
|
fribidi?: string | undefined;
|
||||||
gif?: string | undefined;
|
|
||||||
glib?: string | undefined;
|
glib?: string | undefined;
|
||||||
gsf?: string | undefined;
|
|
||||||
harfbuzz?: string | undefined;
|
harfbuzz?: string | undefined;
|
||||||
jpeg?: string | undefined;
|
heif?: string | undefined;
|
||||||
|
highway?: string | undefined;
|
||||||
|
imagequant?: string | undefined;
|
||||||
lcms?: string | undefined;
|
lcms?: string | undefined;
|
||||||
orc?: string | undefined;
|
mozjpeg?: string | undefined;
|
||||||
pango?: string | undefined;
|
pango?: string | undefined;
|
||||||
pixman?: string | undefined;
|
pixman?: string | undefined;
|
||||||
png?: string | undefined;
|
png?: string | undefined;
|
||||||
sharp?: string | undefined;
|
"proxy-libintl"?: string | undefined;
|
||||||
svg?: string | undefined;
|
rsvg?: string | undefined;
|
||||||
|
sharp: string;
|
||||||
|
spng?: string | undefined;
|
||||||
tiff?: string | undefined;
|
tiff?: string | undefined;
|
||||||
|
vips: string;
|
||||||
webp?: string | undefined;
|
webp?: string | undefined;
|
||||||
avif?: string | undefined;
|
|
||||||
heif?: string | undefined;
|
|
||||||
xml?: string | undefined;
|
xml?: string | undefined;
|
||||||
zlib?: string | undefined;
|
"zlib-ng"?: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An Object containing the available interpolators and their proper values */
|
/** An Object containing the available interpolators and their proper values */
|
||||||
@@ -126,7 +116,7 @@ declare namespace sharp {
|
|||||||
function counters(): SharpCounters;
|
function counters(): SharpCounters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support.
|
* Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with highway support.
|
||||||
* Improves the performance of resize, blur and sharpen operations by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
* Improves the performance of resize, blur and sharpen operations by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||||
* @param enable enable or disable use of SIMD vector unit instructions
|
* @param enable enable or disable use of SIMD vector unit instructions
|
||||||
* @returns true if usage of SIMD vector unit instructions is enabled
|
* @returns true if usage of SIMD vector unit instructions is enabled
|
||||||
@@ -239,19 +229,19 @@ declare namespace sharp {
|
|||||||
//#region Color functions
|
//#region Color functions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tint the image using the provided chroma while preserving the image luminance.
|
* Tint the image using the provided colour.
|
||||||
* An alpha channel may be present and will be unchanged by the operation.
|
* An alpha channel may be present and will be unchanged by the operation.
|
||||||
* @param rgb Parsed by the color module to extract chroma values.
|
* @param tint Parsed by the color module.
|
||||||
* @returns A sharp instance that can be used to chain operations
|
* @returns A sharp instance that can be used to chain operations
|
||||||
*/
|
*/
|
||||||
tint(rgb: Color): Sharp;
|
tint(tint: Colour | Color): Sharp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to 8-bit greyscale; 256 shades of grey.
|
* Convert to 8-bit greyscale; 256 shades of grey.
|
||||||
* This is a linear operation.
|
* This is a linear operation.
|
||||||
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
|
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
|
||||||
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
||||||
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
|
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel.
|
||||||
* An alpha channel may be present, and will be unchanged by the operation.
|
* An alpha channel may be present, and will be unchanged by the operation.
|
||||||
* @param greyscale true to enable and false to disable (defaults to true)
|
* @param greyscale true to enable and false to disable (defaults to true)
|
||||||
* @returns A sharp instance that can be used to chain operations
|
* @returns A sharp instance that can be used to chain operations
|
||||||
@@ -341,6 +331,12 @@ declare namespace sharp {
|
|||||||
*/
|
*/
|
||||||
metadata(): Promise<Metadata>;
|
metadata(): Promise<Metadata>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
*/
|
||||||
|
keepMetadata(): Sharp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access to pixel-derived image statistics for every channel in the image.
|
* Access to pixel-derived image statistics for every channel in the image.
|
||||||
* @returns A sharp instance that can be used to chain operations
|
* @returns A sharp instance that can be used to chain operations
|
||||||
@@ -358,24 +354,72 @@ declare namespace sharp {
|
|||||||
//#region Operation functions
|
//#region Operation functions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag.
|
* Rotate the output image by either an explicit angle
|
||||||
|
* or auto-orient based on the EXIF `Orientation` tag.
|
||||||
*
|
*
|
||||||
* If an angle is provided, it is converted to a valid positive degree rotation. For example, -450 will produce a 270deg rotation.
|
* If an angle is provided, it is converted to a valid positive degree rotation.
|
||||||
|
* For example, `-450` will produce a 270 degree rotation.
|
||||||
*
|
*
|
||||||
* When rotating by an angle other than a multiple of 90, the background colour can be provided with the background option.
|
* When rotating by an angle other than a multiple of 90,
|
||||||
|
* the background colour can be provided with the `background` option.
|
||||||
*
|
*
|
||||||
* If no angle is provided, it is determined from the EXIF data. Mirroring is supported and may infer the use of a flip operation.
|
* If no angle is provided, it is determined from the EXIF data.
|
||||||
|
* Mirroring is supported and may infer the use of a flip operation.
|
||||||
*
|
*
|
||||||
* The use of rotate implies the removal of the EXIF Orientation tag, if any.
|
* The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
||||||
*
|
*
|
||||||
* Method order is important when both rotating and extracting regions, for example rotate(x).extract(y) will produce a different result to extract(y).rotate(x).
|
* Only one rotation can occur per pipeline (aside from an initial call without
|
||||||
* @param angle angle of rotation. (optional, default auto)
|
* arguments to orient via EXIF data). Previous calls to `rotate` in the same
|
||||||
* @param options if present, is an Object with optional attributes.
|
* pipeline will be ignored.
|
||||||
|
*
|
||||||
|
* Multi-page images can only be rotated by 180 degrees.
|
||||||
|
*
|
||||||
|
* Method order is important when rotating, resizing and/or extracting regions,
|
||||||
|
* for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const pipeline = sharp()
|
||||||
|
* .rotate()
|
||||||
|
* .resize(null, 200)
|
||||||
|
* .toBuffer(function (err, outputBuffer, info) {
|
||||||
|
* // outputBuffer contains 200px high JPEG image data,
|
||||||
|
* // auto-rotated using EXIF Orientation tag
|
||||||
|
* // info.width and info.height contain the dimensions of the resized image
|
||||||
|
* });
|
||||||
|
* readableStream.pipe(pipeline);
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const rotateThenResize = await sharp(input)
|
||||||
|
* .rotate(90)
|
||||||
|
* .resize({ width: 16, height: 8, fit: 'fill' })
|
||||||
|
* .toBuffer();
|
||||||
|
* const resizeThenRotate = await sharp(input)
|
||||||
|
* .resize({ width: 16, height: 8, fit: 'fill' })
|
||||||
|
* .rotate(90)
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @param {number} [angle=auto] angle of rotation.
|
||||||
|
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||||
|
* @param {string|Object} [options.background="#000000"] parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||||
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
* @returns A sharp instance that can be used to chain operations
|
|
||||||
*/
|
*/
|
||||||
rotate(angle?: number, options?: RotateOptions): Sharp;
|
rotate(angle?: number, options?: RotateOptions): Sharp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for calling `rotate()` with no arguments, which orients the image based
|
||||||
|
* on EXIF orientsion.
|
||||||
|
*
|
||||||
|
* This operation is aliased to emphasize its purpose, helping to remove any
|
||||||
|
* confusion between rotation and orientation.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).autoOrient().toBuffer();
|
||||||
|
*
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
autoOrient(): Sharp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
||||||
* The use of flip implies the removal of the EXIF Orientation tag, if any.
|
* The use of flip implies the removal of the EXIF Orientation tag, if any.
|
||||||
@@ -395,7 +439,7 @@ declare namespace sharp {
|
|||||||
/**
|
/**
|
||||||
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||||
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||||
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
||||||
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||||
*
|
*
|
||||||
* In the case of a 2x2 matrix, the transform is:
|
* In the case of a 2x2 matrix, the transform is:
|
||||||
@@ -458,7 +502,23 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expand foreground objects using the dilate morphological operator.
|
||||||
|
* @param {Number} [width=1] dilation width in pixels.
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
*/
|
||||||
|
dilate(width?: number): Sharp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink foreground objects using the erode morphological operator.
|
||||||
|
* @param {Number} [width=1] erosion width in pixels.
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
*/
|
||||||
|
erode(width?: number): Sharp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge alpha transparency channel, if any, with background.
|
* Merge alpha transparency channel, if any, with background.
|
||||||
@@ -565,11 +625,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.
|
||||||
@@ -633,6 +693,43 @@ declare namespace sharp {
|
|||||||
*/
|
*/
|
||||||
toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
|
toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep all EXIF metadata from the input image in the output image.
|
||||||
|
* EXIF metadata is unsupported for TIFF output.
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
*/
|
||||||
|
keepExif(): Sharp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set EXIF metadata in the output image, ignoring any EXIF in the input image.
|
||||||
|
* @param {Exif} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
withExif(exif: Exif): Sharp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update EXIF metadata from the input image in the output image.
|
||||||
|
* @param {Exif} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
withExifMerge(exif: Exif): Sharp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep ICC profile from the input image in the output image where possible.
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
*/
|
||||||
|
keepIccProfile(): Sharp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform using an ICC profile and attach to the output image.
|
||||||
|
* @param {string} icc - Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk).
|
||||||
|
* @returns A sharp instance that can be used to chain operations
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
withIccProfile(icc: string, options?: WithIccProfileOptions): Sharp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
||||||
* The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
* The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
||||||
@@ -756,8 +853,6 @@ declare namespace sharp {
|
|||||||
* Use tile-based deep zoom (image pyramid) output.
|
* Use tile-based deep zoom (image pyramid) output.
|
||||||
* Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
|
* Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
|
||||||
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
|
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
|
||||||
*
|
|
||||||
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
|
||||||
* @param tile tile options
|
* @param tile tile options
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
* @returns A sharp instance that can be used to chain operations
|
* @returns A sharp instance that can be used to chain operations
|
||||||
@@ -847,16 +942,36 @@ declare namespace sharp {
|
|||||||
* Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
* Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
||||||
* Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
|
* Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
|
||||||
* The info response Object will contain trimOffsetLeft and trimOffsetTop properties.
|
* The info response Object will contain trimOffsetLeft and trimOffsetTop properties.
|
||||||
* @param trim The specific background colour to trim, the threshold for doing so or an Object with both.
|
* @param options trim options
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
trim(trim?: string | number | TrimOptions): Sharp;
|
trim(options?: TrimOptions): Sharp;
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SharpInput = Buffer
|
||||||
|
| ArrayBuffer
|
||||||
|
| Uint8Array
|
||||||
|
| Uint8ClampedArray
|
||||||
|
| Int8Array
|
||||||
|
| Uint16Array
|
||||||
|
| Int16Array
|
||||||
|
| Uint32Array
|
||||||
|
| Int32Array
|
||||||
|
| Float32Array
|
||||||
|
| Float64Array
|
||||||
|
| string;
|
||||||
|
|
||||||
interface SharpOptions {
|
interface SharpOptions {
|
||||||
|
/**
|
||||||
|
* Auto-orient based on the EXIF `Orientation` tag, if present.
|
||||||
|
* Mirroring is supported and may infer the use of a flip operation.
|
||||||
|
*
|
||||||
|
* Using this option will remove the EXIF `Orientation` tag, if any.
|
||||||
|
*/
|
||||||
|
autoOrient?: boolean | undefined;
|
||||||
/**
|
/**
|
||||||
* When to abort processing of invalid pixel data, one of (in order of sensitivity):
|
* When to abort processing of invalid pixel data, one of (in order of sensitivity):
|
||||||
* 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
|
* 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
|
||||||
@@ -892,6 +1007,8 @@ declare namespace sharp {
|
|||||||
subifd?: number | undefined;
|
subifd?: number | undefined;
|
||||||
/** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
|
/** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
|
||||||
level?: number | undefined;
|
level?: number | undefined;
|
||||||
|
/** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
|
||||||
|
pdfBackground?: Colour | Color | undefined;
|
||||||
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
|
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
|
||||||
animated?: boolean | undefined;
|
animated?: boolean | undefined;
|
||||||
/** Describes raw pixel input image data. See raw() for pixel ordering. */
|
/** Describes raw pixel input image data. See raw() for pixel ordering. */
|
||||||
@@ -900,6 +1017,8 @@ declare namespace sharp {
|
|||||||
create?: Create | undefined;
|
create?: Create | undefined;
|
||||||
/** Describes a new text image to be created. */
|
/** Describes a new text image to be created. */
|
||||||
text?: CreateText | undefined;
|
text?: CreateText | undefined;
|
||||||
|
/** Describes how array of input images should be joined. */
|
||||||
|
join?: Join | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CacheOptions {
|
interface CacheOptions {
|
||||||
@@ -926,7 +1045,7 @@ declare namespace sharp {
|
|||||||
interface Raw {
|
interface Raw {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
channels: 1 | 2 | 3 | 4;
|
channels: Channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateRaw extends Raw {
|
interface CreateRaw extends Raw {
|
||||||
@@ -934,15 +1053,17 @@ declare namespace sharp {
|
|||||||
premultiplied?: boolean | undefined;
|
premultiplied?: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateChannels = 3 | 4;
|
||||||
|
|
||||||
interface Create {
|
interface Create {
|
||||||
/** Number of pixels wide. */
|
/** Number of pixels wide. */
|
||||||
width: number;
|
width: number;
|
||||||
/** Number of pixels high. */
|
/** Number of pixels high. */
|
||||||
height: number;
|
height: number;
|
||||||
/** Number of bands e.g. 3 for RGB, 4 for RGBA */
|
/** Number of bands, 3 for RGB, 4 for RGBA */
|
||||||
channels: Channels;
|
channels: CreateChannels;
|
||||||
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
|
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
|
||||||
background: Color;
|
background: Colour | Color;
|
||||||
/** Describes a noise to be created. */
|
/** Describes a noise to be created. */
|
||||||
noise?: Noise | undefined;
|
noise?: Noise | undefined;
|
||||||
}
|
}
|
||||||
@@ -974,19 +1095,51 @@ declare namespace sharp {
|
|||||||
rgba?: boolean;
|
rgba?: boolean;
|
||||||
/** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */
|
/** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */
|
||||||
spacing?: number;
|
spacing?: number;
|
||||||
/** Word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none' */
|
/** Word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none' */
|
||||||
wrap?: TextWrap;
|
wrap?: TextWrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Join {
|
||||||
|
/** Number of images per row. */
|
||||||
|
across?: number | undefined;
|
||||||
|
/** Treat input as frames of an animated image. */
|
||||||
|
animated?: boolean | undefined;
|
||||||
|
/** Space between images, in pixels. */
|
||||||
|
shim?: number | undefined;
|
||||||
|
/** Background colour. */
|
||||||
|
background?: Colour | Color | undefined;
|
||||||
|
/** Horizontal alignment. */
|
||||||
|
halign?: HorizontalAlignment | undefined;
|
||||||
|
/** Vertical alignment. */
|
||||||
|
valign?: VerticalAlignment | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ExifDir {
|
||||||
|
[k: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Exif {
|
||||||
|
'IFD0'?: ExifDir;
|
||||||
|
'IFD1'?: ExifDir;
|
||||||
|
'IFD2'?: ExifDir;
|
||||||
|
'IFD3'?: ExifDir;
|
||||||
|
}
|
||||||
|
|
||||||
interface WriteableMetadata {
|
interface WriteableMetadata {
|
||||||
/** Value between 1 and 8, used to update the EXIF Orientation tag. */
|
|
||||||
orientation?: number | undefined;
|
|
||||||
/** Filesystem path to output ICC profile, defaults to sRGB. */
|
|
||||||
icc?: string | undefined;
|
|
||||||
/** Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. (optional, default {}) */
|
|
||||||
exif?: Record<string, any> | undefined;
|
|
||||||
/** Number of pixels per inch (DPI) */
|
/** Number of pixels per inch (DPI) */
|
||||||
density?: number | undefined;
|
density?: number | undefined;
|
||||||
|
/** Value between 1 and 8, used to update the EXIF Orientation tag. */
|
||||||
|
orientation?: number | undefined;
|
||||||
|
/**
|
||||||
|
* Filesystem path to output ICC profile, defaults to sRGB.
|
||||||
|
* @deprecated Use `withIccProfile()` instead.
|
||||||
|
*/
|
||||||
|
icc?: string | undefined;
|
||||||
|
/**
|
||||||
|
* Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
|
||||||
|
* @deprecated Use `withExif()` or `withExifMerge()` instead.
|
||||||
|
*/
|
||||||
|
exif?: Exif | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Metadata {
|
interface Metadata {
|
||||||
@@ -1000,6 +1153,13 @@ declare namespace sharp {
|
|||||||
width?: number | undefined;
|
width?: number | undefined;
|
||||||
/** Number of pixels high (EXIF orientation is not taken into consideration) */
|
/** Number of pixels high (EXIF orientation is not taken into consideration) */
|
||||||
height?: number | undefined;
|
height?: number | undefined;
|
||||||
|
/** Any changed metadata after the image orientation is applied. */
|
||||||
|
autoOrient: {
|
||||||
|
/** Number of pixels wide (EXIF orientation is taken into consideration) */
|
||||||
|
width: number;
|
||||||
|
/** Number of pixels high (EXIF orientation is taken into consideration) */
|
||||||
|
height: number;
|
||||||
|
};
|
||||||
/** Name of colour space interpretation */
|
/** Name of colour space interpretation */
|
||||||
space?: keyof ColourspaceEnum | undefined;
|
space?: keyof ColourspaceEnum | undefined;
|
||||||
/** Number of bands e.g. 3 for sRGB, 4 for CMYK */
|
/** Number of bands e.g. 3 for sRGB, 4 for CMYK */
|
||||||
@@ -1009,9 +1169,13 @@ declare namespace sharp {
|
|||||||
/** Number of pixels per inch (DPI), if present */
|
/** Number of pixels per inch (DPI), if present */
|
||||||
density?: number | undefined;
|
density?: number | undefined;
|
||||||
/** String containing JPEG chroma subsampling, 4:2:0 or 4:4:4 for RGB, 4:2:0:4 or 4:4:4:4 for CMYK */
|
/** String containing JPEG chroma subsampling, 4:2:0 or 4:4:4 for RGB, 4:2:0:4 or 4:4:4:4 for CMYK */
|
||||||
chromaSubsampling: string;
|
chromaSubsampling?: string | undefined;
|
||||||
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
||||||
isProgressive?: boolean | undefined;
|
isProgressive?: boolean | undefined;
|
||||||
|
/** Boolean indicating whether the image is palette-based (GIF, PNG). */
|
||||||
|
isPalette?: boolean | undefined;
|
||||||
|
/** Number of bits per sample for each channel (GIF, PNG). */
|
||||||
|
bitsPerSample?: number | undefined;
|
||||||
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
||||||
pages?: number | undefined;
|
pages?: number | undefined;
|
||||||
/** Number of pixels high each page in a multi-page image will be. */
|
/** Number of pixels high each page in a multi-page image will be. */
|
||||||
@@ -1038,8 +1202,8 @@ declare namespace sharp {
|
|||||||
tifftagPhotoshop?: Buffer | undefined;
|
tifftagPhotoshop?: Buffer | undefined;
|
||||||
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
||||||
compression?: 'av1' | 'hevc';
|
compression?: 'av1' | 'hevc';
|
||||||
/** Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value */
|
/** Default background colour, if present, for PNG (bKGD) and GIF images */
|
||||||
background?: { r: number; g: number; b: number } | number;
|
background?: { r: number; g: number; b: number } | { gray: number };
|
||||||
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
|
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
|
||||||
levels?: LevelMetadata[] | undefined;
|
levels?: LevelMetadata[] | undefined;
|
||||||
/** Number of Sub Image File Directories in an OME-TIFF image */
|
/** Number of Sub Image File Directories in an OME-TIFF image */
|
||||||
@@ -1048,6 +1212,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 {
|
||||||
@@ -1055,6 +1221,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[];
|
||||||
@@ -1096,6 +1267,11 @@ declare namespace sharp {
|
|||||||
force?: boolean | undefined;
|
force?: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface WithIccProfileOptions {
|
||||||
|
/** Should the ICC profile be included in the output image metadata? (optional, default true) */
|
||||||
|
attach?: boolean | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
interface JpegOptions extends OutputOptions {
|
interface JpegOptions extends OutputOptions {
|
||||||
/** Quality, integer 1-100 (optional, default 80) */
|
/** Quality, integer 1-100 (optional, default 80) */
|
||||||
quality?: number | undefined;
|
quality?: number | undefined;
|
||||||
@@ -1179,6 +1355,8 @@ declare namespace sharp {
|
|||||||
effort?: number | undefined;
|
effort?: number | undefined;
|
||||||
/** set to '4:2:0' to use chroma subsampling, requires libvips v8.11.0 (optional, default '4:4:4') */
|
/** set to '4:2:0' to use chroma subsampling, requires libvips v8.11.0 (optional, default '4:4:4') */
|
||||||
chromaSubsampling?: string | undefined;
|
chromaSubsampling?: string | undefined;
|
||||||
|
/** Set bitdepth to 8, 10 or 12 bit (optional, default 8) */
|
||||||
|
bitdepth?: 8 | 10 | 12 | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HeifOptions extends OutputOptions {
|
interface HeifOptions extends OutputOptions {
|
||||||
@@ -1192,6 +1370,8 @@ declare namespace sharp {
|
|||||||
effort?: number | undefined;
|
effort?: number | undefined;
|
||||||
/** set to '4:2:0' to use chroma subsampling (optional, default '4:4:4') */
|
/** set to '4:2:0' to use chroma subsampling (optional, default '4:4:4') */
|
||||||
chromaSubsampling?: string | undefined;
|
chromaSubsampling?: string | undefined;
|
||||||
|
/** Set bitdepth to 8, 10 or 12 bit (optional, default 8) */
|
||||||
|
bitdepth?: 8 | 10 | 12 | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GifOptions extends OutputOptions, AnimationOptions {
|
interface GifOptions extends OutputOptions, AnimationOptions {
|
||||||
@@ -1234,6 +1414,8 @@ declare namespace sharp {
|
|||||||
yres?: number | undefined;
|
yres?: number | undefined;
|
||||||
/** Reduce bitdepth to 1, 2 or 4 bit (optional, default 8) */
|
/** Reduce bitdepth to 1, 2 or 4 bit (optional, default 8) */
|
||||||
bitdepth?: 1 | 2 | 4 | 8 | undefined;
|
bitdepth?: 1 | 2 | 4 | 8 | undefined;
|
||||||
|
/** Write 1-bit images as miniswhite (optional, default false) */
|
||||||
|
miniswhite?: boolean | undefined;
|
||||||
/** Resolution unit options: inch, cm (optional, default 'inch') */
|
/** Resolution unit options: inch, cm (optional, default 'inch') */
|
||||||
resolutionUnit?: 'inch' | 'cm' | undefined;
|
resolutionUnit?: 'inch' | 'cm' | undefined;
|
||||||
}
|
}
|
||||||
@@ -1261,12 +1443,23 @@ declare namespace sharp {
|
|||||||
|
|
||||||
interface RotateOptions {
|
interface RotateOptions {
|
||||||
/** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
|
/** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
|
||||||
background?: Color | undefined;
|
background?: Colour | 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?: Colour | Color | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NegateOptions {
|
interface NegateOptions {
|
||||||
@@ -1275,10 +1468,10 @@ declare namespace sharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface NormaliseOptions {
|
interface NormaliseOptions {
|
||||||
/** Percentile below which luminance values will be underexposed. */
|
/** Percentile below which luminance values will be underexposed. */
|
||||||
lower?: number | undefined;
|
lower?: number | undefined;
|
||||||
/** Percentile above which luminance values will be overexposed. */
|
/** Percentile above which luminance values will be overexposed. */
|
||||||
upper?: number | undefined;
|
upper?: number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ResizeOptions {
|
interface ResizeOptions {
|
||||||
@@ -1291,7 +1484,7 @@ declare namespace sharp {
|
|||||||
/** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
|
/** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
|
||||||
position?: number | string | undefined;
|
position?: number | string | undefined;
|
||||||
/** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
/** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
||||||
background?: Color | undefined;
|
background?: Colour | Color | undefined;
|
||||||
/** The kernel to use for image reduction. (optional, default 'lanczos3') */
|
/** The kernel to use for image reduction. (optional, default 'lanczos3') */
|
||||||
kernel?: keyof KernelEnum | undefined;
|
kernel?: keyof KernelEnum | undefined;
|
||||||
/** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
|
/** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
|
||||||
@@ -1334,24 +1527,26 @@ declare namespace sharp {
|
|||||||
/** single pixel count to right edge (optional, default 0) */
|
/** single pixel count to right edge (optional, default 0) */
|
||||||
right?: number | undefined;
|
right?: number | undefined;
|
||||||
/** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
/** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
||||||
background?: Color | undefined;
|
background?: Colour | Color | undefined;
|
||||||
/** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
|
/** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
|
||||||
extendWith?: ExtendWith | undefined;
|
extendWith?: ExtendWith | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TrimOptions {
|
interface TrimOptions {
|
||||||
/** background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
|
/** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
|
||||||
background?: Color | undefined;
|
background?: Colour | Color | undefined;
|
||||||
/** the allowed difference from the above colour, a positive number. (optional, default `10`) */
|
/** Allowed difference from the above colour, a positive number. (optional, default 10) */
|
||||||
threshold?: number | undefined;
|
threshold?: number | undefined;
|
||||||
|
/** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
|
||||||
|
lineArt?: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RawOptions {
|
interface RawOptions {
|
||||||
depth?: 'char' | 'uchar' | 'short' | 'ushort' | 'int' | 'uint' | 'float' | 'complex' | 'double' | 'dpcomplex';
|
depth?: 'char' | 'uchar' | 'short' | 'ushort' | 'int' | 'uint' | 'float' | 'complex' | 'double' | 'dpcomplex';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 3 for sRGB, 4 for CMYK */
|
/** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
|
||||||
type Channels = 3 | 4;
|
type Channels = 1 | 2 | 3 | 4;
|
||||||
|
|
||||||
interface RGBA {
|
interface RGBA {
|
||||||
r?: number | undefined;
|
r?: number | undefined;
|
||||||
@@ -1360,7 +1555,8 @@ declare namespace sharp {
|
|||||||
alpha?: number | undefined;
|
alpha?: number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Color = string | RGBA;
|
type Colour = string | RGBA;
|
||||||
|
type Color = Colour;
|
||||||
|
|
||||||
interface Kernel {
|
interface Kernel {
|
||||||
/** width of the kernel in pixels. */
|
/** width of the kernel in pixels. */
|
||||||
@@ -1406,6 +1602,16 @@ 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;
|
||||||
|
/** see sharp() constructor, (optional, default false) */
|
||||||
|
autoOrient?: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TileOptions {
|
interface TileOptions {
|
||||||
@@ -1477,7 +1683,7 @@ declare namespace sharp {
|
|||||||
size: number;
|
size: number;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
channels: 1 | 2 | 3 | 4;
|
channels: Channels;
|
||||||
/** indicating if premultiplication was used */
|
/** indicating if premultiplication was used */
|
||||||
premultiplied: boolean;
|
premultiplied: boolean;
|
||||||
/** Only defined when using a crop strategy */
|
/** Only defined when using a crop strategy */
|
||||||
@@ -1544,7 +1750,11 @@ declare namespace sharp {
|
|||||||
|
|
||||||
type TextAlign = 'left' | 'centre' | 'center' | 'right';
|
type TextAlign = 'left' | 'centre' | 'center' | 'right';
|
||||||
|
|
||||||
type TextWrap = 'word' | 'char' | 'charWord' | 'none';
|
type TextWrap = 'word' | 'char' | 'word-char' | 'none';
|
||||||
|
|
||||||
|
type HorizontalAlignment = 'left' | 'centre' | 'center' | 'right';
|
||||||
|
|
||||||
|
type VerticalAlignment = 'top' | 'centre' | 'center' | 'bottom';
|
||||||
|
|
||||||
type TileContainer = 'fs' | 'zip';
|
type TileContainer = 'fs' | 'zip';
|
||||||
|
|
||||||
@@ -1649,6 +1859,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;
|
||||||
|
|||||||
171
lib/input.js
@@ -8,15 +8,19 @@ const is = require('./is');
|
|||||||
const sharp = require('./sharp');
|
const sharp = require('./sharp');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Justication alignment
|
* Justification alignment
|
||||||
* @member
|
* @member
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const align = {
|
const align = {
|
||||||
left: 'low',
|
left: 'low',
|
||||||
|
top: 'low',
|
||||||
|
low: 'low',
|
||||||
center: 'centre',
|
center: 'centre',
|
||||||
centre: 'centre',
|
centre: 'centre',
|
||||||
right: 'high'
|
right: 'high',
|
||||||
|
bottom: 'high',
|
||||||
|
high: 'high'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,9 +28,9 @@ const align = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _inputOptionsFromObject (obj) {
|
function _inputOptionsFromObject (obj) {
|
||||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd } = obj;
|
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient } = obj;
|
||||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd].some(is.defined)
|
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient].some(is.defined)
|
||||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd }
|
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient }
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +40,7 @@ function _inputOptionsFromObject (obj) {
|
|||||||
*/
|
*/
|
||||||
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||||
const inputDescriptor = {
|
const inputDescriptor = {
|
||||||
|
autoOrient: false,
|
||||||
failOn: 'warning',
|
failOn: 'warning',
|
||||||
limitInputPixels: Math.pow(0x3FFF, 2),
|
limitInputPixels: Math.pow(0x3FFF, 2),
|
||||||
ignoreIcc: false,
|
ignoreIcc: false,
|
||||||
@@ -71,6 +76,18 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
|
} else if (!is.defined(input) && !is.defined(inputOptions) && is.object(containerOptions) && containerOptions.allowStream) {
|
||||||
// Stream without options
|
// Stream without options
|
||||||
inputDescriptor.buffer = [];
|
inputDescriptor.buffer = [];
|
||||||
|
} else if (Array.isArray(input)) {
|
||||||
|
if (input.length > 1) {
|
||||||
|
// Join images together
|
||||||
|
if (!this.options.joining) {
|
||||||
|
this.options.joining = true;
|
||||||
|
this.options.join = input.map(i => this._createInputDescriptor(i));
|
||||||
|
} else {
|
||||||
|
throw new Error('Recursive join is unsupported');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('Expected at least two images to join');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
|
throw new Error(`Unsupported input '${input}' of type ${typeof input}${
|
||||||
is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : ''
|
is.defined(inputOptions) ? ` when also providing options of type ${typeof inputOptions}` : ''
|
||||||
@@ -93,6 +110,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw is.invalidParameterError('failOn', 'one of: none, truncated, error, warning', inputOptions.failOn);
|
throw is.invalidParameterError('failOn', 'one of: none, truncated, error, warning', inputOptions.failOn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// autoOrient
|
||||||
|
if (is.defined(inputOptions.autoOrient)) {
|
||||||
|
if (is.bool(inputOptions.autoOrient)) {
|
||||||
|
inputDescriptor.autoOrient = inputOptions.autoOrient;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('autoOrient', 'boolean', inputOptions.autoOrient);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Density
|
// Density
|
||||||
if (is.defined(inputOptions.density)) {
|
if (is.defined(inputOptions.density)) {
|
||||||
if (is.inRange(inputOptions.density, 1, 100000)) {
|
if (is.inRange(inputOptions.density, 1, 100000)) {
|
||||||
@@ -222,6 +247,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
|
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// PDF background colour
|
||||||
|
if (is.defined(inputOptions.pdfBackground)) {
|
||||||
|
this._setBackgroundColourOption('pdfBackground', inputOptions.pdfBackground);
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (is.defined(inputOptions.create)) {
|
if (is.defined(inputOptions.create)) {
|
||||||
if (
|
if (
|
||||||
@@ -296,17 +325,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 +353,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,17 +367,17 @@ 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)) {
|
||||||
if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'wordChar', 'none'])) {
|
if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'word-char', 'none'])) {
|
||||||
inputDescriptor.textWrap = inputOptions.text.wrap;
|
inputDescriptor.textWrap = inputOptions.text.wrap;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('text.wrap', 'one of: word, char, wordChar, none', inputOptions.text.wrap);
|
throw is.invalidParameterError('text.wrap', 'one of: word, char, word-char, none', inputOptions.text.wrap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete inputDescriptor.buffer;
|
delete inputDescriptor.buffer;
|
||||||
@@ -356,6 +385,57 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw new Error('Expected a valid string to create an image with text.');
|
throw new Error('Expected a valid string to create an image with text.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Join images together
|
||||||
|
if (is.defined(inputOptions.join)) {
|
||||||
|
if (is.defined(this.options.join)) {
|
||||||
|
if (is.defined(inputOptions.join.animated)) {
|
||||||
|
if (is.bool(inputOptions.join.animated)) {
|
||||||
|
inputDescriptor.joinAnimated = inputOptions.join.animated;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('join.animated', 'boolean', inputOptions.join.animated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(inputOptions.join.across)) {
|
||||||
|
if (is.integer(inputOptions.join.across) && is.inRange(inputOptions.join.across, 1, 1000000)) {
|
||||||
|
inputDescriptor.joinAcross = inputOptions.join.across;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('join.across', 'integer between 1 and 100000', inputOptions.join.across);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(inputOptions.join.shim)) {
|
||||||
|
if (is.integer(inputOptions.join.shim) && is.inRange(inputOptions.join.shim, 0, 1000000)) {
|
||||||
|
inputDescriptor.joinShim = inputOptions.join.shim;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('join.shim', 'integer between 0 and 100000', inputOptions.join.shim);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(inputOptions.join.background)) {
|
||||||
|
const background = color(inputOptions.join.background);
|
||||||
|
inputDescriptor.joinBackground = [
|
||||||
|
background.red(),
|
||||||
|
background.green(),
|
||||||
|
background.blue(),
|
||||||
|
Math.round(background.alpha() * 255)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (is.defined(inputOptions.join.halign)) {
|
||||||
|
if (is.string(inputOptions.join.halign) && is.string(this.constructor.align[inputOptions.join.halign])) {
|
||||||
|
inputDescriptor.joinHalign = this.constructor.align[inputOptions.join.halign];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('join.halign', 'valid alignment', inputOptions.join.halign);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(inputOptions.join.valign)) {
|
||||||
|
if (is.string(inputOptions.join.valign) && is.string(this.constructor.align[inputOptions.join.valign])) {
|
||||||
|
inputDescriptor.joinValign = this.constructor.align[inputOptions.join.valign];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('join.valign', 'valid alignment', inputOptions.join.valign);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('Expected input to be an array of images to join');
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (is.defined(inputOptions)) {
|
} else if (is.defined(inputOptions)) {
|
||||||
throw new Error('Invalid input options ' + inputOptions);
|
throw new Error('Invalid input options ' + inputOptions);
|
||||||
}
|
}
|
||||||
@@ -430,15 +510,16 @@ function _isStreamInput () {
|
|||||||
* - `density`: Number of pixels per inch (DPI), if present
|
* - `density`: Number of pixels per inch (DPI), if present
|
||||||
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||||
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
|
* - `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
||||||
|
* - `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
||||||
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||||
* - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
|
||||||
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||||
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||||
* - `pagePrimary`: Number of the primary page in a HEIF image
|
* - `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||||
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||||
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images
|
||||||
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||||
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||||
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
@@ -450,6 +531,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();
|
||||||
@@ -469,28 +551,35 @@ function _isStreamInput () {
|
|||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Based on EXIF rotation metadata, get the right-side-up width and height:
|
* // Get dimensions taking EXIF Orientation into account.
|
||||||
*
|
* const { autoOrient } = await sharp(input).metadata();
|
||||||
* const size = getNormalSize(await sharp(input).metadata());
|
* const { width, height } = autoOrient;
|
||||||
*
|
|
||||||
* function getNormalSize({ width, height, orientation }) {
|
|
||||||
* return (orientation || 0) >= 5
|
|
||||||
* ? { width: height, height: width }
|
|
||||||
* : { width, height };
|
|
||||||
* }
|
|
||||||
*
|
*
|
||||||
* @param {Function} [callback] - called with the arguments `(err, metadata)`
|
* @param {Function} [callback] - called with the arguments `(err, metadata)`
|
||||||
* @returns {Promise<Object>|Sharp}
|
* @returns {Promise<Object>|Sharp}
|
||||||
*/
|
*/
|
||||||
function metadata (callback) {
|
function metadata (callback) {
|
||||||
|
const stack = Error();
|
||||||
if (is.fn(callback)) {
|
if (is.fn(callback)) {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', () => {
|
this.on('finish', () => {
|
||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.metadata(this.options, callback);
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
|
if (err) {
|
||||||
|
callback(is.nativeError(err, stack));
|
||||||
|
} else {
|
||||||
|
callback(null, metadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sharp.metadata(this.options, callback);
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
|
if (err) {
|
||||||
|
callback(is.nativeError(err, stack));
|
||||||
|
} else {
|
||||||
|
callback(null, metadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
@@ -500,7 +589,7 @@ function metadata (callback) {
|
|||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.metadata(this.options, (err, metadata) => {
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
resolve(metadata);
|
resolve(metadata);
|
||||||
}
|
}
|
||||||
@@ -516,7 +605,7 @@ function metadata (callback) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
sharp.metadata(this.options, (err, metadata) => {
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
resolve(metadata);
|
resolve(metadata);
|
||||||
}
|
}
|
||||||
@@ -572,14 +661,27 @@ function metadata (callback) {
|
|||||||
* @returns {Promise<Object>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
function stats (callback) {
|
function stats (callback) {
|
||||||
|
const stack = Error();
|
||||||
if (is.fn(callback)) {
|
if (is.fn(callback)) {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', () => {
|
this.on('finish', () => {
|
||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.stats(this.options, callback);
|
sharp.stats(this.options, (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
callback(is.nativeError(err, stack));
|
||||||
|
} else {
|
||||||
|
callback(null, stats);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sharp.stats(this.options, callback);
|
sharp.stats(this.options, (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
callback(is.nativeError(err, stack));
|
||||||
|
} else {
|
||||||
|
callback(null, stats);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
@@ -589,7 +691,7 @@ function stats (callback) {
|
|||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.stats(this.options, (err, stats) => {
|
sharp.stats(this.options, (err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
resolve(stats);
|
resolve(stats);
|
||||||
}
|
}
|
||||||
@@ -600,7 +702,7 @@ function stats (callback) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
sharp.stats(this.options, (err, stats) => {
|
sharp.stats(this.options, (err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
resolve(stats);
|
resolve(stats);
|
||||||
}
|
}
|
||||||
@@ -612,6 +714,7 @@ function stats (callback) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with input-related functions.
|
* Decorate the Sharp prototype with input-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
|
|||||||
16
lib/is.js
@@ -137,6 +137,19 @@ const invalidParameterError = function (name, expected, actual) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures an Error from C++ contains a JS stack.
|
||||||
|
*
|
||||||
|
* @param {Error} native - Error with message from C++.
|
||||||
|
* @param {Error} context - Error with stack from JS.
|
||||||
|
* @returns {Error} Error with message and stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const nativeError = function (native, context) {
|
||||||
|
context.message = native.message;
|
||||||
|
return context;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
defined,
|
defined,
|
||||||
object,
|
object,
|
||||||
@@ -151,5 +164,6 @@ module.exports = {
|
|||||||
integer,
|
integer,
|
||||||
inRange,
|
inRange,
|
||||||
inArray,
|
inArray,
|
||||||
invalidParameterError
|
invalidParameterError,
|
||||||
|
nativeError
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,19 +4,21 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { spawnSync } = require('node:child_process');
|
const { spawnSync } = require('node:child_process');
|
||||||
|
const { createHash } = require('node:crypto');
|
||||||
const semverCoerce = require('semver/functions/coerce');
|
const semverCoerce = require('semver/functions/coerce');
|
||||||
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
||||||
|
const semverSatisfies = require('semver/functions/satisfies');
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
|
|
||||||
const { engines } = 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 = [
|
||||||
'darwin-arm64', 'darwin-x64',
|
'darwin-arm64', 'darwin-x64',
|
||||||
'linux-arm', 'linux-arm64', 'linux-x64',
|
'linux-arm', 'linux-arm64', 'linux-s390x', 'linux-x64',
|
||||||
'linuxmusl-arm64', 'linuxmusl-x64',
|
'linuxmusl-arm64', 'linuxmusl-x64',
|
||||||
'win32-ia32', 'win32-x64'
|
'win32-ia32', 'win32-x64'
|
||||||
];
|
];
|
||||||
@@ -41,22 +43,30 @@ const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process
|
|||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const buildPlatformArch = () => {
|
const buildPlatformArch = () => {
|
||||||
|
if (isEmscripten()) {
|
||||||
|
return 'wasm32';
|
||||||
|
}
|
||||||
/* eslint camelcase: ["error", { allow: ["^npm_config_"] }] */
|
/* eslint camelcase: ["error", { allow: ["^npm_config_"] }] */
|
||||||
const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
|
const { npm_config_arch, npm_config_platform, npm_config_libc } = process.env;
|
||||||
return `${npm_config_platform || process.platform}${npm_config_libc || runtimeLibc()}-${npm_config_arch || process.arch}`;
|
const libc = typeof npm_config_libc === 'string' ? npm_config_libc : runtimeLibc();
|
||||||
|
return `${npm_config_platform || process.platform}${libc}-${npm_config_arch || process.arch}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildSharpLibvipsIncludeDir = () => {
|
const buildSharpLibvipsIncludeDir = () => {
|
||||||
try {
|
try {
|
||||||
return require('@sharpen/sharp-libvips-dev/include');
|
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
|
||||||
} catch {}
|
} catch {
|
||||||
|
try {
|
||||||
|
return require('@img/sharp-libvips-dev/include');
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildSharpLibvipsCPlusPlusDir = () => {
|
const buildSharpLibvipsCPlusPlusDir = () => {
|
||||||
try {
|
try {
|
||||||
return require('@sharpen/sharp-libvips-dev/cplusplus');
|
return require('@img/sharp-libvips-dev/cplusplus');
|
||||||
} catch {}
|
} catch {}
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
return '';
|
return '';
|
||||||
@@ -64,12 +74,31 @@ const buildSharpLibvipsCPlusPlusDir = () => {
|
|||||||
|
|
||||||
const buildSharpLibvipsLibDir = () => {
|
const buildSharpLibvipsLibDir = () => {
|
||||||
try {
|
try {
|
||||||
return require(`@sharpen/sharp-libvips-${buildPlatformArch()}/lib`);
|
return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
|
||||||
} catch {}
|
} catch {
|
||||||
|
try {
|
||||||
|
return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isUnsupportedNodeRuntime = () => {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (process.release?.name === 'node' && process.versions) {
|
||||||
|
if (!semverSatisfies(process.versions.node, engines.node)) {
|
||||||
|
return { found: process.versions.node, expected: engines.node };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
const isEmscripten = () => {
|
||||||
|
const { CC } = process.env;
|
||||||
|
return Boolean(CC && CC.endsWith('/emcc'));
|
||||||
|
};
|
||||||
|
|
||||||
const isRosetta = () => {
|
const isRosetta = () => {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (process.platform === 'darwin' && process.arch === 'x64') {
|
if (process.platform === 'darwin' && process.arch === 'x64') {
|
||||||
@@ -79,9 +108,22 @@ const isRosetta = () => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sha512 = (s) => createHash('sha512').update(s).digest('hex');
|
||||||
|
|
||||||
|
const yarnLocator = () => {
|
||||||
|
try {
|
||||||
|
const identHash = sha512(`imgsharp-libvips-${buildPlatformArch()}`);
|
||||||
|
const npmVersion = semverCoerce(optionalDependencies[`@img/sharp-libvips-${buildPlatformArch()}`], {
|
||||||
|
includePrerelease: true
|
||||||
|
}).version;
|
||||||
|
return sha512(`${identHash}npm:${npmVersion}`).slice(0, 10);
|
||||||
|
} catch {}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const spawnRebuild = () =>
|
const spawnRebuild = () =>
|
||||||
spawnSync('node-gyp rebuild --directory=src', {
|
spawnSync(`node-gyp rebuild --directory=src ${isEmscripten() ? '--nodedir=emscripten' : ''}`, {
|
||||||
...spawnSyncOptions,
|
...spawnSyncOptions,
|
||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
}).status;
|
}).status;
|
||||||
@@ -122,15 +164,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 */
|
||||||
@@ -144,8 +194,10 @@ module.exports = {
|
|||||||
buildSharpLibvipsIncludeDir,
|
buildSharpLibvipsIncludeDir,
|
||||||
buildSharpLibvipsCPlusPlusDir,
|
buildSharpLibvipsCPlusPlusDir,
|
||||||
buildSharpLibvipsLibDir,
|
buildSharpLibvipsLibDir,
|
||||||
|
isUnsupportedNodeRuntime,
|
||||||
runtimePlatformArch,
|
runtimePlatformArch,
|
||||||
log,
|
log,
|
||||||
|
yarnLocator,
|
||||||
spawnRebuild,
|
spawnRebuild,
|
||||||
globalLibvipsVersion,
|
globalLibvipsVersion,
|
||||||
pkgConfigPath,
|
pkgConfigPath,
|
||||||
|
|||||||
192
lib/operation.js
@@ -7,38 +7,37 @@ const color = require('color');
|
|||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate the output image by either an explicit angle
|
* How accurate an operation should be.
|
||||||
* or auto-orient based on the EXIF `Orientation` tag.
|
* @member
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const vipsPrecision = {
|
||||||
|
integer: 'integer',
|
||||||
|
float: 'float',
|
||||||
|
approximate: 'approximate'
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate the output image.
|
||||||
*
|
*
|
||||||
* If an angle is provided, it is converted to a valid positive degree rotation.
|
* The provided angle is converted to a valid positive degree rotation.
|
||||||
* For example, `-450` will produce a 270 degree rotation.
|
* For example, `-450` will produce a 270 degree rotation.
|
||||||
*
|
*
|
||||||
* When rotating by an angle other than a multiple of 90,
|
* When rotating by an angle other than a multiple of 90,
|
||||||
* the background colour can be provided with the `background` option.
|
* the background colour can be provided with the `background` option.
|
||||||
*
|
*
|
||||||
* If no angle is provided, it is determined from the EXIF data.
|
* For backwards compatibility, if no angle is provided, `.autoOrient()` will be called.
|
||||||
* Mirroring is supported and may infer the use of a flip operation.
|
|
||||||
*
|
*
|
||||||
* The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
|
* Only one rotation can occur per pipeline (aside from an initial call without
|
||||||
|
* arguments to orient via EXIF data). Previous calls to `rotate` in the same
|
||||||
|
* pipeline will be ignored.
|
||||||
*
|
*
|
||||||
* Only one rotation can occur per pipeline.
|
* Multi-page images can only be rotated by 180 degrees.
|
||||||
* Previous calls to `rotate` in the same pipeline will be ignored.
|
|
||||||
*
|
*
|
||||||
* Method order is important when rotating, resizing and/or extracting regions,
|
* Method order is important when rotating, resizing and/or extracting regions,
|
||||||
* for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
* for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const pipeline = sharp()
|
|
||||||
* .rotate()
|
|
||||||
* .resize(null, 200)
|
|
||||||
* .toBuffer(function (err, outputBuffer, info) {
|
|
||||||
* // outputBuffer contains 200px high JPEG image data,
|
|
||||||
* // auto-rotated using EXIF Orientation tag
|
|
||||||
* // info.width and info.height contain the dimensions of the resized image
|
|
||||||
* });
|
|
||||||
* readableStream.pipe(pipeline);
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const rotateThenResize = await sharp(input)
|
* const rotateThenResize = await sharp(input)
|
||||||
* .rotate(90)
|
* .rotate(90)
|
||||||
* .resize({ width: 16, height: 8, fit: 'fill' })
|
* .resize({ width: 16, height: 8, fit: 'fill' })
|
||||||
@@ -55,12 +54,15 @@ const is = require('./is');
|
|||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function rotate (angle, options) {
|
function rotate (angle, options) {
|
||||||
if (this.options.useExifOrientation || this.options.angle || this.options.rotationAngle) {
|
|
||||||
this.options.debuglog('ignoring previous rotate options');
|
|
||||||
}
|
|
||||||
if (!is.defined(angle)) {
|
if (!is.defined(angle)) {
|
||||||
this.options.useExifOrientation = true;
|
return this.autoOrient();
|
||||||
} else if (is.integer(angle) && !(angle % 90)) {
|
}
|
||||||
|
if (this.options.angle || this.options.rotationAngle) {
|
||||||
|
this.options.debuglog('ignoring previous rotate options');
|
||||||
|
this.options.angle = 0;
|
||||||
|
this.options.rotationAngle = 0;
|
||||||
|
}
|
||||||
|
if (is.integer(angle) && !(angle % 90)) {
|
||||||
this.options.angle = angle;
|
this.options.angle = angle;
|
||||||
} else if (is.number(angle)) {
|
} else if (is.number(angle)) {
|
||||||
this.options.rotationAngle = angle;
|
this.options.rotationAngle = angle;
|
||||||
@@ -79,6 +81,34 @@ function rotate (angle, options) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-orient based on the EXIF `Orientation` tag, then remove the tag.
|
||||||
|
* Mirroring is supported and may infer the use of a flip operation.
|
||||||
|
*
|
||||||
|
* Previous or subsequent use of `rotate(angle)` and either `flip()` or `flop()`
|
||||||
|
* will logically occur after auto-orientation, regardless of call order.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).autoOrient().toBuffer();
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const pipeline = sharp()
|
||||||
|
* .autoOrient()
|
||||||
|
* .resize(null, 200)
|
||||||
|
* .toBuffer(function (err, outputBuffer, info) {
|
||||||
|
* // outputBuffer contains 200px high JPEG image data,
|
||||||
|
* // auto-oriented using EXIF Orientation tag
|
||||||
|
* // info.width and info.height contain the dimensions of the resized image
|
||||||
|
* });
|
||||||
|
* readableStream.pipe(pipeline);
|
||||||
|
*
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
function autoOrient () {
|
||||||
|
this.options.input.autoOrient = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mirror the image vertically (up-down) about the x-axis.
|
* Mirror the image vertically (up-down) about the x-axis.
|
||||||
* This always occurs before rotation, if any.
|
* This always occurs before rotation, if any.
|
||||||
@@ -115,7 +145,7 @@ function flop (flop) {
|
|||||||
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||||
*
|
*
|
||||||
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||||
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
||||||
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||||
*
|
*
|
||||||
* In the case of a 2x2 matrix, the transform is:
|
* In the case of a 2x2 matrix, the transform is:
|
||||||
@@ -365,23 +395,97 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expand foreground objects using the dilate morphological operator.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input)
|
||||||
|
* .dilate()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @param {Number} [width=1] dilation width in pixels.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function dilate (width) {
|
||||||
|
if (!is.defined(width)) {
|
||||||
|
this.options.dilateWidth = 1;
|
||||||
|
} else if (is.integer(width) && width > 0) {
|
||||||
|
this.options.dilateWidth = width;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('dilate', 'positive integer', dilate);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink foreground objects using the erode morphological operator.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input)
|
||||||
|
* .erode()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @param {Number} [width=1] erosion width in pixels.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function erode (width) {
|
||||||
|
if (!is.defined(width)) {
|
||||||
|
this.options.erodeWidth = 1;
|
||||||
|
} else if (is.integer(width) && width > 0) {
|
||||||
|
this.options.erodeWidth = width;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('erode', 'positive integer', erode);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,24 +889,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,15 +993,19 @@ function modulate (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with operation-related functions.
|
* Decorate the Sharp prototype with operation-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
Object.assign(Sharp.prototype, {
|
Object.assign(Sharp.prototype, {
|
||||||
|
autoOrient,
|
||||||
rotate,
|
rotate,
|
||||||
flip,
|
flip,
|
||||||
flop,
|
flop,
|
||||||
affine,
|
affine,
|
||||||
sharpen,
|
sharpen,
|
||||||
|
erode,
|
||||||
|
dilate,
|
||||||
median,
|
median,
|
||||||
blur,
|
blur,
|
||||||
flatten,
|
flatten,
|
||||||
|
|||||||
321
lib/output.js
@@ -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
|
||||||
@@ -86,7 +87,8 @@ function toFile (fileOut, callback) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.options.fileOut = fileOut;
|
this.options.fileOut = fileOut;
|
||||||
return this._pipeline(callback);
|
const stack = Error();
|
||||||
|
return this._pipeline(callback, stack);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -108,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.
|
||||||
@@ -157,43 +160,190 @@ function toBuffer (options, callback) {
|
|||||||
this.options.resolveWithObject = false;
|
this.options.resolveWithObject = false;
|
||||||
}
|
}
|
||||||
this.options.fileOut = '';
|
this.options.fileOut = '';
|
||||||
return this._pipeline(is.fn(options) ? options : callback);
|
const stack = Error();
|
||||||
|
return this._pipeline(is.fn(options) ? options : callback, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
* Keep all EXIF metadata from the input image in the output image.
|
||||||
* This will also convert to and add a web-friendly sRGB ICC profile if appropriate,
|
|
||||||
* unless a custom output profile is provided.
|
|
||||||
*
|
|
||||||
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
|
|
||||||
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
|
||||||
*
|
*
|
||||||
* EXIF metadata is unsupported for TIFF output.
|
* EXIF metadata is unsupported for TIFF output.
|
||||||
*
|
*
|
||||||
* @example
|
* @since 0.33.0
|
||||||
* sharp('input.jpg')
|
|
||||||
* .withMetadata()
|
|
||||||
* .toFile('output-with-metadata.jpg')
|
|
||||||
* .then(info => { ... });
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Set output EXIF metadata
|
* const outputWithExif = await sharp(inputWithExif)
|
||||||
* const data = await sharp(input)
|
* .keepExif()
|
||||||
* .withMetadata({
|
* .toBuffer();
|
||||||
* exif: {
|
*
|
||||||
* IFD0: {
|
* @returns {Sharp}
|
||||||
* Copyright: 'The National Gallery'
|
*/
|
||||||
* },
|
function keepExif () {
|
||||||
* IFD3: {
|
this.options.keepMetadata |= 0b00001;
|
||||||
* GPSLatitudeRef: 'N',
|
return this;
|
||||||
* GPSLatitude: '51/1 30/1 3230/100',
|
}
|
||||||
* GPSLongitudeRef: 'W',
|
|
||||||
* GPSLongitude: '0/1 7/1 4366/100'
|
/**
|
||||||
* }
|
* Set EXIF metadata in the output image, ignoring any EXIF in the input image.
|
||||||
|
*
|
||||||
|
* @since 0.33.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const dataWithExif = await sharp(input)
|
||||||
|
* .withExif({
|
||||||
|
* IFD0: {
|
||||||
|
* Copyright: 'The National Gallery'
|
||||||
|
* },
|
||||||
|
* IFD3: {
|
||||||
|
* GPSLatitudeRef: 'N',
|
||||||
|
* GPSLatitude: '51/1 30/1 3230/100',
|
||||||
|
* GPSLongitudeRef: 'W',
|
||||||
|
* GPSLongitude: '0/1 7/1 4366/100'
|
||||||
* }
|
* }
|
||||||
* })
|
* })
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
|
* @param {Object<string, Object<string, string>>} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function withExif (exif) {
|
||||||
|
if (is.object(exif)) {
|
||||||
|
for (const [ifd, entries] of Object.entries(exif)) {
|
||||||
|
if (is.object(entries)) {
|
||||||
|
for (const [k, v] of Object.entries(entries)) {
|
||||||
|
if (is.string(v)) {
|
||||||
|
this.options.withExif[`exif-${ifd.toLowerCase()}-${k}`] = v;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError(`${ifd}.${k}`, 'string', v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError(ifd, 'object', entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('exif', 'object', exif);
|
||||||
|
}
|
||||||
|
this.options.withExifMerge = false;
|
||||||
|
return this.keepExif();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update EXIF metadata from the input image in the output image.
|
||||||
|
*
|
||||||
|
* @since 0.33.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const dataWithMergedExif = await sharp(inputWithExif)
|
||||||
|
* .withExifMerge({
|
||||||
|
* IFD0: {
|
||||||
|
* Copyright: 'The National Gallery'
|
||||||
|
* }
|
||||||
|
* })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @param {Object<string, Object<string, string>>} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function withExifMerge (exif) {
|
||||||
|
this.withExif(exif);
|
||||||
|
this.options.withExifMerge = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep ICC profile from the input image in the output image.
|
||||||
|
*
|
||||||
|
* Where necessary, will attempt to convert the output colour space to match the profile.
|
||||||
|
*
|
||||||
|
* @since 0.33.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const outputWithIccProfile = await sharp(inputWithIccProfile)
|
||||||
|
* .keepIccProfile()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
function keepIccProfile () {
|
||||||
|
this.options.keepMetadata |= 0b01000;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform using an ICC profile and attach to the output image.
|
||||||
|
*
|
||||||
|
* This can either be an absolute filesystem path or
|
||||||
|
* built-in profile name (`srgb`, `p3`, `cmyk`).
|
||||||
|
*
|
||||||
|
* @since 0.33.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const outputWithP3 = await sharp(input)
|
||||||
|
* .withIccProfile('p3')
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @param {string} icc - Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk).
|
||||||
|
* @param {Object} [options]
|
||||||
|
* @param {number} [options.attach=true] Should the ICC profile be included in the output image metadata?
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function withIccProfile (icc, options) {
|
||||||
|
if (is.string(icc)) {
|
||||||
|
this.options.withIccProfile = icc;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('icc', 'string', icc);
|
||||||
|
}
|
||||||
|
this.keepIccProfile();
|
||||||
|
if (is.object(options)) {
|
||||||
|
if (is.defined(options.attach)) {
|
||||||
|
if (is.bool(options.attach)) {
|
||||||
|
if (!options.attach) {
|
||||||
|
this.options.keepMetadata &= ~0b01000;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('attach', 'boolean', options.attach);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
|
||||||
|
*
|
||||||
|
* The default behaviour, when `keepMetadata` is not used, is to convert to the device-independent
|
||||||
|
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
||||||
|
*
|
||||||
|
* @since 0.33.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const outputWithMetadata = await sharp(inputWithMetadata)
|
||||||
|
* .keepMetadata()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
function keepMetadata () {
|
||||||
|
this.options.keepMetadata = 0b11111;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep most metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
||||||
|
*
|
||||||
|
* This will also convert to and add a web-friendly sRGB ICC profile if appropriate.
|
||||||
|
*
|
||||||
|
* Allows orientation and density to be set or updated.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const outputSrgbWithMetadata = await sharp(inputRgbWithMetadata)
|
||||||
|
* .withMetadata()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Set output metadata to 96 DPI
|
* // Set output metadata to 96 DPI
|
||||||
* const data = await sharp(input)
|
* const data = await sharp(input)
|
||||||
@@ -201,15 +351,14 @@ function toBuffer (options, callback) {
|
|||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
* @param {number} [options.orientation] Used to update the EXIF `Orientation` tag, integer between 1 and 8.
|
||||||
* @param {string} [options.icc='srgb'] Filesystem path to output ICC profile, relative to `process.cwd()`, defaults to built-in sRGB.
|
|
||||||
* @param {Object<Object>} [options.exif={}] Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
|
|
||||||
* @param {number} [options.density] Number of pixels per inch (DPI).
|
* @param {number} [options.density] Number of pixels per inch (DPI).
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function withMetadata (options) {
|
function withMetadata (options) {
|
||||||
this.options.withMetadata = is.bool(options) ? options : true;
|
this.keepMetadata();
|
||||||
|
this.withIccProfile('srgb');
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
if (is.defined(options.orientation)) {
|
if (is.defined(options.orientation)) {
|
||||||
if (is.integer(options.orientation) && is.inRange(options.orientation, 1, 8)) {
|
if (is.integer(options.orientation) && is.inRange(options.orientation, 1, 8)) {
|
||||||
@@ -226,30 +375,10 @@ function withMetadata (options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(options.icc)) {
|
if (is.defined(options.icc)) {
|
||||||
if (is.string(options.icc)) {
|
this.withIccProfile(options.icc);
|
||||||
this.options.withMetadataIcc = options.icc;
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('icc', 'string filesystem path to ICC profile', options.icc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (is.defined(options.exif)) {
|
if (is.defined(options.exif)) {
|
||||||
if (is.object(options.exif)) {
|
this.withExifMerge(options.exif);
|
||||||
for (const [ifd, entries] of Object.entries(options.exif)) {
|
|
||||||
if (is.object(entries)) {
|
|
||||||
for (const [k, v] of Object.entries(entries)) {
|
|
||||||
if (is.string(v)) {
|
|
||||||
this.options.withMetadataStrs[`exif-${ifd.toLowerCase()}-${k}`] = v;
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError(`exif.${ifd}.${k}`, 'string', v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError(`exif.${ifd}`, 'object', entries);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('exif', 'object', options.exif);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -377,10 +506,14 @@ function jpeg (options) {
|
|||||||
/**
|
/**
|
||||||
* Use these PNG options for output image.
|
* Use these PNG options for output image.
|
||||||
*
|
*
|
||||||
* By default, PNG output is full colour at 8 or 16 bits per pixel.
|
* By default, PNG output is full colour at 8 bits per pixel.
|
||||||
|
*
|
||||||
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||||
* Set `palette` to `true` for slower, indexed PNG output.
|
* Set `palette` to `true` for slower, indexed PNG output.
|
||||||
*
|
*
|
||||||
|
* For 16 bits per pixel output, convert to `rgb16` via
|
||||||
|
* {@link /api-colour#tocolourspace|toColourspace}.
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Convert any input to full colour PNG output
|
* // Convert any input to full colour PNG output
|
||||||
* const data = await sharp(input)
|
* const data = await sharp(input)
|
||||||
@@ -393,6 +526,13 @@ function jpeg (options) {
|
|||||||
* .png({ palette: true })
|
* .png({ palette: true })
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Output 16 bits per pixel RGB(A)
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .toColourspace('rgb16')
|
||||||
|
* .png()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
* @param {number} [options.compressionLevel=6] - zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest)
|
* @param {number} [options.compressionLevel=6] - zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest)
|
||||||
@@ -483,6 +623,7 @@ function png (options) {
|
|||||||
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
||||||
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
||||||
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
||||||
|
* @param {boolean} [options.smartDeblock=false] - auto-adjust the deblocking filter, can improve low contrast edges (slow)
|
||||||
* @param {string} [options.preset='default'] - named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text
|
* @param {string} [options.preset='default'] - named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text
|
||||||
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)
|
||||||
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||||
@@ -518,6 +659,9 @@ function webp (options) {
|
|||||||
if (is.defined(options.smartSubsample)) {
|
if (is.defined(options.smartSubsample)) {
|
||||||
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
|
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
|
||||||
}
|
}
|
||||||
|
if (is.defined(options.smartDeblock)) {
|
||||||
|
this._setBooleanOption('webpSmartDeblock', options.smartDeblock);
|
||||||
|
}
|
||||||
if (is.defined(options.preset)) {
|
if (is.defined(options.preset)) {
|
||||||
if (is.string(options.preset) && is.inArray(options.preset, ['default', 'photo', 'picture', 'drawing', 'icon', 'text'])) {
|
if (is.string(options.preset) && is.inArray(options.preset, ['default', 'photo', 'picture', 'drawing', 'icon', 'text'])) {
|
||||||
this.options.webpPreset = options.preset;
|
this.options.webpPreset = options.preset;
|
||||||
@@ -780,6 +924,7 @@ function trySetAnimationOptions (source, target) {
|
|||||||
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
|
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
|
||||||
* @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
|
* @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
|
||||||
* @param {number} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
|
* @param {number} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
|
||||||
|
* @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
@@ -817,6 +962,10 @@ function tiff (options) {
|
|||||||
throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
|
throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// miniswhite
|
||||||
|
if (is.defined(options.miniswhite)) {
|
||||||
|
this._setBooleanOption('tiffMiniswhite', options.miniswhite);
|
||||||
|
}
|
||||||
// pyramid
|
// pyramid
|
||||||
if (is.defined(options.pyramid)) {
|
if (is.defined(options.pyramid)) {
|
||||||
this._setBooleanOption('tiffPyramid', options.pyramid);
|
this._setBooleanOption('tiffPyramid', options.pyramid);
|
||||||
@@ -868,6 +1017,7 @@ function tiff (options) {
|
|||||||
* Use these AVIF options for output image.
|
* Use these AVIF options for output image.
|
||||||
*
|
*
|
||||||
* AVIF image sequences are not supported.
|
* AVIF image sequences are not supported.
|
||||||
|
* Prebuilt binaries support a bitdepth of 8 only.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const data = await sharp(input)
|
* const data = await sharp(input)
|
||||||
@@ -886,6 +1036,7 @@ function tiff (options) {
|
|||||||
* @param {boolean} [options.lossless=false] - use lossless compression
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
||||||
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
||||||
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
||||||
|
* @param {number} [options.bitdepth=8] - set bitdepth to 8, 10 or 12 bit
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
@@ -912,6 +1063,7 @@ function avif (options) {
|
|||||||
* @param {boolean} [options.lossless=false] - use lossless compression
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
||||||
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
||||||
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
||||||
|
* @param {number} [options.bitdepth=8] - set bitdepth to 8, 10 or 12 bit
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
@@ -950,6 +1102,16 @@ function heif (options) {
|
|||||||
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is.defined(options.bitdepth)) {
|
||||||
|
if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [8, 10, 12])) {
|
||||||
|
if (options.bitdepth !== 8 && this.constructor.versions.heif) {
|
||||||
|
throw is.invalidParameterError('bitdepth when using prebuilt binaries', 8, options.bitdepth);
|
||||||
|
}
|
||||||
|
this.options.heifBitdepth = options.bitdepth;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('bitdepth', '8, 10 or 12', options.bitdepth);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('options', 'Object', options);
|
throw is.invalidParameterError('options', 'Object', options);
|
||||||
}
|
}
|
||||||
@@ -965,8 +1127,6 @@ function heif (options) {
|
|||||||
* The prebuilt binaries do not include this - see
|
* The prebuilt binaries do not include this - see
|
||||||
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
||||||
*
|
*
|
||||||
* Image metadata (EXIF, XMP) is unsupported.
|
|
||||||
*
|
|
||||||
* @since 0.31.3
|
* @since 0.31.3
|
||||||
*
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
@@ -974,7 +1134,9 @@ function heif (options) {
|
|||||||
* @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
|
* @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
|
||||||
* @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality)
|
* @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality)
|
||||||
* @param {boolean} [options.lossless=false] - use lossless compression
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
||||||
* @param {number} [options.effort=7] - CPU effort, between 3 (fastest) and 9 (slowest)
|
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 9 (slowest)
|
||||||
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||||
|
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
@@ -1011,13 +1173,14 @@ function jxl (options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(options.effort)) {
|
if (is.defined(options.effort)) {
|
||||||
if (is.integer(options.effort) && is.inRange(options.effort, 3, 9)) {
|
if (is.integer(options.effort) && is.inRange(options.effort, 1, 9)) {
|
||||||
this.options.jxlEffort = options.effort;
|
this.options.jxlEffort = options.effort;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('effort', 'integer between 3 and 9', options.effort);
|
throw is.invalidParameterError('effort', 'integer between 1 and 9', options.effort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
trySetAnimationOptions(options, this.options);
|
||||||
return this._updateFormatOut('jxl', options);
|
return this._updateFormatOut('jxl', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1069,10 +1232,6 @@ function raw (options) {
|
|||||||
*
|
*
|
||||||
* The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
* The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
||||||
*
|
*
|
||||||
* Requires libvips compiled with support for libgsf.
|
|
||||||
* The prebuilt binaries do not include this - see
|
|
||||||
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
|
||||||
*
|
|
||||||
* @example
|
* @example
|
||||||
* sharp('input.tiff')
|
* sharp('input.tiff')
|
||||||
* .png()
|
* .png()
|
||||||
@@ -1101,7 +1260,7 @@ function raw (options) {
|
|||||||
* @param {number} [options.angle=0] tile angle of rotation, must be a multiple of 90.
|
* @param {number} [options.angle=0] tile angle of rotation, must be a multiple of 90.
|
||||||
* @param {string|Object} [options.background={r: 255, g: 255, b: 255, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency.
|
* @param {string|Object} [options.background={r: 255, g: 255, b: 255, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency.
|
||||||
* @param {string} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
* @param {string} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
* @param {number} [options.skipBlanks=-1] threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images
|
* @param {number} [options.skipBlanks=-1] Threshold to skip tile generation. Range is 0-255 for 8-bit images, 0-65535 for 16-bit images. Default is 5 for `google` layout, -1 (no skip) otherwise.
|
||||||
* @param {string} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
* @param {string} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
||||||
* @param {string} [options.layout='dz'] filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`.
|
* @param {string} [options.layout='dz'] filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`.
|
||||||
* @param {boolean} [options.centre=false] centre image in tile.
|
* @param {boolean} [options.centre=false] centre image in tile.
|
||||||
@@ -1282,7 +1441,8 @@ function _read () {
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (!this.options.streamOut) {
|
if (!this.options.streamOut) {
|
||||||
this.options.streamOut = true;
|
this.options.streamOut = true;
|
||||||
this._pipeline();
|
const stack = Error();
|
||||||
|
this._pipeline(undefined, stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1291,18 +1451,30 @@ function _read () {
|
|||||||
* Supports callback, stream and promise variants
|
* Supports callback, stream and promise variants
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _pipeline (callback) {
|
function _pipeline (callback, stack) {
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
// output=file/buffer
|
// output=file/buffer
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
// output=file/buffer, input=stream
|
// output=file/buffer, input=stream
|
||||||
this.on('finish', () => {
|
this.on('finish', () => {
|
||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.pipeline(this.options, callback);
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
|
if (err) {
|
||||||
|
callback(is.nativeError(err, stack));
|
||||||
|
} else {
|
||||||
|
callback(null, data, info);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// output=file/buffer, input=file/buffer
|
// output=file/buffer, input=file/buffer
|
||||||
sharp.pipeline(this.options, callback);
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
|
if (err) {
|
||||||
|
callback(is.nativeError(err, stack));
|
||||||
|
} else {
|
||||||
|
callback(null, data, info);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
} else if (this.options.streamOut) {
|
} else if (this.options.streamOut) {
|
||||||
@@ -1313,7 +1485,7 @@ function _pipeline (callback) {
|
|||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.pipeline(this.options, (err, data, info) => {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.emit('error', err);
|
this.emit('error', is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
this.emit('info', info);
|
this.emit('info', info);
|
||||||
this.push(data);
|
this.push(data);
|
||||||
@@ -1329,7 +1501,7 @@ function _pipeline (callback) {
|
|||||||
// output=stream, input=file/buffer
|
// output=stream, input=file/buffer
|
||||||
sharp.pipeline(this.options, (err, data, info) => {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.emit('error', err);
|
this.emit('error', is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
this.emit('info', info);
|
this.emit('info', info);
|
||||||
this.push(data);
|
this.push(data);
|
||||||
@@ -1348,7 +1520,7 @@ function _pipeline (callback) {
|
|||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.pipeline(this.options, (err, data, info) => {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
if (this.options.resolveWithObject) {
|
if (this.options.resolveWithObject) {
|
||||||
resolve({ data, info });
|
resolve({ data, info });
|
||||||
@@ -1364,7 +1536,7 @@ function _pipeline (callback) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
sharp.pipeline(this.options, (err, data, info) => {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(is.nativeError(err, stack));
|
||||||
} else {
|
} else {
|
||||||
if (this.options.resolveWithObject) {
|
if (this.options.resolveWithObject) {
|
||||||
resolve({ data, info });
|
resolve({ data, info });
|
||||||
@@ -1380,6 +1552,7 @@ function _pipeline (callback) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with output-related functions.
|
* Decorate the Sharp prototype with output-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
@@ -1387,6 +1560,12 @@ module.exports = function (Sharp) {
|
|||||||
// Public
|
// Public
|
||||||
toFile,
|
toFile,
|
||||||
toBuffer,
|
toBuffer,
|
||||||
|
keepExif,
|
||||||
|
withExif,
|
||||||
|
withExifMerge,
|
||||||
|
keepIccProfile,
|
||||||
|
withIccProfile,
|
||||||
|
keepMetadata,
|
||||||
withMetadata,
|
withMetadata,
|
||||||
toFormat,
|
toFormat,
|
||||||
jpeg,
|
jpeg,
|
||||||
|
|||||||
105
lib/resize.js
@@ -68,10 +68,13 @@ const strategy = {
|
|||||||
*/
|
*/
|
||||||
const kernel = {
|
const kernel = {
|
||||||
nearest: 'nearest',
|
nearest: 'nearest',
|
||||||
|
linear: 'linear',
|
||||||
cubic: 'cubic',
|
cubic: 'cubic',
|
||||||
mitchell: 'mitchell',
|
mitchell: 'mitchell',
|
||||||
lanczos2: 'lanczos2',
|
lanczos2: 'lanczos2',
|
||||||
lanczos3: 'lanczos3'
|
lanczos3: 'lanczos3',
|
||||||
|
mks2013: 'mks2013',
|
||||||
|
mks2021: 'mks2021'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +107,7 @@ const mapFitToCanvas = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function isRotationExpected (options) {
|
function isRotationExpected (options) {
|
||||||
return (options.angle % 360) !== 0 || options.useExifOrientation === true || options.rotationAngle !== 0;
|
return (options.angle % 360) !== 0 || options.input.autoOrient === true || options.rotationAngle !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,18 +138,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 +246,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.
|
||||||
@@ -494,70 +501,67 @@ function extract (options) {
|
|||||||
*
|
*
|
||||||
* If the result of this operation would trim an image to nothing then no change is made.
|
* If the result of this operation would trim an image to nothing then no change is made.
|
||||||
*
|
*
|
||||||
* The `info` response Object, obtained from callback of `.toFile()` or `.toBuffer()`,
|
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
* will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Trim pixels with a colour similar to that of the top-left pixel.
|
* // Trim pixels with a colour similar to that of the top-left pixel.
|
||||||
* sharp(input)
|
* await sharp(input)
|
||||||
* .trim()
|
* .trim()
|
||||||
* .toFile(output, function(err, info) {
|
* .toFile(output);
|
||||||
* ...
|
*
|
||||||
* });
|
|
||||||
* @example
|
* @example
|
||||||
* // Trim pixels with the exact same colour as that of the top-left pixel.
|
* // Trim pixels with the exact same colour as that of the top-left pixel.
|
||||||
* sharp(input)
|
* await sharp(input)
|
||||||
* .trim(0)
|
* .trim({
|
||||||
* .toFile(output, function(err, info) {
|
* threshold: 0
|
||||||
* ...
|
* })
|
||||||
* });
|
* .toFile(output);
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Trim only pixels with a similar colour to red.
|
* // Assume input is line art and trim only pixels with a similar colour to red.
|
||||||
* sharp(input)
|
* const output = await sharp(input)
|
||||||
* .trim("#FF0000")
|
* .trim({
|
||||||
* .toFile(output, function(err, info) {
|
* background: "#FF0000",
|
||||||
* ...
|
* lineArt: true
|
||||||
* });
|
* })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
* // Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
||||||
* sharp(input)
|
* const output = await sharp(input)
|
||||||
* .trim({
|
* .trim({
|
||||||
* background: "yellow",
|
* background: "yellow",
|
||||||
* threshold: 42,
|
* threshold: 42,
|
||||||
* })
|
* })
|
||||||
* .toFile(output, function(err, info) {
|
* .toBuffer();
|
||||||
* ...
|
|
||||||
* });
|
|
||||||
*
|
*
|
||||||
* @param {string|number|Object} trim - the specific background colour to trim, the threshold for doing so or an Object with both.
|
* @param {Object} [options]
|
||||||
* @param {string|Object} [trim.background='top-left pixel'] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
|
* @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
|
||||||
* @param {number} [trim.threshold=10] - the allowed difference from the above colour, a positive number.
|
* @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
|
||||||
|
* @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function trim (trim) {
|
function trim (options) {
|
||||||
if (!is.defined(trim)) {
|
this.options.trimThreshold = 10;
|
||||||
this.options.trimThreshold = 10;
|
if (is.defined(options)) {
|
||||||
} else if (is.string(trim)) {
|
if (is.object(options)) {
|
||||||
this._setBackgroundColourOption('trimBackground', trim);
|
if (is.defined(options.background)) {
|
||||||
this.options.trimThreshold = 10;
|
this._setBackgroundColourOption('trimBackground', options.background);
|
||||||
} else if (is.number(trim)) {
|
}
|
||||||
if (trim >= 0) {
|
if (is.defined(options.threshold)) {
|
||||||
this.options.trimThreshold = trim;
|
if (is.number(options.threshold) && options.threshold >= 0) {
|
||||||
|
this.options.trimThreshold = options.threshold;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('threshold', 'positive number', options.threshold);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.lineArt)) {
|
||||||
|
this._setBooleanOption('trimLineArt', options.lineArt);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('threshold', 'positive number', trim);
|
throw is.invalidParameterError('trim', 'object', options);
|
||||||
}
|
}
|
||||||
} else if (is.object(trim)) {
|
|
||||||
this._setBackgroundColourOption('trimBackground', trim.background);
|
|
||||||
if (!is.defined(trim.threshold)) {
|
|
||||||
this.options.trimThreshold = 10;
|
|
||||||
} else if (is.number(trim.threshold) && trim.threshold >= 0) {
|
|
||||||
this.options.trimThreshold = trim.threshold;
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('threshold', 'positive number', trim);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('trim', 'string, number or object', trim);
|
|
||||||
}
|
}
|
||||||
if (isRotationExpected(this.options)) {
|
if (isRotationExpected(this.options)) {
|
||||||
this.options.rotateBeforePreExtract = true;
|
this.options.rotateBeforePreExtract = true;
|
||||||
@@ -567,6 +571,7 @@ function trim (trim) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with resize-related functions.
|
* Decorate the Sharp prototype with resize-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
|
|||||||
160
lib/sharp.js
@@ -7,60 +7,116 @@
|
|||||||
|
|
||||||
const { familySync, versionSync } = require('detect-libc');
|
const { familySync, versionSync } = require('detect-libc');
|
||||||
|
|
||||||
const { runtimePlatformArch, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
||||||
const runtimePlatform = runtimePlatformArch();
|
const runtimePlatform = runtimePlatformArch();
|
||||||
const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
const paths = [
|
||||||
try {
|
`../src/build/Release/sharp-${runtimePlatform}.node`,
|
||||||
// Check for local build
|
'../src/build/Release/sharp-wasm32.node',
|
||||||
module.exports = require(`../src/build/Release/sharp-${runtimePlatform}.node`);
|
`@img/sharp-${runtimePlatform}/sharp.node`,
|
||||||
} catch (errLocal) {
|
'@img/sharp-wasm32/sharp.node'
|
||||||
|
];
|
||||||
|
|
||||||
|
let path, sharp;
|
||||||
|
const errors = [];
|
||||||
|
for (path of paths) {
|
||||||
try {
|
try {
|
||||||
// Check for runtime package
|
sharp = require(path);
|
||||||
module.exports = require(`@sharpen/sharp-${runtimePlatform}/sharp.node`);
|
break;
|
||||||
} catch (errPackage) {
|
} catch (err) {
|
||||||
const help = ['Could not load the "sharp" module at runtime'];
|
/* istanbul ignore next */
|
||||||
if (errLocal.code !== 'MODULE_NOT_FOUND') {
|
errors.push(err);
|
||||||
help.push(`${errLocal.code}: ${errLocal.message}`);
|
|
||||||
}
|
|
||||||
if (errPackage.code !== 'MODULE_NOT_FOUND') {
|
|
||||||
help.push(`${errPackage.code}: ${errPackage.message}`);
|
|
||||||
}
|
|
||||||
help.push('Possible solutions:');
|
|
||||||
// Common error messages
|
|
||||||
if (prebuiltPlatforms.includes(runtimePlatform)) {
|
|
||||||
help.push('- Add explicit dependencies for the runtime platform:');
|
|
||||||
help.push(` npm install --force @sharpen/sharp-${runtimePlatform}`);
|
|
||||||
if (!isWindows) {
|
|
||||||
help.push(` npm install --force @sharpen/sharp-libvips-${runtimePlatform}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
help.push(`- The ${runtimePlatform} platform requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
|
||||||
}
|
|
||||||
if (isLinux && /symbol not found/i.test(errPackage)) {
|
|
||||||
try {
|
|
||||||
const { engines } = require(`@sharpen/sharp-libvips-${runtimePlatform}/package`);
|
|
||||||
const libcFound = `${familySync()} ${versionSync()}`;
|
|
||||||
const libcRequires = `${engines.musl ? 'musl' : 'glibc'} ${engines.musl || engines.glibc}`;
|
|
||||||
help.push(`- Update your OS: found ${libcFound}, requires ${libcRequires}`);
|
|
||||||
} catch (errEngines) {}
|
|
||||||
}
|
|
||||||
if (isMacOs && /Incompatible library version/.test(errLocal.message)) {
|
|
||||||
help.push('- Update Homebrew:');
|
|
||||||
help.push(' brew update && brew upgrade vips');
|
|
||||||
}
|
|
||||||
if (errPackage.code === 'ERR_DLOPEN_DISABLED') {
|
|
||||||
help.push('- Run Node.js without using the --no-addons flag');
|
|
||||||
}
|
|
||||||
// Link to installation docs
|
|
||||||
if (isLinux && /Module did not self-register/.test(errLocal.message + errPackage.message)) {
|
|
||||||
help.push('- Using worker threads on Linux? See https://sharp.pixelplumbing.com/install#worker-threads');
|
|
||||||
} else if (isWindows && /The specified procedure could not be found/.test(errPackage.message)) {
|
|
||||||
help.push('- Using the canvas package on Windows? See https://sharp.pixelplumbing.com/install#canvas-and-windows');
|
|
||||||
} else {
|
|
||||||
help.push('- Consult the installation documentation: https://sharp.pixelplumbing.com/install');
|
|
||||||
}
|
|
||||||
throw new Error(help.join('\n'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) {
|
||||||
|
const err = new Error('Prebuilt binaries for linux-x64 require v2 microarchitecture');
|
||||||
|
err.code = 'Unsupported CPU';
|
||||||
|
errors.push(err);
|
||||||
|
sharp = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (sharp) {
|
||||||
|
module.exports = sharp;
|
||||||
|
} else {
|
||||||
|
const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
|
||||||
|
|
||||||
|
const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
|
||||||
|
errors.forEach(err => {
|
||||||
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
||||||
|
help.push(`${err.code}: ${err.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const messages = errors.map(err => err.message).join(' ');
|
||||||
|
help.push('Possible solutions:');
|
||||||
|
// Common error messages
|
||||||
|
if (isUnsupportedNodeRuntime()) {
|
||||||
|
const { found, expected } = isUnsupportedNodeRuntime();
|
||||||
|
help.push(
|
||||||
|
'- Please upgrade Node.js:',
|
||||||
|
` Found ${found}`,
|
||||||
|
` Requires ${expected}`
|
||||||
|
);
|
||||||
|
} else if (prebuiltPlatforms.includes(runtimePlatform)) {
|
||||||
|
const [os, cpu] = runtimePlatform.split('-');
|
||||||
|
const libc = os.endsWith('musl') ? ' --libc=musl' : '';
|
||||||
|
help.push(
|
||||||
|
'- Ensure optional dependencies can be installed:',
|
||||||
|
' npm install --include=optional sharp',
|
||||||
|
'- Ensure your package manager supports multi-platform installation:',
|
||||||
|
' See https://sharp.pixelplumbing.com/install#cross-platform',
|
||||||
|
'- Add platform-specific dependencies:',
|
||||||
|
` npm install --os=${os.replace('musl', '')}${libc} --cpu=${cpu} sharp`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
help.push(
|
||||||
|
`- Manually install libvips >= ${minimumLibvipsVersion}`,
|
||||||
|
'- Add experimental WebAssembly-based dependencies:',
|
||||||
|
' npm install --cpu=wasm32 sharp',
|
||||||
|
' npm install @img/sharp-wasm32'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
|
||||||
|
try {
|
||||||
|
const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`);
|
||||||
|
const libcFound = `${familySync()} ${versionSync()}`;
|
||||||
|
const libcRequires = `${config.musl ? 'musl' : 'glibc'} ${config.musl || config.glibc}`;
|
||||||
|
help.push(
|
||||||
|
'- Update your OS:',
|
||||||
|
` Found ${libcFound}`,
|
||||||
|
` Requires ${libcRequires}`
|
||||||
|
);
|
||||||
|
} catch (errEngines) {}
|
||||||
|
}
|
||||||
|
if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
|
||||||
|
help.push(
|
||||||
|
'- Remove the Node.js Snap, which does not support native modules',
|
||||||
|
' snap remove node'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isMacOs && /Incompatible library version/.test(messages)) {
|
||||||
|
help.push(
|
||||||
|
'- Update Homebrew:',
|
||||||
|
' brew update && brew upgrade vips'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
|
||||||
|
help.push('- Run Node.js without using the --no-addons flag');
|
||||||
|
}
|
||||||
|
// Link to installation docs
|
||||||
|
if (isWindows && /The specified procedure could not be found/.test(messages)) {
|
||||||
|
help.push(
|
||||||
|
'- Using the canvas package on Windows?',
|
||||||
|
' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
|
||||||
|
'- Check for outdated versions of sharp in the dependency tree:',
|
||||||
|
' npm ls sharp'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
help.push(
|
||||||
|
'- Consult the installation documentation:',
|
||||||
|
' See https://sharp.pixelplumbing.com/install'
|
||||||
|
);
|
||||||
|
throw new Error(help.join('\n'));
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ const is = require('./is');
|
|||||||
const { runtimePlatformArch } = require('./libvips');
|
const { runtimePlatformArch } = require('./libvips');
|
||||||
const sharp = require('./sharp');
|
const sharp = require('./sharp');
|
||||||
|
|
||||||
|
const runtimePlatform = runtimePlatformArch();
|
||||||
|
const libvipsVersion = sharp.libvipsVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Object containing nested boolean values representing the available input and output formats/methods.
|
* An Object containing nested boolean values representing the available input and output formats/methods.
|
||||||
* @member
|
* @member
|
||||||
@@ -44,23 +47,41 @@ const interpolators = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Object containing the version numbers of sharp, libvips and its dependencies.
|
* An Object containing the version numbers of sharp, libvips
|
||||||
|
* and (when using prebuilt binaries) its dependencies.
|
||||||
|
*
|
||||||
* @member
|
* @member
|
||||||
* @example
|
* @example
|
||||||
* console.log(sharp.versions);
|
* console.log(sharp.versions);
|
||||||
*/
|
*/
|
||||||
let versions = {
|
let versions = {
|
||||||
vips: sharp.libvipsVersion()
|
vips: libvipsVersion.semver
|
||||||
};
|
};
|
||||||
try {
|
/* istanbul ignore next */
|
||||||
versions = require(`@sharpen/sharp-${runtimePlatformArch()}/versions`);
|
if (!libvipsVersion.isGlobal) {
|
||||||
} catch (_) {
|
if (!libvipsVersion.isWasm) {
|
||||||
try {
|
try {
|
||||||
versions = require(`@sharpen/sharp-libvips-${runtimePlatformArch()}/versions`);
|
versions = require(`@img/sharp-${runtimePlatform}/versions`);
|
||||||
} catch (_) {}
|
} catch (_) {
|
||||||
|
try {
|
||||||
|
versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`);
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
versions = require('@img/sharp-wasm32/versions');
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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.
|
||||||
@@ -139,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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,17 +193,17 @@ function counters () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get and set use of SIMD vector unit instructions.
|
* Get and set use of SIMD vector unit instructions.
|
||||||
* Requires libvips to have been compiled with liborc support.
|
* Requires libvips to have been compiled with highway support.
|
||||||
*
|
*
|
||||||
* Improves the performance of `resize`, `blur` and `sharpen` operations
|
* Improves the performance of `resize`, `blur` and `sharpen` operations
|
||||||
* by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
* by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const simd = sharp.simd();
|
* const simd = sharp.simd();
|
||||||
* // simd is `true` if the runtime use of liborc is currently enabled
|
* // simd is `true` if the runtime use of highway is currently enabled
|
||||||
* @example
|
* @example
|
||||||
* const simd = sharp.simd(false);
|
* const simd = sharp.simd(false);
|
||||||
* // prevent libvips from using liborc at runtime
|
* // prevent libvips from using highway at runtime
|
||||||
*
|
*
|
||||||
* @param {boolean} [simd=true]
|
* @param {boolean} [simd=true]
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -187,7 +211,6 @@ function counters () {
|
|||||||
function simd (simd) {
|
function simd (simd) {
|
||||||
return sharp.simd(is.bool(simd) ? simd : null);
|
return sharp.simd(is.bool(simd) ? simd : null);
|
||||||
}
|
}
|
||||||
simd(true);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block libvips operations at runtime.
|
* Block libvips operations at runtime.
|
||||||
@@ -257,6 +280,7 @@ function unblock (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp class with utility-related functions.
|
* Decorate the Sharp class with utility-related functions.
|
||||||
|
* @module Sharp
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-darwin-arm64",
|
"name": "@img/sharp-darwin-arm64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.1",
|
||||||
"description": "Prebuilt sharp for use with macOS ARM64",
|
"description": "Prebuilt sharp for use with macOS 64-bit ARM",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-darwin-arm64": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-darwin-x64",
|
"name": "@img/sharp-darwin-x64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.1",
|
||||||
"description": "Prebuilt sharp for use with macOS x64",
|
"description": "Prebuilt sharp for use with macOS x64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-darwin-x64": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
// Populate contents of all packages with the current GitHub release
|
// Populate contents of all packages with the current GitHub release
|
||||||
|
|
||||||
const { writeFile, copyFile, rm } = require('node:fs/promises');
|
const { readFile, writeFile, appendFile, copyFile, rm } = require('node:fs/promises');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const { Readable } = require('node:stream');
|
const { Readable } = require('node:stream');
|
||||||
const { pipeline } = require('node:stream/promises');
|
const { pipeline } = require('node:stream/promises');
|
||||||
@@ -38,7 +38,8 @@ limitations under the License.
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
workspaces.map(async platform => {
|
workspaces.map(async platform => {
|
||||||
const url = `https://github.com/lovell/sharp/releases/download/v${version}/sharp-v${version}-napi-v9-${platform}.tar.gz`;
|
const prebuildPlatform = platform === 'wasm32' ? 'emscripten-wasm32' : platform;
|
||||||
|
const url = `https://github.com/lovell/sharp/releases/download/v${version}/sharp-v${version}-napi-v9-${prebuildPlatform}.tar.gz`;
|
||||||
const dir = path.join(__dirname, platform);
|
const dir = path.join(__dirname, platform);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -47,7 +48,7 @@ workspaces.map(async platform => {
|
|||||||
}
|
}
|
||||||
// Extract prebuild tarball
|
// Extract prebuild tarball
|
||||||
const lib = path.join(dir, 'lib');
|
const lib = path.join(dir, 'lib');
|
||||||
await rm(lib, { recursive: true });
|
await rm(lib, { force: true, recursive: true });
|
||||||
await pipeline(
|
await pipeline(
|
||||||
Readable.fromWeb(response.body),
|
Readable.fromWeb(response.body),
|
||||||
createGunzip(),
|
createGunzip(),
|
||||||
@@ -58,13 +59,15 @@ workspaces.map(async platform => {
|
|||||||
await writeFile(path.join(dir, 'README.md'), `# \`${name}\`\n\n${description}.\n${licensing}`);
|
await writeFile(path.join(dir, 'README.md'), `# \`${name}\`\n\n${description}.\n${licensing}`);
|
||||||
// Copy Apache-2.0 LICENSE
|
// Copy Apache-2.0 LICENSE
|
||||||
await copyFile(path.join(__dirname, '..', 'LICENSE'), path.join(dir, 'LICENSE'));
|
await copyFile(path.join(__dirname, '..', 'LICENSE'), path.join(dir, 'LICENSE'));
|
||||||
// Copy Windows-specific files
|
// Copy files for packages without an explicit sharp-libvips dependency (Windows, wasm)
|
||||||
if (platform.startsWith('win32-')) {
|
if (platform.startsWith('win') || platform.startsWith('wasm')) {
|
||||||
const sharpLibvipsDir = path.join(require(`@sharpen/sharp-libvips-${platform}/lib`), '..');
|
const libvipsPlatform = platform === 'wasm32' ? 'dev-wasm32' : platform;
|
||||||
await Promise.all(
|
const sharpLibvipsDir = path.join(require(`@img/sharp-libvips-${libvipsPlatform}/lib`), '..');
|
||||||
['versions.json', 'THIRD-PARTY-NOTICES.md'].map(
|
// Copy versions.json
|
||||||
filename => copyFile(path.join(sharpLibvipsDir, filename), path.join(dir, filename))
|
await copyFile(path.join(sharpLibvipsDir, 'versions.json'), path.join(dir, 'versions.json'));
|
||||||
)
|
// Append third party licensing to README
|
||||||
);
|
const readme = await readFile(path.join(sharpLibvipsDir, 'README.md'), { encoding: 'utf-8' });
|
||||||
|
const thirdParty = readme.substring(readme.indexOf('\nThis software contains'));
|
||||||
|
appendFile(path.join(dir, 'README.md'), thirdParty);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linux-arm",
|
"name": "@img/sharp-linux-arm",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.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>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-arm": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linux-arm64",
|
"name": "@img/sharp-linux-arm64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.1",
|
||||||
"description": "Prebuilt sharp for use with Linux (glibc) ARM64",
|
"description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-arm64": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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": [
|
||||||
|
|||||||
46
npm/linux-ppc64/package.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-linux-ppc64",
|
||||||
|
"version": "0.34.1",
|
||||||
|
"description": "Prebuilt sharp for use with Linux (glibc) ppc64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp.git",
|
||||||
|
"directory": "npm/linux-ppc64"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-ppc64": "1.1.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./sharp.node": "./lib/sharp-linux-ppc64.node",
|
||||||
|
"./package": "./package.json"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"glibc": ">=2.31"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"libc": [
|
||||||
|
"glibc"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"ppc64"
|
||||||
|
]
|
||||||
|
}
|
||||||
46
npm/linux-s390x/package.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-linux-s390x",
|
||||||
|
"version": "0.34.1",
|
||||||
|
"description": "Prebuilt sharp for use with Linux (glibc) s390x",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp.git",
|
||||||
|
"directory": "npm/linux-s390x"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-s390x": "1.1.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./sharp.node": "./lib/sharp-linux-s390x.node",
|
||||||
|
"./package": "./package.json"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"glibc": ">=2.31"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"libc": [
|
||||||
|
"glibc"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"s390x"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linux-x64",
|
"name": "@img/sharp-linux-x64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.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>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-x64": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linuxmusl-arm64",
|
"name": "@img/sharp-linuxmusl-arm64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.1",
|
||||||
"description": "Prebuilt sharp for use with Linux (musl) ARM64",
|
"description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-linuxmusl-x64",
|
"name": "@img/sharp-linuxmusl-x64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.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>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,6 +14,9 @@
|
|||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linuxmusl-x64": "1.1.0"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@@ -25,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,15 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp",
|
"name": "@img/sharp",
|
||||||
"version": "0.0.1-alpha.1",
|
"version": "0.34.1",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"darwin-x64",
|
|
||||||
"darwin-arm64",
|
"darwin-arm64",
|
||||||
|
"darwin-x64",
|
||||||
"linux-arm",
|
"linux-arm",
|
||||||
"linux-arm64",
|
"linux-arm64",
|
||||||
|
"linux-ppc64",
|
||||||
|
"linux-s390x",
|
||||||
|
"linux-x64",
|
||||||
"linuxmusl-arm64",
|
"linuxmusl-arm64",
|
||||||
"linuxmusl-x64",
|
"linuxmusl-x64",
|
||||||
"linux-x64",
|
"wasm32",
|
||||||
"win32-ia32",
|
"win32-ia32",
|
||||||
"win32-x64"
|
"win32-x64"
|
||||||
]
|
]
|
||||||
|
|||||||
39
npm/wasm32/package.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-wasm32",
|
||||||
|
"version": "0.34.1",
|
||||||
|
"description": "Prebuilt sharp for use with wasm32",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp.git",
|
||||||
|
"directory": "npm/wasm32"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"versions.json"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./sharp.node": "./lib/sharp-wasm32.node.js",
|
||||||
|
"./package": "./package.json",
|
||||||
|
"./versions": "./versions.json"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@emnapi/runtime": "^1.4.0"
|
||||||
|
},
|
||||||
|
"cpu": [
|
||||||
|
"wasm32"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-win32-ia32",
|
"name": "@img/sharp-win32-ia32",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.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>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -15,8 +16,7 @@
|
|||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
"versions.json",
|
"versions.json"
|
||||||
"THIRD-PARTY-NOTICES.md"
|
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
@@ -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,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@sharpen/sharp-win32-x64",
|
"name": "@img/sharp-win32-x64",
|
||||||
"version": "0.0.1-alpha.6",
|
"version": "0.34.1",
|
||||||
"description": "Prebuilt sharp for use with Windows x64",
|
"description": "Prebuilt sharp for use with Windows x64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://sharp.pixelplumbing.com",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -15,8 +16,7 @@
|
|||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
"versions.json",
|
"versions.json"
|
||||||
"THIRD-PARTY-NOTICES.md"
|
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
@@ -24,13 +24,11 @@
|
|||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./sharp.node": "./lib/sharp-win32-x64.node",
|
"./sharp.node": "./lib/sharp-win32-x64.node",
|
||||||
"./package": "./package.json"
|
"./package": "./package.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"
|
||||||
|
|||||||
94
package.json
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
||||||
"version": "0.33.0-alpha.6",
|
"version": "0.34.1",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Pierre Inglebert <pierre.inglebert@gmail.com>",
|
"Pierre Inglebert <pierre.inglebert@gmail.com>",
|
||||||
"Jonathan Ong <jonathanrichardong@gmail.com>",
|
"Jonathan Ong <jonathanrichardong@gmail.com>",
|
||||||
@@ -82,11 +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>",
|
||||||
|
"Ingvar Stepanyan <me@rreverser.com>",
|
||||||
|
"Don Denton <don@happycollision.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node install/check",
|
"install": "node install/check",
|
||||||
@@ -99,9 +102,9 @@
|
|||||||
"test-types": "tsd",
|
"test-types": "tsd",
|
||||||
"package-from-local-build": "node npm/from-local-build",
|
"package-from-local-build": "node npm/from-local-build",
|
||||||
"package-from-github-release": "node npm/from-github-release",
|
"package-from-github-release": "node npm/from-github-release",
|
||||||
"docs-build": "node docs/build && node docs/search-index/build",
|
"docs-build": "node docs/build.mjs",
|
||||||
"docs-serve": "cd docs && npx serve",
|
"docs-serve": "cd docs && npm start",
|
||||||
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
"docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
||||||
},
|
},
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
@@ -135,51 +138,59 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"detect-libc": "^2.0.2",
|
"detect-libc": "^2.0.3",
|
||||||
"semver": "^7.5.4"
|
"semver": "^7.7.1"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@sharpen/sharp-darwin-arm64": "0.0.1-alpha.6",
|
"@img/sharp-darwin-arm64": "0.34.1",
|
||||||
"@sharpen/sharp-darwin-x64": "0.0.1-alpha.6",
|
"@img/sharp-darwin-x64": "0.34.1",
|
||||||
"@sharpen/sharp-libvips-darwin-arm64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-darwin-arm64": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-darwin-x64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-darwin-x64": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-linux-arm": "0.0.1-alpha.2",
|
"@img/sharp-libvips-linux-arm": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-linux-arm64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-linux-arm64": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-linux-x64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-linux-ppc64": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-linuxmusl-arm64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-linux-s390x": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-linuxmusl-x64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-linux-x64": "1.1.0",
|
||||||
"@sharpen/sharp-linux-arm": "0.0.1-alpha.6",
|
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0",
|
||||||
"@sharpen/sharp-linux-arm64": "0.0.1-alpha.6",
|
"@img/sharp-libvips-linuxmusl-x64": "1.1.0",
|
||||||
"@sharpen/sharp-linux-x64": "0.0.1-alpha.6",
|
"@img/sharp-linux-arm": "0.34.1",
|
||||||
"@sharpen/sharp-linuxmusl-arm64": "0.0.1-alpha.6",
|
"@img/sharp-linux-arm64": "0.34.1",
|
||||||
"@sharpen/sharp-linuxmusl-x64": "0.0.1-alpha.6",
|
"@img/sharp-linux-s390x": "0.34.1",
|
||||||
"@sharpen/sharp-win32-ia32": "0.0.1-alpha.6",
|
"@img/sharp-linux-x64": "0.34.1",
|
||||||
"@sharpen/sharp-win32-x64": "0.0.1-alpha.6"
|
"@img/sharp-linuxmusl-arm64": "0.34.1",
|
||||||
|
"@img/sharp-linuxmusl-x64": "0.34.1",
|
||||||
|
"@img/sharp-wasm32": "0.34.1",
|
||||||
|
"@img/sharp-win32-ia32": "0.34.1",
|
||||||
|
"@img/sharp-win32-x64": "0.34.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sharpen/sharp-libvips-dev": "0.0.1-alpha.2",
|
"@emnapi/runtime": "^1.4.0",
|
||||||
"@sharpen/sharp-libvips-win32-ia32": "0.0.1-alpha.2",
|
"@img/sharp-libvips-dev": "1.1.0",
|
||||||
"@sharpen/sharp-libvips-win32-x64": "0.0.1-alpha.2",
|
"@img/sharp-libvips-dev-wasm32": "1.1.0",
|
||||||
|
"@img/sharp-libvips-win32-ia32": "1.1.0",
|
||||||
|
"@img/sharp-libvips-win32-x64": "1.1.0",
|
||||||
"@types/node": "*",
|
"@types/node": "*",
|
||||||
"async": "^3.2.4",
|
|
||||||
"cc": "^3.0.1",
|
"cc": "^3.0.1",
|
||||||
"exif-reader": "^2.0.0",
|
"emnapi": "^1.4.0",
|
||||||
|
"exif-reader": "^2.0.2",
|
||||||
"extract-zip": "^2.0.1",
|
"extract-zip": "^2.0.1",
|
||||||
"icc": "^3.0.0",
|
"icc": "^3.0.0",
|
||||||
"jsdoc-to-markdown": "^8.0.0",
|
"jsdoc-to-markdown": "^9.1.1",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^11.1.0",
|
||||||
"node-addon-api": "^7.0.0",
|
"node-addon-api": "^8.3.1",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^17.1.0",
|
||||||
"prebuild": "^12.1.0",
|
"prebuild": "^13.0.1",
|
||||||
"semistandard": "^17.0.0",
|
"semistandard": "^17.0.0",
|
||||||
"tar-fs": "^3.0.4",
|
"tar-fs": "^3.0.8",
|
||||||
"tsd": "^0.29.0"
|
"tsd": "^0.31.2"
|
||||||
},
|
},
|
||||||
"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.14.5"
|
},
|
||||||
|
"config": {
|
||||||
|
"libvips": ">=8.16.1"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
@@ -200,6 +211,11 @@
|
|||||||
"build/include"
|
"build/include"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"nyc": {
|
||||||
|
"include": [
|
||||||
|
"lib"
|
||||||
|
]
|
||||||
|
},
|
||||||
"tsd": {
|
"tsd": {
|
||||||
"directory": "test/types/"
|
"directory": "test/types/"
|
||||||
}
|
}
|
||||||
|
|||||||
100
src/binding.gyp
@@ -5,19 +5,24 @@
|
|||||||
'variables': {
|
'variables': {
|
||||||
'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
|
'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
|
||||||
'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
|
'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
|
||||||
|
'sharp_libvips_version': '<!(node -p "require(\'../package.json\').optionalDependencies[\'@img/sharp-libvips-<(platform_and_arch)\']")',
|
||||||
|
'sharp_libvips_yarn_locator': '<!(node -p "require(\'../lib/libvips\').yarnLocator()")',
|
||||||
'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
|
'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
|
||||||
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
|
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
|
||||||
'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
|
'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
|
||||||
},
|
},
|
||||||
'targets': [{
|
'targets': [{
|
||||||
'target_name': 'libvips-cpp',
|
'target_name': 'libvips-cpp-<(vips_version)',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
||||||
'type': 'shared_library',
|
'type': 'shared_library',
|
||||||
'defines': [
|
'defines': [
|
||||||
'VIPS_CPLUSPLUS_EXPORTS',
|
'_VIPS_PUBLIC=__declspec(dllexport)',
|
||||||
'_ALLOW_KEYWORD_MACROS'
|
'_ALLOW_KEYWORD_MACROS',
|
||||||
|
'G_DISABLE_ASSERT',
|
||||||
|
'G_DISABLE_CAST_CHECKS',
|
||||||
|
'G_DISABLE_CHECKS'
|
||||||
],
|
],
|
||||||
'sources': [
|
'sources': [
|
||||||
'<(sharp_libvips_cplusplus_dir)/VConnection.cpp',
|
'<(sharp_libvips_cplusplus_dir)/VConnection.cpp',
|
||||||
@@ -32,17 +37,20 @@
|
|||||||
'<(sharp_libvips_lib_dir)/glib-2.0/include'
|
'<(sharp_libvips_lib_dir)/glib-2.0/include'
|
||||||
],
|
],
|
||||||
'link_settings': {
|
'link_settings': {
|
||||||
'library_dirs': ['<(sharp_libvips_lib_dir)'],
|
'library_dirs': [
|
||||||
|
'<(sharp_libvips_lib_dir)'
|
||||||
|
],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'libvips.lib',
|
'libvips.lib'
|
||||||
'libglib-2.0.lib',
|
|
||||||
'libgobject-2.0.lib'
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'configurations': {
|
'configurations': {
|
||||||
'Release': {
|
'Release': {
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
|
"AdditionalOptions": [
|
||||||
|
"/std:c++17"
|
||||||
|
],
|
||||||
'ExceptionHandling': 1,
|
'ExceptionHandling': 1,
|
||||||
'Optimization': 1,
|
'Optimization': 1,
|
||||||
'WholeProgramOptimization': 'true'
|
'WholeProgramOptimization': 'true'
|
||||||
@@ -75,13 +83,16 @@
|
|||||||
}, {
|
}, {
|
||||||
'target_name': 'sharp-<(platform_and_arch)',
|
'target_name': 'sharp-<(platform_and_arch)',
|
||||||
'defines': [
|
'defines': [
|
||||||
|
'G_DISABLE_ASSERT',
|
||||||
|
'G_DISABLE_CAST_CHECKS',
|
||||||
|
'G_DISABLE_CHECKS',
|
||||||
'NAPI_VERSION=9',
|
'NAPI_VERSION=9',
|
||||||
'NODE_ADDON_API_DISABLE_DEPRECATED',
|
'NODE_ADDON_API_DISABLE_DEPRECATED',
|
||||||
'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'
|
'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'<!(node -p "require(\'node-addon-api\').gyp")',
|
'<!(node -p "require(\'node-addon-api\').gyp")',
|
||||||
'libvips-cpp'
|
'libvips-cpp-<(vips_version)'
|
||||||
],
|
],
|
||||||
'variables': {
|
'variables': {
|
||||||
'conditions': [
|
'conditions': [
|
||||||
@@ -111,6 +122,9 @@
|
|||||||
# Use pkg-config for include and lib
|
# Use pkg-config for include and lib
|
||||||
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
|
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
|
||||||
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
|
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
|
||||||
|
'defines': [
|
||||||
|
'SHARP_USE_GLOBAL_LIBVIPS'
|
||||||
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "linux"', {
|
['OS == "linux"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
@@ -126,6 +140,9 @@
|
|||||||
'<(sharp_libvips_include_dir)/glib-2.0',
|
'<(sharp_libvips_include_dir)/glib-2.0',
|
||||||
'<(sharp_libvips_lib_dir)/glib-2.0/include'
|
'<(sharp_libvips_lib_dir)/glib-2.0/include'
|
||||||
],
|
],
|
||||||
|
'library_dirs': [
|
||||||
|
'<(sharp_libvips_lib_dir)'
|
||||||
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
@@ -133,28 +150,25 @@
|
|||||||
'_FILE_OFFSET_BITS=64'
|
'_FILE_OFFSET_BITS=64'
|
||||||
],
|
],
|
||||||
'link_settings': {
|
'link_settings': {
|
||||||
'library_dirs': ['<(sharp_libvips_lib_dir)'],
|
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'libvips.lib',
|
'libvips.lib'
|
||||||
'libglib-2.0.lib',
|
|
||||||
'libgobject-2.0.lib'
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
['OS == "mac"', {
|
['OS == "mac"', {
|
||||||
'link_settings': {
|
'link_settings': {
|
||||||
'library_dirs': [
|
|
||||||
'<(sharp_libvips_lib_dir)'
|
|
||||||
],
|
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'libvips-cpp.42.dylib'
|
'libvips-cpp.<(vips_version).dylib'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'OTHER_LDFLAGS': [
|
'OTHER_LDFLAGS': [
|
||||||
# Ensure runtime linking is relative to sharp.node
|
# Ensure runtime linking is relative to sharp.node
|
||||||
'-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
'-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
||||||
'-Wl,-rpath,\'@loader_path/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
|
'-Wl,-rpath,\'@loader_path/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
|
||||||
|
'-Wl,-rpath,\'@loader_path/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
|
||||||
|
'-Wl,-rpath,\'@loader_path/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
|
||||||
|
'-Wl,-rpath,\'@loader_path/../../../../../@img-sharp-libvips-<(platform_and_arch)-npm-<(sharp_libvips_version)-<(sharp_libvips_yarn_locator)/node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
@@ -163,33 +177,55 @@
|
|||||||
'_GLIBCXX_USE_CXX11_ABI=1'
|
'_GLIBCXX_USE_CXX11_ABI=1'
|
||||||
],
|
],
|
||||||
'link_settings': {
|
'link_settings': {
|
||||||
'library_dirs': [
|
|
||||||
'<(sharp_libvips_lib_dir)'
|
|
||||||
],
|
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'-l:libvips-cpp.so.42'
|
'-l:libvips-cpp.so.<(vips_version)'
|
||||||
],
|
],
|
||||||
'ldflags': [
|
'ldflags': [
|
||||||
# Ensure runtime linking is relative to sharp.node
|
'-lstdc++fs',
|
||||||
'-Wl,-s',
|
'-Wl,-s',
|
||||||
'-Wl,--disable-new-dtags',
|
'-Wl,--disable-new-dtags',
|
||||||
|
'-Wl,-z,nodelete',
|
||||||
|
'-Wl,-Bsymbolic-functions',
|
||||||
'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
|
||||||
'-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
|
'-Wl,-rpath=\'$$ORIGIN/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
|
||||||
|
'-Wl,-rpath=\'$$ORIGIN/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
|
||||||
|
'-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
|
||||||
|
'-Wl,-rpath,\'$$ORIGIN/../../../../../@img-sharp-libvips-<(platform_and_arch)-npm-<(sharp_libvips_version)-<(sharp_libvips_yarn_locator)/node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}],
|
||||||
|
['OS == "emscripten"', {
|
||||||
|
'product_extension': 'node.js',
|
||||||
|
'link_settings': {
|
||||||
|
'ldflags': [
|
||||||
|
'-fexceptions',
|
||||||
|
'--pre-js=<!(node -p "require.resolve(\'./emscripten/pre.js\')")',
|
||||||
|
'-Oz',
|
||||||
|
'-sALLOW_MEMORY_GROWTH',
|
||||||
|
'-sENVIRONMENT=node',
|
||||||
|
'-sEXPORTED_FUNCTIONS=["emnapiInit", "_vips_shutdown", "_uv_library_shutdown"]',
|
||||||
|
'-sNODERAWFS',
|
||||||
|
'-sTEXTDECODER=0',
|
||||||
|
'-sWASM_ASYNC_COMPILATION=0',
|
||||||
|
'-sWASM_BIGINT'
|
||||||
|
],
|
||||||
|
'libraries': [
|
||||||
|
'<!@(PKG_CONFIG_PATH="<!(node -p "require(\'@img/sharp-libvips-dev-wasm32/lib\')")/pkgconfig" pkg-config --static --libs vips-cpp)'
|
||||||
|
],
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
'cflags_cc': [
|
'cflags_cc': [
|
||||||
'-std=c++0x',
|
'-std=c++17',
|
||||||
'-fexceptions',
|
'-fexceptions',
|
||||||
'-Wall',
|
'-Wall',
|
||||||
'-Os'
|
'-Os'
|
||||||
],
|
],
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
|
||||||
'MACOSX_DEPLOYMENT_TARGET': '10.13',
|
'MACOSX_DEPLOYMENT_TARGET': '10.15',
|
||||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
||||||
'GCC_ENABLE_CPP_RTTI': 'YES',
|
'GCC_ENABLE_CPP_RTTI': 'YES',
|
||||||
'OTHER_CPLUSPLUSFLAGS': [
|
'OTHER_CPLUSPLUSFLAGS': [
|
||||||
@@ -201,11 +237,6 @@
|
|||||||
'configurations': {
|
'configurations': {
|
||||||
'Release': {
|
'Release': {
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "linux"', {
|
|
||||||
'cflags_cc': [
|
|
||||||
'-Wno-cast-function-type'
|
|
||||||
]
|
|
||||||
}],
|
|
||||||
['target_arch == "arm"', {
|
['target_arch == "arm"', {
|
||||||
'cflags_cc': [
|
'cflags_cc': [
|
||||||
'-Wno-psabi'
|
'-Wno-psabi'
|
||||||
@@ -214,6 +245,9 @@
|
|||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
|
"AdditionalOptions": [
|
||||||
|
"/std:c++17"
|
||||||
|
],
|
||||||
'ExceptionHandling': 1,
|
'ExceptionHandling': 1,
|
||||||
'Optimization': 1,
|
'Optimization': 1,
|
||||||
'WholeProgramOptimization': 'true'
|
'WholeProgramOptimization': 'true'
|
||||||
@@ -251,9 +285,7 @@
|
|||||||
'copies': [{
|
'copies': [{
|
||||||
'destination': 'build/Release',
|
'destination': 'build/Release',
|
||||||
'files': [
|
'files': [
|
||||||
'<(sharp_libvips_lib_dir)/libvips-42.dll',
|
'<(sharp_libvips_lib_dir)/libvips-42.dll'
|
||||||
'<(sharp_libvips_lib_dir)/libglib-2.0-0.dll',
|
|
||||||
'<(sharp_libvips_lib_dir)/libgobject-2.0-0.dll'
|
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
|
|||||||
115
src/common.cc
@@ -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
|
||||||
@@ -109,6 +109,10 @@ namespace sharp {
|
|||||||
if (HasAttr(input, "subifd")) {
|
if (HasAttr(input, "subifd")) {
|
||||||
descriptor->subifd = AttrAsInt32(input, "subifd");
|
descriptor->subifd = AttrAsInt32(input, "subifd");
|
||||||
}
|
}
|
||||||
|
// // PDF background color
|
||||||
|
if (HasAttr(input, "pdfBackground")) {
|
||||||
|
descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (HasAttr(input, "createChannels")) {
|
if (HasAttr(input, "createChannels")) {
|
||||||
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
||||||
@@ -156,12 +160,34 @@ namespace sharp {
|
|||||||
descriptor->textWrap = AttrAsEnum<VipsTextWrap>(input, "textWrap", VIPS_TYPE_TEXT_WRAP);
|
descriptor->textWrap = AttrAsEnum<VipsTextWrap>(input, "textWrap", VIPS_TYPE_TEXT_WRAP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Join images together
|
||||||
|
if (HasAttr(input, "joinAnimated")) {
|
||||||
|
descriptor->joinAnimated = AttrAsBool(input, "joinAnimated");
|
||||||
|
}
|
||||||
|
if (HasAttr(input, "joinAcross")) {
|
||||||
|
descriptor->joinAcross = AttrAsUint32(input, "joinAcross");
|
||||||
|
}
|
||||||
|
if (HasAttr(input, "joinShim")) {
|
||||||
|
descriptor->joinShim = AttrAsUint32(input, "joinShim");
|
||||||
|
}
|
||||||
|
if (HasAttr(input, "joinBackground")) {
|
||||||
|
descriptor->joinBackground = AttrAsVectorOfDouble(input, "joinBackground");
|
||||||
|
}
|
||||||
|
if (HasAttr(input, "joinHalign")) {
|
||||||
|
descriptor->joinHalign = AttrAsEnum<VipsAlign>(input, "joinHalign", VIPS_TYPE_ALIGN);
|
||||||
|
}
|
||||||
|
if (HasAttr(input, "joinValign")) {
|
||||||
|
descriptor->joinValign = AttrAsEnum<VipsAlign>(input, "joinValign", VIPS_TYPE_ALIGN);
|
||||||
|
}
|
||||||
// Limit input images to a given number of pixels, where pixels = width * height
|
// Limit input images to a given number of pixels, where pixels = width * height
|
||||||
descriptor->limitInputPixels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputPixels"));
|
descriptor->limitInputPixels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputPixels"));
|
||||||
// Allow switch from random to sequential access
|
if (HasAttr(input, "access")) {
|
||||||
descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||||
|
}
|
||||||
// Remove safety features and allow unlimited input
|
// Remove safety features and allow unlimited input
|
||||||
descriptor->unlimited = AttrAsBool(input, "unlimited");
|
descriptor->unlimited = AttrAsBool(input, "unlimited");
|
||||||
|
// Use the EXIF orientation to auto orient the image
|
||||||
|
descriptor->autoOrient = AttrAsBool(input, "autoOrient");
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +270,7 @@ namespace sharp {
|
|||||||
case ImageType::FITS: id = "fits"; break;
|
case ImageType::FITS: id = "fits"; break;
|
||||||
case ImageType::EXR: id = "exr"; break;
|
case ImageType::EXR: id = "exr"; break;
|
||||||
case ImageType::JXL: id = "jxl"; break;
|
case ImageType::JXL: id = "jxl"; break;
|
||||||
|
case ImageType::RAD: id = "rad"; break;
|
||||||
case ImageType::VIPS: id = "vips"; break;
|
case ImageType::VIPS: id = "vips"; break;
|
||||||
case ImageType::RAW: id = "raw"; break;
|
case ImageType::RAW: id = "raw"; break;
|
||||||
case ImageType::UNKNOWN: id = "unknown"; break;
|
case ImageType::UNKNOWN: id = "unknown"; break;
|
||||||
@@ -290,6 +317,8 @@ namespace sharp {
|
|||||||
{ "VipsForeignLoadOpenexr", ImageType::EXR },
|
{ "VipsForeignLoadOpenexr", ImageType::EXR },
|
||||||
{ "VipsForeignLoadJxlFile", ImageType::JXL },
|
{ "VipsForeignLoadJxlFile", ImageType::JXL },
|
||||||
{ "VipsForeignLoadJxlBuffer", ImageType::JXL },
|
{ "VipsForeignLoadJxlBuffer", ImageType::JXL },
|
||||||
|
{ "VipsForeignLoadRadFile", ImageType::RAD },
|
||||||
|
{ "VipsForeignLoadRadBuffer", ImageType::RAD },
|
||||||
{ "VipsForeignLoadVips", ImageType::VIPS },
|
{ "VipsForeignLoadVips", ImageType::VIPS },
|
||||||
{ "VipsForeignLoadVipsFile", ImageType::VIPS },
|
{ "VipsForeignLoadVipsFile", ImageType::VIPS },
|
||||||
{ "VipsForeignLoadRaw", ImageType::RAW }
|
{ "VipsForeignLoadRaw", ImageType::RAW }
|
||||||
@@ -384,7 +413,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);
|
||||||
@@ -402,6 +431,9 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::TIFF) {
|
if (imageType == ImageType::TIFF) {
|
||||||
option->set("subifd", descriptor->subifd);
|
option->set("subifd", descriptor->subifd);
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::PDF) {
|
||||||
|
option->set("background", descriptor->pdfBackground);
|
||||||
|
}
|
||||||
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||||
image = SetDensity(image, descriptor->density);
|
image = SetDensity(image, descriptor->density);
|
||||||
@@ -488,7 +520,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);
|
||||||
@@ -506,6 +538,9 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::TIFF) {
|
if (imageType == ImageType::TIFF) {
|
||||||
option->set("subifd", descriptor->subifd);
|
option->set("subifd", descriptor->subifd);
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::PDF) {
|
||||||
|
option->set("background", descriptor->pdfBackground);
|
||||||
|
}
|
||||||
image = VImage::new_from_file(descriptor->file.data(), option);
|
image = VImage::new_from_file(descriptor->file.data(), option);
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||||
image = SetDensity(image, descriptor->density);
|
image = SetDensity(image, descriptor->density);
|
||||||
@@ -531,15 +566,54 @@ namespace sharp {
|
|||||||
Does this image have an embedded profile?
|
Does this image have an embedded profile?
|
||||||
*/
|
*/
|
||||||
bool HasProfile(VImage image) {
|
bool HasProfile(VImage image) {
|
||||||
return (image.get_typeof(VIPS_META_ICC_NAME) != 0) ? TRUE : FALSE;
|
return image.get_typeof(VIPS_META_ICC_NAME) == VIPS_TYPE_BLOB;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Does this image have an alpha channel?
|
Get copy of embedded profile.
|
||||||
Uses colour space interpretation with number of channels to guess this.
|
|
||||||
*/
|
*/
|
||||||
bool HasAlpha(VImage image) {
|
std::pair<char*, size_t> GetProfile(VImage image) {
|
||||||
return image.has_alpha();
|
std::pair<char*, size_t> icc(nullptr, 0);
|
||||||
|
if (HasProfile(image)) {
|
||||||
|
size_t length;
|
||||||
|
const void *data = image.get_blob(VIPS_META_ICC_NAME, &length);
|
||||||
|
icc.first = static_cast<char*>(g_malloc(length));
|
||||||
|
icc.second = length;
|
||||||
|
memcpy(icc.first, data, length);
|
||||||
|
}
|
||||||
|
return icc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set embedded profile.
|
||||||
|
*/
|
||||||
|
VImage SetProfile(VImage image, std::pair<char*, size_t> icc) {
|
||||||
|
if (icc.first != nullptr) {
|
||||||
|
image = image.copy();
|
||||||
|
image.set(VIPS_META_ICC_NAME, reinterpret_cast<VipsCallbackFn>(vips_area_free_cb), icc.first, icc.second);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void* RemoveExifCallback(VipsImage *image, char const *field, GValue *value, void *data) {
|
||||||
|
std::vector<std::string> *fieldNames = static_cast<std::vector<std::string> *>(data);
|
||||||
|
std::string fieldName(field);
|
||||||
|
if (fieldName.substr(0, 8) == ("exif-ifd")) {
|
||||||
|
fieldNames->push_back(fieldName);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Remove all EXIF-related image fields.
|
||||||
|
*/
|
||||||
|
VImage RemoveExif(VImage image) {
|
||||||
|
std::vector<std::string> fieldNames;
|
||||||
|
vips_image_map(image.get_image(), static_cast<VipsImageMapFn>(RemoveExifCallback), &fieldNames);
|
||||||
|
for (const auto& f : fieldNames) {
|
||||||
|
image.remove(f.data());
|
||||||
|
}
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -721,7 +795,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -731,7 +805,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;
|
||||||
}
|
}
|
||||||
@@ -929,13 +1003,13 @@ namespace sharp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Add alpha channel to alphaColour colour
|
// Add alpha channel to alphaColour colour
|
||||||
if (colour[3] < 255.0 || HasAlpha(image)) {
|
if (colour[3] < 255.0 || image.has_alpha()) {
|
||||||
alphaColour.push_back(colour[3] * multiplier);
|
alphaColour.push_back(colour[3] * multiplier);
|
||||||
}
|
}
|
||||||
// Ensure alphaColour colour uses correct colourspace
|
// Ensure alphaColour colour uses correct colourspace
|
||||||
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
|
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
|
||||||
// Add non-transparent alpha channel, if required
|
// Add non-transparent alpha channel, if required
|
||||||
if (colour[3] < 255.0 && !HasAlpha(image)) {
|
if (colour[3] < 255.0 && !image.has_alpha()) {
|
||||||
image = image.bandjoin(
|
image = image.bandjoin(
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format()));
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format()));
|
||||||
}
|
}
|
||||||
@@ -943,10 +1017,10 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Removes alpha channel, if any.
|
Removes alpha channels, if any.
|
||||||
*/
|
*/
|
||||||
VImage RemoveAlpha(VImage image) {
|
VImage RemoveAlpha(VImage image) {
|
||||||
if (HasAlpha(image)) {
|
while (image.bands() > 1 && image.has_alpha()) {
|
||||||
image = image.extract_band(0, VImage::option()->set("n", image.bands() - 1));
|
image = image.extract_band(0, VImage::option()->set("n", image.bands() - 1));
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
@@ -956,7 +1030,7 @@ namespace sharp {
|
|||||||
Ensures alpha channel, if missing.
|
Ensures alpha channel, if missing.
|
||||||
*/
|
*/
|
||||||
VImage EnsureAlpha(VImage image, double const value) {
|
VImage EnsureAlpha(VImage image, double const value) {
|
||||||
if (!HasAlpha(image)) {
|
if (!image.has_alpha()) {
|
||||||
std::vector<double> alpha;
|
std::vector<double> alpha;
|
||||||
alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));
|
alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));
|
||||||
image = image.bandjoin_const(alpha);
|
image = image.bandjoin_const(alpha);
|
||||||
@@ -1034,9 +1108,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;
|
||||||
}
|
}
|
||||||
|
|||||||
66
src/common.h
@@ -15,18 +15,14 @@
|
|||||||
// Verify platform and compiler compatibility
|
// Verify platform and compiler compatibility
|
||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION < 8) || \
|
#if (VIPS_MAJOR_VERSION < 8) || \
|
||||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 14) || \
|
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 16) || \
|
||||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 14 && VIPS_MICRO_VERSION < 5)
|
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 16 && VIPS_MICRO_VERSION < 1)
|
||||||
#error "libvips version 8.14.5+ is required - please see https://sharp.pixelplumbing.com/install"
|
#error "libvips version 8.16.1+ 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(__has_include)
|
||||||
#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
|
#if !__has_include(<filesystem>)
|
||||||
#endif
|
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
|
||||||
|
|
||||||
#if (defined(__clang__) && defined(__has_feature))
|
|
||||||
#if (!__has_feature(cxx_range_for))
|
|
||||||
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -37,6 +33,7 @@ namespace sharp {
|
|||||||
struct InputDescriptor { // NOLINT(runtime/indentation_namespace)
|
struct InputDescriptor { // NOLINT(runtime/indentation_namespace)
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string file;
|
std::string file;
|
||||||
|
bool autoOrient;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
VipsFailOn failOn;
|
VipsFailOn failOn;
|
||||||
uint64_t limitInputPixels;
|
uint64_t limitInputPixels;
|
||||||
@@ -74,17 +71,25 @@ namespace sharp {
|
|||||||
int textSpacing;
|
int textSpacing;
|
||||||
VipsTextWrap textWrap;
|
VipsTextWrap textWrap;
|
||||||
int textAutofitDpi;
|
int textAutofitDpi;
|
||||||
|
bool joinAnimated;
|
||||||
|
int joinAcross;
|
||||||
|
int joinShim;
|
||||||
|
std::vector<double> joinBackground;
|
||||||
|
VipsAlign joinHalign;
|
||||||
|
VipsAlign joinValign;
|
||||||
|
std::vector<double> pdfBackground;
|
||||||
|
|
||||||
InputDescriptor():
|
InputDescriptor():
|
||||||
|
autoOrient(false),
|
||||||
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_SEQUENTIAL),
|
||||||
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,12 +108,19 @@ 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),
|
||||||
|
joinAnimated(false),
|
||||||
|
joinAcross(1),
|
||||||
|
joinShim(0),
|
||||||
|
joinBackground{ 0.0, 0.0, 0.0, 255.0 },
|
||||||
|
joinHalign(VIPS_ALIGN_LOW),
|
||||||
|
joinValign(VIPS_ALIGN_LOW),
|
||||||
|
pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convenience methods to access the attributes of a Napi::Object
|
// Convenience methods to access the attributes of a Napi::Object
|
||||||
@@ -147,6 +159,7 @@ namespace sharp {
|
|||||||
FITS,
|
FITS,
|
||||||
EXR,
|
EXR,
|
||||||
JXL,
|
JXL,
|
||||||
|
RAD,
|
||||||
VIPS,
|
VIPS,
|
||||||
RAW,
|
RAW,
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
@@ -223,10 +236,19 @@ namespace sharp {
|
|||||||
bool HasProfile(VImage image);
|
bool HasProfile(VImage image);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Does this image have an alpha channel?
|
Get copy of embedded profile.
|
||||||
Uses colour space interpretation with number of channels to guess this.
|
|
||||||
*/
|
*/
|
||||||
bool HasAlpha(VImage image);
|
std::pair<char*, size_t> GetProfile(VImage image);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set embedded profile.
|
||||||
|
*/
|
||||||
|
VImage SetProfile(VImage image, std::pair<char*, size_t> icc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Remove all EXIF-related image fields.
|
||||||
|
*/
|
||||||
|
VImage RemoveExif(VImage image);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get EXIF Orientation of image, if any.
|
Get EXIF Orientation of image, if any.
|
||||||
@@ -353,7 +375,7 @@ namespace sharp {
|
|||||||
std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour, bool premultiply);
|
std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour, bool premultiply);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Removes alpha channel, if any.
|
Removes alpha channels, if any.
|
||||||
*/
|
*/
|
||||||
VImage RemoveAlpha(VImage image);
|
VImage RemoveAlpha(VImage image);
|
||||||
|
|
||||||
@@ -371,7 +393,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
|
||||||
|
|
||||||
|
|||||||
40
src/emscripten/common.gypi
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Copyright 2013 Lovell Fuller and others.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
{
|
||||||
|
'variables': {
|
||||||
|
'OS': 'emscripten'
|
||||||
|
},
|
||||||
|
'target_defaults': {
|
||||||
|
'default_configuration': 'Release',
|
||||||
|
'type': 'executable',
|
||||||
|
'cflags': [
|
||||||
|
'-pthread'
|
||||||
|
],
|
||||||
|
'cflags_cc': [
|
||||||
|
'-pthread'
|
||||||
|
],
|
||||||
|
'ldflags': [
|
||||||
|
'--js-library=<!(node -p "require(\'emnapi\').js_library")',
|
||||||
|
'-sAUTO_JS_LIBRARIES=0',
|
||||||
|
'-sAUTO_NATIVE_LIBRARIES=0',
|
||||||
|
'-sDEFAULT_TO_CXX=0',
|
||||||
|
'-sNODEJS_CATCH_EXIT=0',
|
||||||
|
'-sNODEJS_CATCH_REJECTION=0'
|
||||||
|
],
|
||||||
|
'defines': [
|
||||||
|
'__STDC_FORMAT_MACROS',
|
||||||
|
'BUILDING_NODE_EXTENSION',
|
||||||
|
'EMNAPI_WORKER_POOL_SIZE=1'
|
||||||
|
],
|
||||||
|
'include_dirs': [
|
||||||
|
'<!(node -p "require(\'emnapi\').include_dir")'
|
||||||
|
],
|
||||||
|
'sources': [
|
||||||
|
'<!@(node -p "require(\'emnapi\').sources.map(x => JSON.stringify(path.relative(process.cwd(), x))).join(\' \')")'
|
||||||
|
],
|
||||||
|
'configurations': {
|
||||||
|
'Release': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/emscripten/pre.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2013 Lovell Fuller and others.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/* global Module, ENV, _vips_shutdown, _uv_library_shutdown */
|
||||||
|
|
||||||
|
Module.preRun = () => {
|
||||||
|
ENV.VIPS_CONCURRENCY = Number(process.env.VIPS_CONCURRENCY) || 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
Module.onRuntimeInitialized = () => {
|
||||||
|
module.exports = Module.emnapiInit({
|
||||||
|
context: require('@emnapi/runtime').getDefaultContext()
|
||||||
|
});
|
||||||
|
|
||||||
|
process.once('exit', () => {
|
||||||
|
_vips_shutdown();
|
||||||
|
_uv_library_shutdown();
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
@@ -10,6 +11,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) :
|
||||||
@@ -45,8 +48,11 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
||||||
baton->isProgressive = image.get_int("interlaced") == 1;
|
baton->isProgressive = image.get_int("interlaced") == 1;
|
||||||
}
|
}
|
||||||
if (image.get_typeof("palette-bit-depth") == G_TYPE_INT) {
|
if (image.get_typeof(VIPS_META_PALETTE) == G_TYPE_INT) {
|
||||||
baton->paletteBitDepth = image.get_int("palette-bit-depth");
|
baton->isPalette = image.get_int(VIPS_META_PALETTE);
|
||||||
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT) {
|
||||||
|
baton->bitsPerSample = image.get_int(VIPS_META_BITS_PER_SAMPLE);
|
||||||
}
|
}
|
||||||
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
||||||
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
||||||
@@ -89,7 +95,7 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
baton->background = image.get_array_double("background");
|
baton->background = image.get_array_double("background");
|
||||||
}
|
}
|
||||||
// Derived attributes
|
// Derived attributes
|
||||||
baton->hasAlpha = sharp::HasAlpha(image);
|
baton->hasAlpha = image.has_alpha();
|
||||||
baton->orientation = sharp::ExifOrientation(image);
|
baton->orientation = sharp::ExifOrientation(image);
|
||||||
// EXIF
|
// EXIF
|
||||||
if (image.get_typeof(VIPS_META_EXIF_NAME) == VIPS_TYPE_BLOB) {
|
if (image.get_typeof(VIPS_META_EXIF_NAME) == VIPS_TYPE_BLOB) {
|
||||||
@@ -131,6 +137,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
|
||||||
@@ -145,7 +153,7 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
// Handle warnings
|
// Handle warnings
|
||||||
std::string warning = sharp::VipsWarningPop();
|
std::string warning = sharp::VipsWarningPop();
|
||||||
while (!warning.empty()) {
|
while (!warning.empty()) {
|
||||||
debuglog.MakeCallback(Receiver().Value(), { Napi::String::New(env, warning) });
|
debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +175,13 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("chromaSubsampling", baton->chromaSubsampling);
|
info.Set("chromaSubsampling", baton->chromaSubsampling);
|
||||||
}
|
}
|
||||||
info.Set("isProgressive", baton->isProgressive);
|
info.Set("isProgressive", baton->isProgressive);
|
||||||
if (baton->paletteBitDepth > 0) {
|
info.Set("isPalette", baton->isPalette);
|
||||||
info.Set("paletteBitDepth", baton->paletteBitDepth);
|
if (baton->bitsPerSample > 0) {
|
||||||
|
info.Set("bitsPerSample", baton->bitsPerSample);
|
||||||
|
if (baton->isPalette) {
|
||||||
|
// Deprecated, remove with libvips 8.17.0
|
||||||
|
info.Set("paletteBitDepth", baton->bitsPerSample);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (baton->pages > 0) {
|
if (baton->pages > 0) {
|
||||||
info.Set("pages", baton->pages);
|
info.Set("pages", baton->pages);
|
||||||
@@ -214,21 +227,30 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("subifds", baton->subifds);
|
info.Set("subifds", baton->subifds);
|
||||||
}
|
}
|
||||||
if (!baton->background.empty()) {
|
if (!baton->background.empty()) {
|
||||||
|
Napi::Object background = Napi::Object::New(env);
|
||||||
if (baton->background.size() == 3) {
|
if (baton->background.size() == 3) {
|
||||||
Napi::Object background = Napi::Object::New(env);
|
|
||||||
background.Set("r", baton->background[0]);
|
background.Set("r", baton->background[0]);
|
||||||
background.Set("g", baton->background[1]);
|
background.Set("g", baton->background[1]);
|
||||||
background.Set("b", baton->background[2]);
|
background.Set("b", baton->background[2]);
|
||||||
info.Set("background", background);
|
|
||||||
} else {
|
} else {
|
||||||
info.Set("background", baton->background[0]);
|
background.Set("gray", round(baton->background[0] * 100 / 255));
|
||||||
}
|
}
|
||||||
|
info.Set("background", background);
|
||||||
}
|
}
|
||||||
info.Set("hasProfile", baton->hasProfile);
|
info.Set("hasProfile", baton->hasProfile);
|
||||||
info.Set("hasAlpha", baton->hasAlpha);
|
info.Set("hasAlpha", baton->hasAlpha);
|
||||||
if (baton->orientation > 0) {
|
if (baton->orientation > 0) {
|
||||||
info.Set("orientation", baton->orientation);
|
info.Set("orientation", baton->orientation);
|
||||||
}
|
}
|
||||||
|
Napi::Object autoOrient = Napi::Object::New(env);
|
||||||
|
info.Set("autoOrient", autoOrient);
|
||||||
|
if (baton->orientation >= 5) {
|
||||||
|
autoOrient.Set("width", baton->height);
|
||||||
|
autoOrient.Set("height", baton->width);
|
||||||
|
} else {
|
||||||
|
autoOrient.Set("width", baton->width);
|
||||||
|
autoOrient.Set("height", baton->height);
|
||||||
|
}
|
||||||
if (baton->exifLength > 0) {
|
if (baton->exifLength > 0) {
|
||||||
info.Set("exif", Napi::Buffer<char>::NewOrCopy(env, baton->exif, baton->exifLength, sharp::FreeCallback));
|
info.Set("exif", Napi::Buffer<char>::NewOrCopy(env, baton->exif, baton->exifLength, sharp::FreeCallback));
|
||||||
}
|
}
|
||||||
@@ -246,9 +268,20 @@ 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));
|
||||||
}
|
}
|
||||||
Callback().MakeCallback(Receiver().Value(), { env.Null(), info });
|
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 });
|
||||||
} else {
|
} else {
|
||||||
Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
||||||
}
|
}
|
||||||
|
|
||||||
delete baton->input;
|
delete baton->input;
|
||||||
@@ -285,3 +318,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;
|
||||||
@@ -22,7 +24,8 @@ struct MetadataBaton {
|
|||||||
int density;
|
int density;
|
||||||
std::string chromaSubsampling;
|
std::string chromaSubsampling;
|
||||||
bool isProgressive;
|
bool isProgressive;
|
||||||
int paletteBitDepth;
|
bool isPalette;
|
||||||
|
int bitsPerSample;
|
||||||
int pages;
|
int pages;
|
||||||
int pageHeight;
|
int pageHeight;
|
||||||
int loop;
|
int loop;
|
||||||
@@ -47,6 +50,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():
|
||||||
@@ -56,7 +60,8 @@ struct MetadataBaton {
|
|||||||
channels(0),
|
channels(0),
|
||||||
density(0),
|
density(0),
|
||||||
isProgressive(false),
|
isProgressive(false),
|
||||||
paletteBitDepth(0),
|
isPalette(false),
|
||||||
|
bitsPerSample(0),
|
||||||
pages(0),
|
pages(0),
|
||||||
pageHeight(0),
|
pageHeight(0),
|
||||||
loop(-1),
|
loop(-1),
|
||||||
|
|||||||
@@ -16,30 +16,44 @@ using vips::VError;
|
|||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
/*
|
/*
|
||||||
* Tint an image using the specified chroma, preserving the original image luminance
|
* Tint an image using the provided RGB.
|
||||||
*/
|
*/
|
||||||
VImage Tint(VImage image, double const a, double const b) {
|
VImage Tint(VImage image, std::vector<double> const tint) {
|
||||||
// Get original colourspace
|
std::vector<double> const tintLab = (VImage::black(1, 1) + tint)
|
||||||
|
.colourspace(VIPS_INTERPRETATION_LAB, VImage::option()->set("source_space", VIPS_INTERPRETATION_sRGB))
|
||||||
|
.getpoint(0, 0);
|
||||||
|
// LAB identity function
|
||||||
|
VImage identityLab = VImage::identity(VImage::option()->set("bands", 3))
|
||||||
|
.colourspace(VIPS_INTERPRETATION_LAB, VImage::option()->set("source_space", VIPS_INTERPRETATION_sRGB));
|
||||||
|
// Scale luminance range, 0.0 to 1.0
|
||||||
|
VImage l = identityLab[0] / 100;
|
||||||
|
// Weighting functions
|
||||||
|
VImage weightL = 1.0 - 4.0 * ((l - 0.5) * (l - 0.5));
|
||||||
|
VImage weightAB = (weightL * tintLab).extract_band(1, VImage::option()->set("n", 2));
|
||||||
|
identityLab = identityLab[0].bandjoin(weightAB);
|
||||||
|
// Convert lookup table to sRGB
|
||||||
|
VImage lut = identityLab.colourspace(VIPS_INTERPRETATION_sRGB,
|
||||||
|
VImage::option()->set("source_space", VIPS_INTERPRETATION_LAB));
|
||||||
|
// Original colourspace
|
||||||
VipsInterpretation typeBeforeTint = image.interpretation();
|
VipsInterpretation typeBeforeTint = image.interpretation();
|
||||||
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
|
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
|
||||||
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
|
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
|
||||||
}
|
}
|
||||||
// Extract luminance
|
// Apply lookup table
|
||||||
VImage luminance = image.colourspace(VIPS_INTERPRETATION_LAB)[0];
|
if (image.has_alpha()) {
|
||||||
// Create the tinted version by combining the L from the original and the chroma from the tint
|
|
||||||
std::vector<double> chroma {a, b};
|
|
||||||
VImage tinted = luminance
|
|
||||||
.bandjoin(chroma)
|
|
||||||
.copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_LAB))
|
|
||||||
.colourspace(typeBeforeTint);
|
|
||||||
// Attach original alpha channel, if any
|
|
||||||
if (HasAlpha(image)) {
|
|
||||||
// Extract original alpha channel
|
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
// Join alpha channel to normalised image
|
image = RemoveAlpha(image)
|
||||||
tinted = tinted.bandjoin(alpha);
|
.colourspace(VIPS_INTERPRETATION_B_W)
|
||||||
|
.maplut(lut)
|
||||||
|
.colourspace(typeBeforeTint)
|
||||||
|
.bandjoin(alpha);
|
||||||
|
} else {
|
||||||
|
image = image
|
||||||
|
.colourspace(VIPS_INTERPRETATION_B_W)
|
||||||
|
.maplut(lut)
|
||||||
|
.colourspace(typeBeforeTint);
|
||||||
}
|
}
|
||||||
return tinted;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -69,7 +83,7 @@ namespace sharp {
|
|||||||
// Scale luminance, join to chroma, convert back to original colourspace
|
// Scale luminance, join to chroma, convert back to original colourspace
|
||||||
VImage normalized = luminance.linear(f, a).bandjoin(chroma).colourspace(typeBeforeNormalize);
|
VImage normalized = luminance.linear(f, a).bandjoin(chroma).colourspace(typeBeforeNormalize);
|
||||||
// Attach original alpha channel, if any
|
// Attach original alpha channel, if any
|
||||||
if (HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
// Extract original alpha channel
|
// Extract original alpha channel
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
// Join alpha channel to normalised image
|
// Join alpha channel to normalised image
|
||||||
@@ -92,7 +106,7 @@ namespace sharp {
|
|||||||
* Gamma encoding/decoding
|
* Gamma encoding/decoding
|
||||||
*/
|
*/
|
||||||
VImage Gamma(VImage image, double const exponent) {
|
VImage Gamma(VImage image, double const exponent) {
|
||||||
if (HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
// Separate alpha channel
|
// Separate alpha channel
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
return RemoveAlpha(image).gamma(VImage::option()->set("exponent", exponent)).bandjoin(alpha);
|
return RemoveAlpha(image).gamma(VImage::option()->set("exponent", exponent)).bandjoin(alpha);
|
||||||
@@ -118,7 +132,7 @@ namespace sharp {
|
|||||||
* Produce the "negative" of the image.
|
* Produce the "negative" of the image.
|
||||||
*/
|
*/
|
||||||
VImage Negate(VImage image, bool const negateAlpha) {
|
VImage Negate(VImage image, bool const negateAlpha) {
|
||||||
if (HasAlpha(image) && !negateAlpha) {
|
if (image.has_alpha() && !negateAlpha) {
|
||||||
// Separate alpha channel
|
// Separate alpha channel
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
return RemoveAlpha(image).invert().bandjoin(alpha);
|
return RemoveAlpha(image).invert().bandjoin(alpha);
|
||||||
@@ -130,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,
|
||||||
@@ -141,7 +155,9 @@ namespace sharp {
|
|||||||
return image.conv(blur);
|
return image.conv(blur);
|
||||||
} else {
|
} else {
|
||||||
// Slower, accurate Gaussian blur
|
// Slower, accurate Gaussian blur
|
||||||
return image.gaussblur(sigma);
|
return StaySequential(image).gaussblur(sigma, VImage::option()
|
||||||
|
->set("precision", precision)
|
||||||
|
->set("min_ampl", minAmpl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,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,
|
||||||
@@ -169,25 +185,27 @@ 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,
|
||||||
int const hue, double const lightness) {
|
int const hue, double const lightness) {
|
||||||
VipsInterpretation colourspaceBeforeModulate = image.interpretation();
|
VipsInterpretation colourspaceBeforeModulate = image.interpretation();
|
||||||
if (HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
// Separate alpha channel
|
// Separate alpha channel
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
return RemoveAlpha(image)
|
return RemoveAlpha(image)
|
||||||
@@ -265,7 +283,7 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
Trim an image
|
Trim an image
|
||||||
*/
|
*/
|
||||||
VImage Trim(VImage image, std::vector<double> background, double threshold) {
|
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt) {
|
||||||
if (image.width() < 3 && image.height() < 3) {
|
if (image.width() < 3 && image.height() < 3) {
|
||||||
throw VError("Image to trim must be at least 3x3 pixels");
|
throw VError("Image to trim must be at least 3x3 pixels");
|
||||||
}
|
}
|
||||||
@@ -279,7 +297,7 @@ namespace sharp {
|
|||||||
threshold *= 256.0;
|
threshold *= 256.0;
|
||||||
}
|
}
|
||||||
std::vector<double> backgroundAlpha({ background.back() });
|
std::vector<double> backgroundAlpha({ background.back() });
|
||||||
if (HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
background.pop_back();
|
background.pop_back();
|
||||||
} else {
|
} else {
|
||||||
background.resize(image.bands());
|
background.resize(image.bands());
|
||||||
@@ -287,13 +305,15 @@ namespace sharp {
|
|||||||
int left, top, width, height;
|
int left, top, width, height;
|
||||||
left = image.find_trim(&top, &width, &height, VImage::option()
|
left = image.find_trim(&top, &width, &height, VImage::option()
|
||||||
->set("background", background)
|
->set("background", background)
|
||||||
|
->set("line_art", lineArt)
|
||||||
->set("threshold", threshold));
|
->set("threshold", threshold));
|
||||||
if (HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
// Search alpha channel (A)
|
// Search alpha channel (A)
|
||||||
int leftA, topA, widthA, heightA;
|
int leftA, topA, widthA, heightA;
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
leftA = alpha.find_trim(&topA, &widthA, &heightA, VImage::option()
|
leftA = alpha.find_trim(&topA, &widthA, &heightA, VImage::option()
|
||||||
->set("background", backgroundAlpha)
|
->set("background", backgroundAlpha)
|
||||||
|
->set("line_art", lineArt)
|
||||||
->set("threshold", threshold));
|
->set("threshold", threshold));
|
||||||
if (widthA > 0 && heightA > 0) {
|
if (widthA > 0 && heightA > 0) {
|
||||||
if (width > 0 && height > 0) {
|
if (width > 0 && height > 0) {
|
||||||
@@ -324,7 +344,7 @@ namespace sharp {
|
|||||||
throw VError("Band expansion using linear is unsupported");
|
throw VError("Band expansion using linear is unsupported");
|
||||||
}
|
}
|
||||||
bool const uchar = !Is16Bit(image.interpretation());
|
bool const uchar = !Is16Bit(image.interpretation());
|
||||||
if (HasAlpha(image) && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
|
if (image.has_alpha() && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
|
||||||
// Separate alpha channel
|
// Separate alpha channel
|
||||||
VImage alpha = image[bands - 1];
|
VImage alpha = image[bands - 1];
|
||||||
return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", uchar)).bandjoin(alpha);
|
return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", uchar)).bandjoin(alpha);
|
||||||
@@ -337,7 +357,7 @@ namespace sharp {
|
|||||||
* Unflatten
|
* Unflatten
|
||||||
*/
|
*/
|
||||||
VImage Unflatten(VImage image) {
|
VImage Unflatten(VImage image) {
|
||||||
if (HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
VImage noAlpha = RemoveAlpha(image);
|
VImage noAlpha = RemoveAlpha(image);
|
||||||
return noAlpha.bandjoin(alpha & (noAlpha.colourspace(VIPS_INTERPRETATION_B_W) < 255));
|
return noAlpha.bandjoin(alpha & (noAlpha.colourspace(VIPS_INTERPRETATION_B_W) < 255));
|
||||||
@@ -370,6 +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);
|
||||||
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));
|
||||||
@@ -451,4 +472,26 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dilate an image
|
||||||
|
*/
|
||||||
|
VImage Dilate(VImage image, int const width) {
|
||||||
|
int const maskWidth = 2 * width + 1;
|
||||||
|
VImage mask = VImage::new_matrix(maskWidth, maskWidth);
|
||||||
|
return image.morph(
|
||||||
|
mask,
|
||||||
|
VIPS_OPERATION_MORPHOLOGY_DILATE).invert();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Erode an image
|
||||||
|
*/
|
||||||
|
VImage Erode(VImage image, int const width) {
|
||||||
|
int const maskWidth = 2 * width + 1;
|
||||||
|
VImage mask = VImage::new_matrix(maskWidth, maskWidth);
|
||||||
|
return image.morph(
|
||||||
|
mask,
|
||||||
|
VIPS_OPERATION_MORPHOLOGY_ERODE).invert();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ using vips::VImage;
|
|||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tint an image using the specified chroma, preserving the original image luminance
|
* Tint an image using the provided RGB.
|
||||||
*/
|
*/
|
||||||
VImage Tint(VImage image, double const a, double const b);
|
VImage Tint(VImage image, std::vector<double> const tint);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stretch luminance to cover full dynamic range.
|
* Stretch luminance to cover full dynamic range.
|
||||||
@@ -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.
|
||||||
@@ -79,7 +79,7 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
Trim an image
|
Trim an image
|
||||||
*/
|
*/
|
||||||
VImage Trim(VImage image, std::vector<double> background, double const threshold);
|
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Linear adjustment (a * in + b)
|
* Linear adjustment (a * in + b)
|
||||||
@@ -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
|
||||||
@@ -120,6 +120,15 @@ namespace sharp {
|
|||||||
VImage EmbedMultiPage(VImage image, int left, int top, int width, int height,
|
VImage EmbedMultiPage(VImage image, int left, int top, int width, int height,
|
||||||
VipsExtend extendWith, std::vector<double> background, int nPages, int *pageHeight);
|
VipsExtend extendWith, std::vector<double> background, int nPages, int *pageHeight);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dilate an image
|
||||||
|
*/
|
||||||
|
VImage Dilate(VImage image, int const maskWidth);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Erode an image
|
||||||
|
*/
|
||||||
|
VImage Erode(VImage image, int const maskWidth);
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
#endif // SRC_OPERATIONS_H_
|
#endif // SRC_OPERATIONS_H_
|
||||||
|
|||||||
422
src/pipeline.cc
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <filesystem>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
@@ -20,17 +21,6 @@
|
|||||||
#include "operations.h"
|
#include "operations.h"
|
||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define STAT64_STRUCT __stat64
|
|
||||||
#define STAT64_FUNCTION _stat64
|
|
||||||
#elif defined(_LARGEFILE64_SOURCE)
|
|
||||||
#define STAT64_STRUCT stat64
|
|
||||||
#define STAT64_FUNCTION stat64
|
|
||||||
#else
|
|
||||||
#define STAT64_STRUCT stat
|
|
||||||
#define STAT64_FUNCTION stat
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class PipelineWorker : public Napi::AsyncWorker {
|
class PipelineWorker : public Napi::AsyncWorker {
|
||||||
public:
|
public:
|
||||||
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
|
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
|
||||||
@@ -52,9 +42,41 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Open input
|
// Open input
|
||||||
vips::VImage image;
|
vips::VImage image;
|
||||||
sharp::ImageType inputImageType;
|
sharp::ImageType inputImageType;
|
||||||
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
if (baton->join.empty()) {
|
||||||
|
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
||||||
|
} else {
|
||||||
|
std::vector<VImage> images;
|
||||||
|
bool hasAlpha = false;
|
||||||
|
for (auto &join : baton->join) {
|
||||||
|
std::tie(image, inputImageType) = sharp::OpenInput(join);
|
||||||
|
image = sharp::EnsureColourspace(image, baton->colourspacePipeline);
|
||||||
|
images.push_back(image);
|
||||||
|
hasAlpha |= image.has_alpha();
|
||||||
|
}
|
||||||
|
if (hasAlpha) {
|
||||||
|
for (auto &image : images) {
|
||||||
|
if (!image.has_alpha()) {
|
||||||
|
image = sharp::EnsureAlpha(image, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
baton->input->joinBackground.pop_back();
|
||||||
|
}
|
||||||
|
inputImageType = sharp::ImageType::PNG;
|
||||||
|
image = VImage::arrayjoin(images, VImage::option()
|
||||||
|
->set("across", baton->input->joinAcross)
|
||||||
|
->set("shim", baton->input->joinShim)
|
||||||
|
->set("background", baton->input->joinBackground)
|
||||||
|
->set("halign", baton->input->joinHalign)
|
||||||
|
->set("valign", baton->input->joinValign));
|
||||||
|
if (baton->input->joinAnimated) {
|
||||||
|
image = image.copy();
|
||||||
|
image.set(VIPS_META_N_PAGES, static_cast<int>(images.size()));
|
||||||
|
image.set(VIPS_META_PAGE_HEIGHT, static_cast<int>(image.height() / images.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
VipsAccess access = baton->input->access;
|
VipsAccess access = baton->input->access;
|
||||||
image = sharp::EnsureColourspace(image, baton->colourspaceInput);
|
image = sharp::EnsureColourspace(image, baton->colourspacePipeline);
|
||||||
|
|
||||||
int nPages = baton->input->pages;
|
int nPages = baton->input->pages;
|
||||||
if (nPages == -1) {
|
if (nPages == -1) {
|
||||||
@@ -70,17 +92,17 @@ 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->input->autoOrient) {
|
||||||
// Rotate and flip image according to Exif orientation
|
// Rotate and flip image according to Exif orientation
|
||||||
std::tie(autoRotation, autoFlip, autoFlop) = CalculateExifRotationAndFlip(sharp::ExifOrientation(image));
|
std::tie(autoRotation, autoFlip, autoFlop) = CalculateExifRotationAndFlip(sharp::ExifOrientation(image));
|
||||||
image = sharp::RemoveExifOrientation(image);
|
image = sharp::RemoveExifOrientation(image);
|
||||||
} else {
|
|
||||||
rotation = CalculateAngleRotation(baton->angle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rotation = CalculateAngleRotation(baton->angle);
|
||||||
|
|
||||||
// Rotate pre-extract
|
// Rotate pre-extract
|
||||||
bool const shouldRotateBefore = baton->rotateBeforePreExtract &&
|
bool const shouldRotateBefore = baton->rotateBeforePreExtract &&
|
||||||
(rotation != VIPS_ANGLE_D0 || autoRotation != VIPS_ANGLE_D0 ||
|
(rotation != VIPS_ANGLE_D0 || autoRotation != VIPS_ANGLE_D0 ||
|
||||||
@@ -88,7 +110,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 ||
|
||||||
@@ -96,40 +118,42 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
baton->rotationAngle != 0.0);
|
baton->rotationAngle != 0.0);
|
||||||
|
|
||||||
if (autoRotation != VIPS_ANGLE_D0) {
|
if (autoRotation != VIPS_ANGLE_D0) {
|
||||||
|
if (autoRotation != VIPS_ANGLE_D180) {
|
||||||
|
MultiPageUnsupported(nPages, "Rotate");
|
||||||
|
}
|
||||||
image = image.rot(autoRotation);
|
image = image.rot(autoRotation);
|
||||||
autoRotation = VIPS_ANGLE_D0;
|
autoRotation = VIPS_ANGLE_D0;
|
||||||
}
|
}
|
||||||
if (autoFlip) {
|
if (autoFlip != baton->flip) {
|
||||||
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
||||||
autoFlip = FALSE;
|
autoFlip = false;
|
||||||
} else if (baton->flip) {
|
baton->flip = false;
|
||||||
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
|
||||||
baton->flip = FALSE;
|
|
||||||
}
|
}
|
||||||
if (autoFlop) {
|
if (autoFlop != baton->flop) {
|
||||||
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
||||||
autoFlop = FALSE;
|
autoFlop = false;
|
||||||
} else if (baton->flop) {
|
baton->flop = false;
|
||||||
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
|
||||||
baton->flop = FALSE;
|
|
||||||
}
|
}
|
||||||
if (rotation != VIPS_ANGLE_D0) {
|
if (rotation != VIPS_ANGLE_D0) {
|
||||||
|
if (rotation != VIPS_ANGLE_D180) {
|
||||||
|
MultiPageUnsupported(nPages, "Rotate");
|
||||||
|
}
|
||||||
image = image.rot(rotation);
|
image = image.rot(rotation);
|
||||||
rotation = VIPS_ANGLE_D0;
|
rotation = VIPS_ANGLE_D0;
|
||||||
}
|
}
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
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();
|
||||||
}
|
}
|
||||||
@@ -182,8 +206,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// - trimming or pre-resize extract isn't required;
|
// - trimming or pre-resize extract isn't required;
|
||||||
// - input colourspace is not specified;
|
// - input colourspace is not specified;
|
||||||
bool const shouldPreShrink = (targetResizeWidth > 0 || targetResizeHeight > 0) &&
|
bool const shouldPreShrink = (targetResizeWidth > 0 || targetResizeHeight > 0) &&
|
||||||
baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimThreshold == 0.0 &&
|
baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimThreshold < 0.0 &&
|
||||||
baton->colourspaceInput == VIPS_INTERPRETATION_LAST && !shouldRotateBefore;
|
baton->colourspacePipeline == VIPS_INTERPRETATION_LAST && !shouldRotateBefore;
|
||||||
|
|
||||||
if (shouldPreShrink) {
|
if (shouldPreShrink) {
|
||||||
// The common part of the shrink: the bit by which both axes must be shrunk
|
// The common part of the shrink: the bit by which both axes must be shrunk
|
||||||
@@ -315,17 +339,24 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we're using a device-independent colour space
|
// Ensure we're using a device-independent colour space
|
||||||
|
std::pair<char*, size_t> inputProfile(nullptr, 0);
|
||||||
|
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->withIccProfile.empty()) {
|
||||||
|
// Cache input profile for use with output
|
||||||
|
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 (
|
||||||
sharp::HasProfile(image) &&
|
sharp::HasProfile(image) &&
|
||||||
image.interpretation() != VIPS_INTERPRETATION_LABS &&
|
image.interpretation() != VIPS_INTERPRETATION_LABS &&
|
||||||
image.interpretation() != VIPS_INTERPRETATION_GREY16 &&
|
image.interpretation() != VIPS_INTERPRETATION_GREY16 &&
|
||||||
|
baton->colourspacePipeline != VIPS_INTERPRETATION_CMYK &&
|
||||||
!baton->input->ignoreIcc
|
!baton->input->ignoreIcc
|
||||||
) {
|
) {
|
||||||
// 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(...) {
|
||||||
@@ -333,7 +364,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
image.interpretation() == VIPS_INTERPRETATION_CMYK &&
|
image.interpretation() == VIPS_INTERPRETATION_CMYK &&
|
||||||
baton->colourspaceInput != VIPS_INTERPRETATION_CMYK
|
baton->colourspacePipeline != VIPS_INTERPRETATION_CMYK
|
||||||
) {
|
) {
|
||||||
image = image.icc_transform(processingProfile, VImage::option()
|
image = image.icc_transform(processingProfile, VImage::option()
|
||||||
->set("input_profile", "cmyk")
|
->set("input_profile", "cmyk")
|
||||||
@@ -341,15 +372,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flatten image to remove alpha channel
|
// Flatten image to remove alpha channel
|
||||||
if (baton->flatten && sharp::HasAlpha(image)) {
|
if (baton->flatten && image.has_alpha()) {
|
||||||
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);
|
||||||
@@ -366,12 +392,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
||||||
bool const shouldComposite = !baton->composite.empty();
|
bool const shouldComposite = !baton->composite.empty();
|
||||||
|
|
||||||
if (shouldComposite && !sharp::HasAlpha(image)) {
|
if (shouldComposite && !image.has_alpha()) {
|
||||||
image = sharp::EnsureAlpha(image, 1);
|
image = sharp::EnsureAlpha(image, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
VipsBandFormat premultiplyFormat = image.format();
|
VipsBandFormat premultiplyFormat = image.format();
|
||||||
bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) &&
|
bool const shouldPremultiplyAlpha = image.has_alpha() &&
|
||||||
(shouldResize || shouldBlur || shouldConv || shouldSharpen);
|
(shouldResize || shouldBlur || shouldConv || shouldSharpen);
|
||||||
|
|
||||||
if (shouldPremultiplyAlpha) {
|
if (shouldPremultiplyAlpha) {
|
||||||
@@ -385,25 +411,31 @@ 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 ||
|
||||||
rotation != VIPS_ANGLE_D0);
|
rotation != VIPS_ANGLE_D0);
|
||||||
// Auto-rotate post-extract
|
// Auto-rotate post-extract
|
||||||
if (autoRotation != VIPS_ANGLE_D0) {
|
if (autoRotation != VIPS_ANGLE_D0) {
|
||||||
|
if (autoRotation != VIPS_ANGLE_D180) {
|
||||||
|
MultiPageUnsupported(nPages, "Rotate");
|
||||||
|
}
|
||||||
image = image.rot(autoRotation);
|
image = image.rot(autoRotation);
|
||||||
}
|
}
|
||||||
// Mirror vertically (up-down) about the x-axis
|
// Mirror vertically (up-down) about the x-axis
|
||||||
if (baton->flip || autoFlip) {
|
if (baton->flip != autoFlip) {
|
||||||
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
||||||
}
|
}
|
||||||
// Mirror horizontally (left-right) about the y-axis
|
// Mirror horizontally (left-right) about the y-axis
|
||||||
if (baton->flop || autoFlop) {
|
if (baton->flop != autoFlop) {
|
||||||
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
image = image.flip(VIPS_DIRECTION_HORIZONTAL);
|
||||||
}
|
}
|
||||||
// Rotate post-extract 90-angle
|
// Rotate post-extract 90-angle
|
||||||
if (rotation != VIPS_ANGLE_D0) {
|
if (rotation != VIPS_ANGLE_D0) {
|
||||||
|
if (rotation != VIPS_ANGLE_D180) {
|
||||||
|
MultiPageUnsupported(nPages, "Rotate");
|
||||||
|
}
|
||||||
image = image.rot(rotation);
|
image = image.rot(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +447,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
for (unsigned int i = 0; i < baton->joinChannelIn.size(); i++) {
|
for (unsigned int i = 0; i < baton->joinChannelIn.size(); i++) {
|
||||||
baton->joinChannelIn[i]->access = access;
|
baton->joinChannelIn[i]->access = access;
|
||||||
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i]);
|
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i]);
|
||||||
joinImage = sharp::EnsureColourspace(joinImage, baton->colourspaceInput);
|
joinImage = sharp::EnsureColourspace(joinImage, baton->colourspacePipeline);
|
||||||
image = image.bandjoin(joinImage);
|
image = image.bandjoin(joinImage);
|
||||||
}
|
}
|
||||||
image = image.copy(VImage::option()->set("interpretation", baton->colourspace));
|
image = image.copy(VImage::option()->set("interpretation", baton->colourspace));
|
||||||
@@ -482,12 +514,10 @@ 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)
|
||||||
#if (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 15)
|
|
||||||
->set("premultiplied", shouldPremultiplyAlpha)
|
->set("premultiplied", shouldPremultiplyAlpha)
|
||||||
#endif
|
|
||||||
->set("attention_x", &attention_x)
|
->set("attention_x", &attention_x)
|
||||||
->set("attention_y", &attention_y));
|
->set("attention_y", &attention_y));
|
||||||
baton->hasCropOffset = true;
|
baton->hasCropOffset = true;
|
||||||
@@ -503,7 +533,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));
|
||||||
@@ -527,7 +557,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(
|
||||||
@@ -550,6 +580,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,
|
||||||
@@ -558,6 +589,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);
|
||||||
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,
|
||||||
@@ -577,9 +609,19 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dilate - must happen before blurring, due to the utility of dilating after thresholding
|
||||||
|
if (baton->dilateWidth != 0) {
|
||||||
|
image = sharp::Dilate(image, baton->dilateWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erode - must happen before blurring, due to the utility of eroding after thresholding
|
||||||
|
if (baton->erodeWidth != 0) {
|
||||||
|
image = sharp::Erode(image, baton->erodeWidth);
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@@ -596,7 +638,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,7 +668,31 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
sharp::ImageType compositeImageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType compositeImageType = sharp::ImageType::UNKNOWN;
|
||||||
composite->input->access = access;
|
composite->input->access = access;
|
||||||
std::tie(compositeImage, compositeImageType) = sharp::OpenInput(composite->input);
|
std::tie(compositeImage, compositeImageType) = sharp::OpenInput(composite->input);
|
||||||
compositeImage = sharp::EnsureColourspace(compositeImage, baton->colourspaceInput);
|
compositeImage = sharp::EnsureColourspace(compositeImage, baton->colourspacePipeline);
|
||||||
|
|
||||||
|
if (composite->input->autoOrient) {
|
||||||
|
// Respect EXIF Orientation
|
||||||
|
VipsAngle compositeAutoRotation = VIPS_ANGLE_D0;
|
||||||
|
bool compositeAutoFlip = false;
|
||||||
|
bool compositeAutoFlop = false;
|
||||||
|
std::tie(compositeAutoRotation, compositeAutoFlip, compositeAutoFlop) =
|
||||||
|
CalculateExifRotationAndFlip(sharp::ExifOrientation(compositeImage));
|
||||||
|
|
||||||
|
compositeImage = sharp::RemoveExifOrientation(compositeImage);
|
||||||
|
compositeImage = sharp::StaySequential(compositeImage,
|
||||||
|
compositeAutoRotation != VIPS_ANGLE_D0 || compositeAutoFlip);
|
||||||
|
|
||||||
|
if (compositeAutoRotation != VIPS_ANGLE_D0) {
|
||||||
|
compositeImage = compositeImage.rot(compositeAutoRotation);
|
||||||
|
}
|
||||||
|
if (compositeAutoFlip) {
|
||||||
|
compositeImage = compositeImage.flip(VIPS_DIRECTION_VERTICAL);
|
||||||
|
}
|
||||||
|
if (compositeAutoFlop) {
|
||||||
|
compositeImage = compositeImage.flip(VIPS_DIRECTION_HORIZONTAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Verify within current dimensions
|
// Verify within current dimensions
|
||||||
if (compositeImage.width() > image.width() || compositeImage.height() > image.height()) {
|
if (compositeImage.width() > image.width() || compositeImage.height() > image.height()) {
|
||||||
throw vips::VError("Image to composite must have same dimensions or smaller");
|
throw vips::VError("Image to composite must have same dimensions or smaller");
|
||||||
@@ -653,7 +719,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(),
|
||||||
@@ -669,9 +735,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
// Ensure image to composite is sRGB with unpremultiplied alpha
|
// Ensure image to composite is sRGB with unpremultiplied alpha
|
||||||
compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
|
compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
if (!sharp::HasAlpha(compositeImage)) {
|
compositeImage = sharp::EnsureAlpha(compositeImage, 1);
|
||||||
compositeImage = sharp::EnsureAlpha(compositeImage, 1);
|
|
||||||
}
|
|
||||||
if (composite->premultiplied) compositeImage = compositeImage.unpremultiply();
|
if (composite->premultiplied) compositeImage = compositeImage.unpremultiply();
|
||||||
// Calculate position
|
// Calculate position
|
||||||
int left;
|
int left;
|
||||||
@@ -711,13 +775,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,7 +791,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
sharp::ImageType booleanImageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType booleanImageType = sharp::ImageType::UNKNOWN;
|
||||||
baton->boolean->access = access;
|
baton->boolean->access = access;
|
||||||
std::tie(booleanImage, booleanImageType) = sharp::OpenInput(baton->boolean);
|
std::tie(booleanImage, booleanImageType) = sharp::OpenInput(baton->boolean);
|
||||||
booleanImage = sharp::EnsureColourspace(booleanImage, baton->colourspaceInput);
|
booleanImage = sharp::EnsureColourspace(booleanImage, baton->colourspacePipeline);
|
||||||
image = sharp::Boolean(image, booleanImage, baton->booleanOp);
|
image = sharp::Boolean(image, booleanImage, baton->booleanOp);
|
||||||
image = sharp::RemoveGifPalette(image);
|
image = sharp::RemoveGifPalette(image);
|
||||||
}
|
}
|
||||||
@@ -738,8 +802,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tint the image
|
// Tint the image
|
||||||
if (baton->tintA < 128.0 || baton->tintB < 128.0) {
|
if (baton->tint[0] >= 0.0) {
|
||||||
image = sharp::Tint(image, baton->tintA, baton->tintB);
|
image = sharp::Tint(image, baton->tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove alpha channel, if any
|
// Remove alpha channel, if any
|
||||||
@@ -760,9 +824,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
||||||
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
||||||
// Transform colours from embedded profile to output profile
|
// Transform colours from embedded profile to output profile
|
||||||
if (baton->withMetadata && sharp::HasProfile(image) && baton->withMetadataIcc.empty()) {
|
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->colourspacePipeline != VIPS_INTERPRETATION_CMYK &&
|
||||||
image = image.icc_transform("srgb", VImage::option()
|
baton->withIccProfile.empty() && sharp::HasProfile(image)) {
|
||||||
->set("embedded", TRUE)
|
image = image.icc_transform(processingProfile, VImage::option()
|
||||||
|
->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));
|
||||||
}
|
}
|
||||||
@@ -771,7 +836,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Extract channel
|
// Extract channel
|
||||||
if (baton->extractChannel > -1) {
|
if (baton->extractChannel > -1) {
|
||||||
if (baton->extractChannel >= image.bands()) {
|
if (baton->extractChannel >= image.bands()) {
|
||||||
if (baton->extractChannel == 3 && sharp::HasAlpha(image)) {
|
if (baton->extractChannel == 3 && image.has_alpha()) {
|
||||||
baton->extractChannel = image.bands() - 1;
|
baton->extractChannel = image.bands() - 1;
|
||||||
} else {
|
} else {
|
||||||
(baton->err)
|
(baton->err)
|
||||||
@@ -789,27 +854,40 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply output ICC profile
|
// Apply output ICC profile
|
||||||
if (baton->withMetadata) {
|
if (!baton->withIccProfile.empty()) {
|
||||||
image = image.icc_transform(
|
try {
|
||||||
baton->withMetadataIcc.empty() ? "srgb" : const_cast<char*>(baton->withMetadataIcc.data()),
|
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
|
||||||
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(...) {
|
||||||
|
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
|
||||||
|
}
|
||||||
|
} else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) {
|
||||||
|
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->withMetadata && baton->withMetadataOrientation != -1) {
|
if (baton->withMetadataOrientation != -1) {
|
||||||
image = sharp::SetExifOrientation(image, baton->withMetadataOrientation);
|
image = sharp::SetExifOrientation(image, baton->withMetadataOrientation);
|
||||||
}
|
}
|
||||||
// Override pixel density
|
// Override pixel density
|
||||||
if (baton->withMetadataDensity > 0) {
|
if (baton->withMetadataDensity > 0) {
|
||||||
image = sharp::SetDensity(image, baton->withMetadataDensity);
|
image = sharp::SetDensity(image, baton->withMetadataDensity);
|
||||||
}
|
}
|
||||||
// Metadata key/value pairs, e.g. EXIF
|
// EXIF key/value pairs
|
||||||
if (!baton->withMetadataStrs.empty()) {
|
if (baton->keepMetadata & VIPS_FOREIGN_KEEP_EXIF) {
|
||||||
image = image.copy();
|
image = image.copy();
|
||||||
for (const auto& s : baton->withMetadataStrs) {
|
if (!baton->withExifMerge) {
|
||||||
|
image = sharp::RemoveExif(image);
|
||||||
|
}
|
||||||
|
for (const auto& s : baton->withExif) {
|
||||||
image.set(s.first.data(), s.second.data());
|
image.set(s.first.data(), s.second.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -822,6 +900,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()) {
|
||||||
@@ -830,7 +913,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write JPEG to buffer
|
// Write JPEG to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.jpegsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.jpegsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->jpegQuality)
|
->set("Q", baton->jpegQuality)
|
||||||
->set("interlace", baton->jpegProgressive)
|
->set("interlace", baton->jpegProgressive)
|
||||||
->set("subsample_mode", baton->jpegChromaSubsampling == "4:4:4"
|
->set("subsample_mode", baton->jpegChromaSubsampling == "4:4:4"
|
||||||
@@ -872,7 +955,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write PNG to buffer
|
// Write PNG to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.pngsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.pngsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
|
||||||
@@ -891,11 +974,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write WEBP to buffer
|
// Write WEBP to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::WEBP);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::WEBP);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.webpsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.webpsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
->set("smart_subsample", baton->webpSmartSubsample)
|
->set("smart_subsample", baton->webpSmartSubsample)
|
||||||
|
->set("smart_deblock", baton->webpSmartDeblock)
|
||||||
->set("preset", baton->webpPreset)
|
->set("preset", baton->webpPreset)
|
||||||
->set("effort", baton->webpEffort)
|
->set("effort", baton->webpEffort)
|
||||||
->set("min_size", baton->webpMinSize)
|
->set("min_size", baton->webpMinSize)
|
||||||
@@ -911,7 +995,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write GIF to buffer
|
// Write GIF to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.gifsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.gifsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("bitdepth", baton->gifBitdepth)
|
->set("bitdepth", baton->gifBitdepth)
|
||||||
->set("effort", baton->gifEffort)
|
->set("effort", baton->gifEffort)
|
||||||
->set("reuse", baton->gifReuse)
|
->set("reuse", baton->gifReuse)
|
||||||
@@ -936,10 +1020,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = image.cast(VIPS_FORMAT_FLOAT);
|
image = image.cast(VIPS_FORMAT_FLOAT);
|
||||||
}
|
}
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.tiffsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.tiffsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->tiffQuality)
|
->set("Q", baton->tiffQuality)
|
||||||
->set("bitdepth", baton->tiffBitdepth)
|
->set("bitdepth", baton->tiffBitdepth)
|
||||||
->set("compression", baton->tiffCompression)
|
->set("compression", baton->tiffCompression)
|
||||||
|
->set("miniswhite", baton->tiffMiniswhite)
|
||||||
->set("predictor", baton->tiffPredictor)
|
->set("predictor", baton->tiffPredictor)
|
||||||
->set("pyramid", baton->tiffPyramid)
|
->set("pyramid", baton->tiffPyramid)
|
||||||
->set("tile", baton->tiffTile)
|
->set("tile", baton->tiffTile)
|
||||||
@@ -957,13 +1042,13 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
(baton->formatOut == "input" && inputImageType == sharp::ImageType::HEIF)) {
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::HEIF)) {
|
||||||
// Write HEIF to buffer
|
// Write HEIF to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::HEIF);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::HEIF);
|
||||||
image = sharp::RemoveAnimationProperties(image).cast(VIPS_FORMAT_UCHAR);
|
image = sharp::RemoveAnimationProperties(image);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.heifsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.heifsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->heifQuality)
|
->set("Q", baton->heifQuality)
|
||||||
->set("compression", baton->heifCompression)
|
->set("compression", baton->heifCompression)
|
||||||
->set("effort", baton->heifEffort)
|
->set("effort", baton->heifEffort)
|
||||||
->set("bitdepth", 8)
|
->set("bitdepth", baton->heifBitdepth)
|
||||||
->set("subsample_mode", baton->heifChromaSubsampling == "4:4:4"
|
->set("subsample_mode", baton->heifChromaSubsampling == "4:4:4"
|
||||||
? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON)
|
? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON)
|
||||||
->set("lossless", baton->heifLossless)));
|
->set("lossless", baton->heifLossless)));
|
||||||
@@ -975,10 +1060,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
} else if (baton->formatOut == "dz") {
|
} else if (baton->formatOut == "dz") {
|
||||||
// Write DZ to buffer
|
// Write DZ to buffer
|
||||||
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
||||||
if (!sharp::HasAlpha(image)) {
|
if (!image.has_alpha()) {
|
||||||
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);
|
||||||
@@ -991,7 +1076,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write JXL to buffer
|
// Write JXL to buffer
|
||||||
image = sharp::RemoveAnimationProperties(image);
|
image = sharp::RemoveAnimationProperties(image);
|
||||||
VipsArea *area = reinterpret_cast<VipsArea*>(image.jxlsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.jxlsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("distance", baton->jxlDistance)
|
->set("distance", baton->jxlDistance)
|
||||||
->set("tier", baton->jxlDecodingTier)
|
->set("tier", baton->jxlDecodingTier)
|
||||||
->set("effort", baton->jxlEffort)
|
->set("effort", baton->jxlEffort)
|
||||||
@@ -1024,6 +1109,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Unsupported output format
|
// Unsupported output format
|
||||||
(baton->err).append("Unsupported output format ");
|
(baton->err).append("Unsupported output format ");
|
||||||
if (baton->formatOut == "input") {
|
if (baton->formatOut == "input") {
|
||||||
|
(baton->err).append("when trying to match input format of ");
|
||||||
(baton->err).append(ImageTypeId(inputImageType));
|
(baton->err).append(ImageTypeId(inputImageType));
|
||||||
} else {
|
} else {
|
||||||
(baton->err).append(baton->formatOut);
|
(baton->err).append(baton->formatOut);
|
||||||
@@ -1052,7 +1138,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write JPEG to file
|
// Write JPEG to file
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
||||||
image.jpegsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.jpegsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->jpegQuality)
|
->set("Q", baton->jpegQuality)
|
||||||
->set("interlace", baton->jpegProgressive)
|
->set("interlace", baton->jpegProgressive)
|
||||||
->set("subsample_mode", baton->jpegChromaSubsampling == "4:4:4"
|
->set("subsample_mode", baton->jpegChromaSubsampling == "4:4:4"
|
||||||
@@ -1082,7 +1168,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write PNG to file
|
// Write PNG to file
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
||||||
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
|
||||||
@@ -1097,11 +1183,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write WEBP to file
|
// Write WEBP to file
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::WEBP);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::WEBP);
|
||||||
image.webpsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.webpsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
->set("smart_subsample", baton->webpSmartSubsample)
|
->set("smart_subsample", baton->webpSmartSubsample)
|
||||||
|
->set("smart_deblock", baton->webpSmartDeblock)
|
||||||
->set("preset", baton->webpPreset)
|
->set("preset", baton->webpPreset)
|
||||||
->set("effort", baton->webpEffort)
|
->set("effort", baton->webpEffort)
|
||||||
->set("min_size", baton->webpMinSize)
|
->set("min_size", baton->webpMinSize)
|
||||||
@@ -1113,7 +1200,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write GIF to file
|
// Write GIF to file
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
||||||
image.gifsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.gifsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("bitdepth", baton->gifBitdepth)
|
->set("bitdepth", baton->gifBitdepth)
|
||||||
->set("effort", baton->gifEffort)
|
->set("effort", baton->gifEffort)
|
||||||
->set("reuse", baton->gifReuse)
|
->set("reuse", baton->gifReuse)
|
||||||
@@ -1132,10 +1219,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = image.cast(VIPS_FORMAT_FLOAT);
|
image = image.cast(VIPS_FORMAT_FLOAT);
|
||||||
}
|
}
|
||||||
image.tiffsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.tiffsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->tiffQuality)
|
->set("Q", baton->tiffQuality)
|
||||||
->set("bitdepth", baton->tiffBitdepth)
|
->set("bitdepth", baton->tiffBitdepth)
|
||||||
->set("compression", baton->tiffCompression)
|
->set("compression", baton->tiffCompression)
|
||||||
|
->set("miniswhite", baton->tiffMiniswhite)
|
||||||
->set("predictor", baton->tiffPredictor)
|
->set("predictor", baton->tiffPredictor)
|
||||||
->set("pyramid", baton->tiffPyramid)
|
->set("pyramid", baton->tiffPyramid)
|
||||||
->set("tile", baton->tiffTile)
|
->set("tile", baton->tiffTile)
|
||||||
@@ -1149,13 +1237,13 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
(willMatchInput && inputImageType == sharp::ImageType::HEIF)) {
|
(willMatchInput && inputImageType == sharp::ImageType::HEIF)) {
|
||||||
// Write HEIF to file
|
// Write HEIF to file
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::HEIF);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::HEIF);
|
||||||
image = sharp::RemoveAnimationProperties(image).cast(VIPS_FORMAT_UCHAR);
|
image = sharp::RemoveAnimationProperties(image);
|
||||||
image.heifsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.heifsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("Q", baton->heifQuality)
|
->set("Q", baton->heifQuality)
|
||||||
->set("compression", baton->heifCompression)
|
->set("compression", baton->heifCompression)
|
||||||
->set("effort", baton->heifEffort)
|
->set("effort", baton->heifEffort)
|
||||||
->set("bitdepth", 8)
|
->set("bitdepth", baton->heifBitdepth)
|
||||||
->set("subsample_mode", baton->heifChromaSubsampling == "4:4:4"
|
->set("subsample_mode", baton->heifChromaSubsampling == "4:4:4"
|
||||||
? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON)
|
? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON)
|
||||||
->set("lossless", baton->heifLossless));
|
->set("lossless", baton->heifLossless));
|
||||||
@@ -1165,7 +1253,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Write JXL to file
|
// Write JXL to file
|
||||||
image = sharp::RemoveAnimationProperties(image);
|
image = sharp::RemoveAnimationProperties(image);
|
||||||
image.jxlsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.jxlsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("distance", baton->jxlDistance)
|
->set("distance", baton->jxlDistance)
|
||||||
->set("tier", baton->jxlDecodingTier)
|
->set("tier", baton->jxlDecodingTier)
|
||||||
->set("effort", baton->jxlEffort)
|
->set("effort", baton->jxlEffort)
|
||||||
@@ -1176,10 +1264,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (isDzZip) {
|
if (isDzZip) {
|
||||||
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
||||||
}
|
}
|
||||||
if (!sharp::HasAlpha(image)) {
|
if (!image.has_alpha()) {
|
||||||
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";
|
||||||
@@ -1187,7 +1275,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
(willMatchInput && inputImageType == sharp::ImageType::VIPS)) {
|
(willMatchInput && inputImageType == sharp::ImageType::VIPS)) {
|
||||||
// Write V to file
|
// Write V to file
|
||||||
image.vipssave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.vipssave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata));
|
->set("keep", baton->keepMetadata));
|
||||||
baton->formatOut = "v";
|
baton->formatOut = "v";
|
||||||
} else {
|
} else {
|
||||||
// Unsupported output format
|
// Unsupported output format
|
||||||
@@ -1215,7 +1303,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Handle warnings
|
// Handle warnings
|
||||||
std::string warning = sharp::VipsWarningPop();
|
std::string warning = sharp::VipsWarningPop();
|
||||||
while (!warning.empty()) {
|
while (!warning.empty()) {
|
||||||
debuglog.MakeCallback(Receiver().Value(), { Napi::String::New(env, warning) });
|
debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1248,14 +1336,17 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("attentionX", static_cast<int32_t>(baton->attentionX));
|
info.Set("attentionX", static_cast<int32_t>(baton->attentionX));
|
||||||
info.Set("attentionY", static_cast<int32_t>(baton->attentionY));
|
info.Set("attentionY", static_cast<int32_t>(baton->attentionY));
|
||||||
}
|
}
|
||||||
if (baton->trimThreshold > 0.0) {
|
if (baton->trimThreshold >= 0.0) {
|
||||||
info.Set("trimOffsetLeft", static_cast<int32_t>(baton->trimOffsetLeft));
|
info.Set("trimOffsetLeft", static_cast<int32_t>(baton->trimOffsetLeft));
|
||||||
info.Set("trimOffsetTop", static_cast<int32_t>(baton->trimOffsetTop));
|
info.Set("trimOffsetTop", static_cast<int32_t>(baton->trimOffsetTop));
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -1263,17 +1354,19 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Pass ownership of output data to Buffer instance
|
// Pass ownership of output data to Buffer instance
|
||||||
Napi::Buffer<char> data = Napi::Buffer<char>::NewOrCopy(env, static_cast<char*>(baton->bufferOut),
|
Napi::Buffer<char> data = Napi::Buffer<char>::NewOrCopy(env, static_cast<char*>(baton->bufferOut),
|
||||||
baton->bufferOutLength, sharp::FreeCallback);
|
baton->bufferOutLength, sharp::FreeCallback);
|
||||||
Callback().MakeCallback(Receiver().Value(), { env.Null(), data, info });
|
Callback().Call(Receiver().Value(), { env.Null(), data, info });
|
||||||
} else {
|
} else {
|
||||||
// Add file size to info
|
// Add file size to info
|
||||||
struct STAT64_STRUCT st;
|
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
|
||||||
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
|
try {
|
||||||
info.Set("size", static_cast<uint32_t>(st.st_size));
|
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
|
||||||
|
info.Set("size", size);
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
Callback().MakeCallback(Receiver().Value(), { env.Null(), info });
|
Callback().Call(Receiver().Value(), { env.Null(), info });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete baton
|
// Delete baton
|
||||||
@@ -1286,12 +1379,15 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
for (sharp::InputDescriptor *input : baton->joinChannelIn) {
|
for (sharp::InputDescriptor *input : baton->joinChannelIn) {
|
||||||
delete input;
|
delete input;
|
||||||
}
|
}
|
||||||
|
for (sharp::InputDescriptor *input : baton->join) {
|
||||||
|
delete input;
|
||||||
|
}
|
||||||
delete baton;
|
delete baton;
|
||||||
|
|
||||||
// Decrement processing task counter
|
// Decrement processing task counter
|
||||||
sharp::counterProcess--;
|
sharp::counterProcess--;
|
||||||
Napi::Number queueLength = Napi::Number::New(env, static_cast<int>(sharp::counterQueue));
|
Napi::Number queueLength = Napi::Number::New(env, static_cast<int>(sharp::counterQueue));
|
||||||
queueListener.MakeCallback(Receiver().Value(), { queueLength });
|
queueListener.Call(Receiver().Value(), { queueLength });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -1312,16 +1408,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);
|
||||||
}
|
}
|
||||||
@@ -1369,7 +1465,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"}
|
||||||
};
|
};
|
||||||
@@ -1378,31 +1474,32 @@ 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"},
|
||||||
|
{"smart_deblock", baton->webpSmartDeblock ? "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);
|
||||||
}
|
}
|
||||||
vips::VOption *options = VImage::option()
|
vips::VOption *options = VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("keep", baton->keepMetadata)
|
||||||
->set("tile_size", baton->tileSize)
|
->set("tile_size", baton->tileSize)
|
||||||
->set("overlap", baton->tileOverlap)
|
->set("overlap", baton->tileOverlap)
|
||||||
->set("container", baton->tileContainer)
|
->set("container", baton->tileContainer)
|
||||||
@@ -1442,6 +1539,14 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
|
|
||||||
// Input
|
// Input
|
||||||
baton->input = sharp::CreateInputDescriptor(options.Get("input").As<Napi::Object>());
|
baton->input = sharp::CreateInputDescriptor(options.Get("input").As<Napi::Object>());
|
||||||
|
// Join images together
|
||||||
|
if (sharp::HasAttr(options, "join")) {
|
||||||
|
Napi::Array join = options.Get("join").As<Napi::Array>();
|
||||||
|
for (unsigned int i = 0; i < join.Length(); i++) {
|
||||||
|
baton->join.push_back(
|
||||||
|
sharp::CreateInputDescriptor(join.Get(i).As<Napi::Object>()));
|
||||||
|
}
|
||||||
|
}
|
||||||
// Extract image options
|
// Extract image options
|
||||||
baton->topOffsetPre = sharp::AttrAsInt32(options, "topOffsetPre");
|
baton->topOffsetPre = sharp::AttrAsInt32(options, "topOffsetPre");
|
||||||
baton->leftOffsetPre = sharp::AttrAsInt32(options, "leftOffsetPre");
|
baton->leftOffsetPre = sharp::AttrAsInt32(options, "leftOffsetPre");
|
||||||
@@ -1504,6 +1609,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");
|
||||||
@@ -1519,20 +1626,21 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->thresholdGrayscale = sharp::AttrAsBool(options, "thresholdGrayscale");
|
baton->thresholdGrayscale = sharp::AttrAsBool(options, "thresholdGrayscale");
|
||||||
baton->trimBackground = sharp::AttrAsVectorOfDouble(options, "trimBackground");
|
baton->trimBackground = sharp::AttrAsVectorOfDouble(options, "trimBackground");
|
||||||
baton->trimThreshold = sharp::AttrAsDouble(options, "trimThreshold");
|
baton->trimThreshold = sharp::AttrAsDouble(options, "trimThreshold");
|
||||||
|
baton->trimLineArt = sharp::AttrAsBool(options, "trimLineArt");
|
||||||
baton->gamma = sharp::AttrAsDouble(options, "gamma");
|
baton->gamma = sharp::AttrAsDouble(options, "gamma");
|
||||||
baton->gammaOut = sharp::AttrAsDouble(options, "gammaOut");
|
baton->gammaOut = sharp::AttrAsDouble(options, "gammaOut");
|
||||||
baton->linearA = sharp::AttrAsVectorOfDouble(options, "linearA");
|
baton->linearA = sharp::AttrAsVectorOfDouble(options, "linearA");
|
||||||
baton->linearB = sharp::AttrAsVectorOfDouble(options, "linearB");
|
baton->linearB = sharp::AttrAsVectorOfDouble(options, "linearB");
|
||||||
|
baton->dilateWidth = sharp::AttrAsUint32(options, "dilateWidth");
|
||||||
|
baton->erodeWidth = sharp::AttrAsUint32(options, "erodeWidth");
|
||||||
baton->greyscale = sharp::AttrAsBool(options, "greyscale");
|
baton->greyscale = sharp::AttrAsBool(options, "greyscale");
|
||||||
baton->normalise = sharp::AttrAsBool(options, "normalise");
|
baton->normalise = sharp::AttrAsBool(options, "normalise");
|
||||||
baton->normaliseLower = sharp::AttrAsUint32(options, "normaliseLower");
|
baton->normaliseLower = sharp::AttrAsUint32(options, "normaliseLower");
|
||||||
baton->normaliseUpper = sharp::AttrAsUint32(options, "normaliseUpper");
|
baton->normaliseUpper = sharp::AttrAsUint32(options, "normaliseUpper");
|
||||||
baton->tintA = sharp::AttrAsDouble(options, "tintA");
|
baton->tint = sharp::AttrAsVectorOfDouble(options, "tint");
|
||||||
baton->tintB = sharp::AttrAsDouble(options, "tintB");
|
|
||||||
baton->claheWidth = sharp::AttrAsUint32(options, "claheWidth");
|
baton->claheWidth = sharp::AttrAsUint32(options, "claheWidth");
|
||||||
baton->claheHeight = sharp::AttrAsUint32(options, "claheHeight");
|
baton->claheHeight = sharp::AttrAsUint32(options, "claheHeight");
|
||||||
baton->claheMaxSlope = sharp::AttrAsUint32(options, "claheMaxSlope");
|
baton->claheMaxSlope = sharp::AttrAsUint32(options, "claheMaxSlope");
|
||||||
baton->useExifOrientation = sharp::AttrAsBool(options, "useExifOrientation");
|
|
||||||
baton->angle = sharp::AttrAsInt32(options, "angle");
|
baton->angle = sharp::AttrAsInt32(options, "angle");
|
||||||
baton->rotationAngle = sharp::AttrAsDouble(options, "rotationAngle");
|
baton->rotationAngle = sharp::AttrAsDouble(options, "rotationAngle");
|
||||||
baton->rotationBackground = sharp::AttrAsVectorOfDouble(options, "rotationBackground");
|
baton->rotationBackground = sharp::AttrAsVectorOfDouble(options, "rotationBackground");
|
||||||
@@ -1569,23 +1677,24 @@ 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->colourspaceInput = sharp::AttrAsEnum<VipsInterpretation>(
|
baton->colourspacePipeline = sharp::AttrAsEnum<VipsInterpretation>(
|
||||||
options, "colourspaceInput", VIPS_TYPE_INTERPRETATION);
|
options, "colourspacePipeline", VIPS_TYPE_INTERPRETATION);
|
||||||
if (baton->colourspaceInput == VIPS_INTERPRETATION_ERROR) {
|
if (baton->colourspacePipeline == VIPS_INTERPRETATION_ERROR) {
|
||||||
baton->colourspaceInput = VIPS_INTERPRETATION_LAST;
|
baton->colourspacePipeline = VIPS_INTERPRETATION_LAST;
|
||||||
}
|
}
|
||||||
baton->colourspace = sharp::AttrAsEnum<VipsInterpretation>(options, "colourspace", VIPS_TYPE_INTERPRETATION);
|
baton->colourspace = sharp::AttrAsEnum<VipsInterpretation>(options, "colourspace", VIPS_TYPE_INTERPRETATION);
|
||||||
if (baton->colourspace == VIPS_INTERPRETATION_ERROR) {
|
if (baton->colourspace == VIPS_INTERPRETATION_ERROR) {
|
||||||
@@ -1594,19 +1703,22 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
// Output
|
// Output
|
||||||
baton->formatOut = sharp::AttrAsStr(options, "formatOut");
|
baton->formatOut = sharp::AttrAsStr(options, "formatOut");
|
||||||
baton->fileOut = sharp::AttrAsStr(options, "fileOut");
|
baton->fileOut = sharp::AttrAsStr(options, "fileOut");
|
||||||
baton->withMetadata = sharp::AttrAsBool(options, "withMetadata");
|
baton->keepMetadata = sharp::AttrAsUint32(options, "keepMetadata");
|
||||||
baton->withMetadataOrientation = sharp::AttrAsUint32(options, "withMetadataOrientation");
|
baton->withMetadataOrientation = sharp::AttrAsUint32(options, "withMetadataOrientation");
|
||||||
baton->withMetadataDensity = sharp::AttrAsDouble(options, "withMetadataDensity");
|
baton->withMetadataDensity = sharp::AttrAsDouble(options, "withMetadataDensity");
|
||||||
baton->withMetadataIcc = sharp::AttrAsStr(options, "withMetadataIcc");
|
baton->withIccProfile = sharp::AttrAsStr(options, "withIccProfile");
|
||||||
Napi::Object mdStrs = options.Get("withMetadataStrs").As<Napi::Object>();
|
Napi::Object withExif = options.Get("withExif").As<Napi::Object>();
|
||||||
Napi::Array mdStrKeys = mdStrs.GetPropertyNames();
|
Napi::Array withExifKeys = withExif.GetPropertyNames();
|
||||||
for (unsigned int i = 0; i < mdStrKeys.Length(); i++) {
|
for (unsigned int i = 0; i < withExifKeys.Length(); i++) {
|
||||||
std::string k = sharp::AttrAsStr(mdStrKeys, i);
|
std::string k = sharp::AttrAsStr(withExifKeys, i);
|
||||||
if (mdStrs.HasOwnProperty(k)) {
|
if (withExif.HasOwnProperty(k)) {
|
||||||
baton->withMetadataStrs.insert(std::make_pair(k, sharp::AttrAsStr(mdStrs, k)));
|
baton->withExif.insert(std::make_pair(k, sharp::AttrAsStr(withExif, k)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
baton->withExifMerge = sharp::AttrAsBool(options, "withExifMerge");
|
||||||
baton->timeoutSeconds = sharp::AttrAsUint32(options, "timeoutSeconds");
|
baton->timeoutSeconds = sharp::AttrAsUint32(options, "timeoutSeconds");
|
||||||
|
baton->loop = sharp::AttrAsUint32(options, "loop");
|
||||||
|
baton->delay = sharp::AttrAsInt32Vector(options, "delay");
|
||||||
// Format-specific
|
// Format-specific
|
||||||
baton->jpegQuality = sharp::AttrAsUint32(options, "jpegQuality");
|
baton->jpegQuality = sharp::AttrAsUint32(options, "jpegQuality");
|
||||||
baton->jpegProgressive = sharp::AttrAsBool(options, "jpegProgressive");
|
baton->jpegProgressive = sharp::AttrAsBool(options, "jpegProgressive");
|
||||||
@@ -1634,6 +1746,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->webpLossless = sharp::AttrAsBool(options, "webpLossless");
|
baton->webpLossless = sharp::AttrAsBool(options, "webpLossless");
|
||||||
baton->webpNearLossless = sharp::AttrAsBool(options, "webpNearLossless");
|
baton->webpNearLossless = sharp::AttrAsBool(options, "webpNearLossless");
|
||||||
baton->webpSmartSubsample = sharp::AttrAsBool(options, "webpSmartSubsample");
|
baton->webpSmartSubsample = sharp::AttrAsBool(options, "webpSmartSubsample");
|
||||||
|
baton->webpSmartDeblock = sharp::AttrAsBool(options, "webpSmartDeblock");
|
||||||
baton->webpPreset = sharp::AttrAsEnum<VipsForeignWebpPreset>(options, "webpPreset", VIPS_TYPE_FOREIGN_WEBP_PRESET);
|
baton->webpPreset = sharp::AttrAsEnum<VipsForeignWebpPreset>(options, "webpPreset", VIPS_TYPE_FOREIGN_WEBP_PRESET);
|
||||||
baton->webpEffort = sharp::AttrAsUint32(options, "webpEffort");
|
baton->webpEffort = sharp::AttrAsUint32(options, "webpEffort");
|
||||||
baton->webpMinSize = sharp::AttrAsBool(options, "webpMinSize");
|
baton->webpMinSize = sharp::AttrAsBool(options, "webpMinSize");
|
||||||
@@ -1647,6 +1760,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->gifProgressive = sharp::AttrAsBool(options, "gifProgressive");
|
baton->gifProgressive = sharp::AttrAsBool(options, "gifProgressive");
|
||||||
baton->tiffQuality = sharp::AttrAsUint32(options, "tiffQuality");
|
baton->tiffQuality = sharp::AttrAsUint32(options, "tiffQuality");
|
||||||
baton->tiffPyramid = sharp::AttrAsBool(options, "tiffPyramid");
|
baton->tiffPyramid = sharp::AttrAsBool(options, "tiffPyramid");
|
||||||
|
baton->tiffMiniswhite = sharp::AttrAsBool(options, "tiffMiniswhite");
|
||||||
baton->tiffBitdepth = sharp::AttrAsUint32(options, "tiffBitdepth");
|
baton->tiffBitdepth = sharp::AttrAsUint32(options, "tiffBitdepth");
|
||||||
baton->tiffTile = sharp::AttrAsBool(options, "tiffTile");
|
baton->tiffTile = sharp::AttrAsBool(options, "tiffTile");
|
||||||
baton->tiffTileWidth = sharp::AttrAsUint32(options, "tiffTileWidth");
|
baton->tiffTileWidth = sharp::AttrAsUint32(options, "tiffTileWidth");
|
||||||
@@ -1668,18 +1782,12 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
options, "heifCompression", VIPS_TYPE_FOREIGN_HEIF_COMPRESSION);
|
options, "heifCompression", VIPS_TYPE_FOREIGN_HEIF_COMPRESSION);
|
||||||
baton->heifEffort = sharp::AttrAsUint32(options, "heifEffort");
|
baton->heifEffort = sharp::AttrAsUint32(options, "heifEffort");
|
||||||
baton->heifChromaSubsampling = sharp::AttrAsStr(options, "heifChromaSubsampling");
|
baton->heifChromaSubsampling = sharp::AttrAsStr(options, "heifChromaSubsampling");
|
||||||
|
baton->heifBitdepth = sharp::AttrAsUint32(options, "heifBitdepth");
|
||||||
baton->jxlDistance = sharp::AttrAsDouble(options, "jxlDistance");
|
baton->jxlDistance = sharp::AttrAsDouble(options, "jxlDistance");
|
||||||
baton->jxlDecodingTier = sharp::AttrAsUint32(options, "jxlDecodingTier");
|
baton->jxlDecodingTier = sharp::AttrAsUint32(options, "jxlDecodingTier");
|
||||||
baton->jxlEffort = sharp::AttrAsUint32(options, "jxlEffort");
|
baton->jxlEffort = sharp::AttrAsUint32(options, "jxlEffort");
|
||||||
baton->jxlLossless = sharp::AttrAsBool(options, "jxlLossless");
|
baton->jxlLossless = sharp::AttrAsBool(options, "jxlLossless");
|
||||||
baton->rawDepth = sharp::AttrAsEnum<VipsBandFormat>(options, "rawDepth", VIPS_TYPE_BAND_FORMAT);
|
baton->rawDepth = sharp::AttrAsEnum<VipsBandFormat>(options, "rawDepth", VIPS_TYPE_BAND_FORMAT);
|
||||||
// Animated output properties
|
|
||||||
if (sharp::HasAttr(options, "loop")) {
|
|
||||||
baton->loop = sharp::AttrAsUint32(options, "loop");
|
|
||||||
}
|
|
||||||
if (sharp::HasAttr(options, "delay")) {
|
|
||||||
baton->delay = sharp::AttrAsInt32Vector(options, "delay");
|
|
||||||
}
|
|
||||||
baton->tileSize = sharp::AttrAsUint32(options, "tileSize");
|
baton->tileSize = sharp::AttrAsUint32(options, "tileSize");
|
||||||
baton->tileOverlap = sharp::AttrAsUint32(options, "tileOverlap");
|
baton->tileOverlap = sharp::AttrAsUint32(options, "tileOverlap");
|
||||||
baton->tileAngle = sharp::AttrAsInt32(options, "tileAngle");
|
baton->tileAngle = sharp::AttrAsInt32(options, "tileAngle");
|
||||||
@@ -1708,7 +1816,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
|
|
||||||
// Increment queued task counter
|
// Increment queued task counter
|
||||||
Napi::Number queueLength = Napi::Number::New(info.Env(), static_cast<int>(++sharp::counterQueue));
|
Napi::Number queueLength = Napi::Number::New(info.Env(), static_cast<int>(++sharp::counterQueue));
|
||||||
queueListener.MakeCallback(info.This(), { queueLength });
|
queueListener.Call(info.This(), { queueLength });
|
||||||
|
|
||||||
return info.Env().Undefined();
|
return info.Env().Undefined();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,13 @@ struct Composite {
|
|||||||
|
|
||||||
struct PipelineBaton {
|
struct PipelineBaton {
|
||||||
sharp::InputDescriptor *input;
|
sharp::InputDescriptor *input;
|
||||||
|
std::vector<sharp::InputDescriptor *> join;
|
||||||
std::string formatOut;
|
std::string formatOut;
|
||||||
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;
|
||||||
@@ -69,14 +72,15 @@ struct PipelineBaton {
|
|||||||
bool premultiplied;
|
bool premultiplied;
|
||||||
bool tileCentre;
|
bool tileCentre;
|
||||||
bool fastShrinkOnLoad;
|
bool fastShrinkOnLoad;
|
||||||
double tintA;
|
std::vector<double> tint;
|
||||||
double tintB;
|
|
||||||
bool flatten;
|
bool flatten;
|
||||||
std::vector<double> flattenBackground;
|
std::vector<double> flattenBackground;
|
||||||
bool unflatten;
|
bool unflatten;
|
||||||
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;
|
||||||
@@ -92,10 +96,13 @@ struct PipelineBaton {
|
|||||||
bool thresholdGrayscale;
|
bool thresholdGrayscale;
|
||||||
std::vector<double> trimBackground;
|
std::vector<double> trimBackground;
|
||||||
double trimThreshold;
|
double trimThreshold;
|
||||||
|
bool trimLineArt;
|
||||||
int trimOffsetLeft;
|
int trimOffsetLeft;
|
||||||
int trimOffsetTop;
|
int trimOffsetTop;
|
||||||
std::vector<double> linearA;
|
std::vector<double> linearA;
|
||||||
std::vector<double> linearB;
|
std::vector<double> linearB;
|
||||||
|
int dilateWidth;
|
||||||
|
int erodeWidth;
|
||||||
double gamma;
|
double gamma;
|
||||||
double gammaOut;
|
double gammaOut;
|
||||||
bool greyscale;
|
bool greyscale;
|
||||||
@@ -105,7 +112,6 @@ struct PipelineBaton {
|
|||||||
int claheWidth;
|
int claheWidth;
|
||||||
int claheHeight;
|
int claheHeight;
|
||||||
int claheMaxSlope;
|
int claheMaxSlope;
|
||||||
bool useExifOrientation;
|
|
||||||
int angle;
|
int angle;
|
||||||
double rotationAngle;
|
double rotationAngle;
|
||||||
std::vector<double> rotationBackground;
|
std::vector<double> rotationBackground;
|
||||||
@@ -153,6 +159,7 @@ struct PipelineBaton {
|
|||||||
bool webpNearLossless;
|
bool webpNearLossless;
|
||||||
bool webpLossless;
|
bool webpLossless;
|
||||||
bool webpSmartSubsample;
|
bool webpSmartSubsample;
|
||||||
|
bool webpSmartDeblock;
|
||||||
VipsForeignWebpPreset webpPreset;
|
VipsForeignWebpPreset webpPreset;
|
||||||
int webpEffort;
|
int webpEffort;
|
||||||
bool webpMinSize;
|
bool webpMinSize;
|
||||||
@@ -169,6 +176,7 @@ struct PipelineBaton {
|
|||||||
VipsForeignTiffPredictor tiffPredictor;
|
VipsForeignTiffPredictor tiffPredictor;
|
||||||
bool tiffPyramid;
|
bool tiffPyramid;
|
||||||
int tiffBitdepth;
|
int tiffBitdepth;
|
||||||
|
bool tiffMiniswhite;
|
||||||
bool tiffTile;
|
bool tiffTile;
|
||||||
int tiffTileHeight;
|
int tiffTileHeight;
|
||||||
int tiffTileWidth;
|
int tiffTileWidth;
|
||||||
@@ -180,19 +188,21 @@ struct PipelineBaton {
|
|||||||
int heifEffort;
|
int heifEffort;
|
||||||
std::string heifChromaSubsampling;
|
std::string heifChromaSubsampling;
|
||||||
bool heifLossless;
|
bool heifLossless;
|
||||||
|
int heifBitdepth;
|
||||||
double jxlDistance;
|
double jxlDistance;
|
||||||
int jxlDecodingTier;
|
int jxlDecodingTier;
|
||||||
int jxlEffort;
|
int jxlEffort;
|
||||||
bool jxlLossless;
|
bool jxlLossless;
|
||||||
VipsBandFormat rawDepth;
|
VipsBandFormat rawDepth;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool withMetadata;
|
int keepMetadata;
|
||||||
int withMetadataOrientation;
|
int withMetadataOrientation;
|
||||||
double withMetadataDensity;
|
double withMetadataDensity;
|
||||||
std::string withMetadataIcc;
|
std::string withIccProfile;
|
||||||
std::unordered_map<std::string, std::string> withMetadataStrs;
|
std::unordered_map<std::string, std::string> withExif;
|
||||||
|
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;
|
||||||
@@ -203,7 +213,7 @@ struct PipelineBaton {
|
|||||||
int extractChannel;
|
int extractChannel;
|
||||||
bool removeAlpha;
|
bool removeAlpha;
|
||||||
double ensureAlpha;
|
double ensureAlpha;
|
||||||
VipsInterpretation colourspaceInput;
|
VipsInterpretation colourspacePipeline;
|
||||||
VipsInterpretation colourspace;
|
VipsInterpretation colourspace;
|
||||||
std::vector<int> delay;
|
std::vector<int> delay;
|
||||||
int loop;
|
int loop;
|
||||||
@@ -218,11 +228,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),
|
||||||
@@ -237,8 +249,7 @@ struct PipelineBaton {
|
|||||||
attentionX(0),
|
attentionX(0),
|
||||||
attentionY(0),
|
attentionY(0),
|
||||||
premultiplied(false),
|
premultiplied(false),
|
||||||
tintA(128.0),
|
tint{ -1.0, 0.0, 0.0, 0.0 },
|
||||||
tintB(128.0),
|
|
||||||
flatten(false),
|
flatten(false),
|
||||||
flattenBackground{ 0.0, 0.0, 0.0 },
|
flattenBackground{ 0.0, 0.0, 0.0 },
|
||||||
unflatten(false),
|
unflatten(false),
|
||||||
@@ -259,11 +270,14 @@ struct PipelineBaton {
|
|||||||
threshold(0),
|
threshold(0),
|
||||||
thresholdGrayscale(true),
|
thresholdGrayscale(true),
|
||||||
trimBackground{},
|
trimBackground{},
|
||||||
trimThreshold(0.0),
|
trimThreshold(-1.0),
|
||||||
|
trimLineArt(false),
|
||||||
trimOffsetLeft(0),
|
trimOffsetLeft(0),
|
||||||
trimOffsetTop(0),
|
trimOffsetTop(0),
|
||||||
linearA{},
|
linearA{},
|
||||||
linearB{},
|
linearB{},
|
||||||
|
dilateWidth(0),
|
||||||
|
erodeWidth(0),
|
||||||
gamma(0.0),
|
gamma(0.0),
|
||||||
greyscale(false),
|
greyscale(false),
|
||||||
normalise(false),
|
normalise(false),
|
||||||
@@ -272,7 +286,6 @@ struct PipelineBaton {
|
|||||||
claheWidth(0),
|
claheWidth(0),
|
||||||
claheHeight(0),
|
claheHeight(0),
|
||||||
claheMaxSlope(3),
|
claheMaxSlope(3),
|
||||||
useExifOrientation(false),
|
|
||||||
angle(0),
|
angle(0),
|
||||||
rotationAngle(0.0),
|
rotationAngle(0.0),
|
||||||
rotationBackground{ 0.0, 0.0, 0.0, 255.0 },
|
rotationBackground{ 0.0, 0.0, 0.0, 255.0 },
|
||||||
@@ -319,6 +332,7 @@ struct PipelineBaton {
|
|||||||
webpNearLossless(false),
|
webpNearLossless(false),
|
||||||
webpLossless(false),
|
webpLossless(false),
|
||||||
webpSmartSubsample(false),
|
webpSmartSubsample(false),
|
||||||
|
webpSmartDeblock(false),
|
||||||
webpPreset(VIPS_FOREIGN_WEBP_PRESET_DEFAULT),
|
webpPreset(VIPS_FOREIGN_WEBP_PRESET_DEFAULT),
|
||||||
webpEffort(4),
|
webpEffort(4),
|
||||||
webpMinSize(false),
|
webpMinSize(false),
|
||||||
@@ -335,6 +349,7 @@ struct PipelineBaton {
|
|||||||
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
||||||
tiffPyramid(false),
|
tiffPyramid(false),
|
||||||
tiffBitdepth(8),
|
tiffBitdepth(8),
|
||||||
|
tiffMiniswhite(false),
|
||||||
tiffTile(false),
|
tiffTile(false),
|
||||||
tiffTileHeight(256),
|
tiffTileHeight(256),
|
||||||
tiffTileWidth(256),
|
tiffTileWidth(256),
|
||||||
@@ -346,14 +361,16 @@ struct PipelineBaton {
|
|||||||
heifEffort(4),
|
heifEffort(4),
|
||||||
heifChromaSubsampling("4:4:4"),
|
heifChromaSubsampling("4:4:4"),
|
||||||
heifLossless(false),
|
heifLossless(false),
|
||||||
|
heifBitdepth(8),
|
||||||
jxlDistance(1.0),
|
jxlDistance(1.0),
|
||||||
jxlDecodingTier(0),
|
jxlDecodingTier(0),
|
||||||
jxlEffort(7),
|
jxlEffort(7),
|
||||||
jxlLossless(false),
|
jxlLossless(false),
|
||||||
rawDepth(VIPS_FORMAT_UCHAR),
|
rawDepth(VIPS_FORMAT_UCHAR),
|
||||||
withMetadata(false),
|
keepMetadata(0),
|
||||||
withMetadataOrientation(-1),
|
withMetadataOrientation(-1),
|
||||||
withMetadataDensity(0.0),
|
withMetadataDensity(0.0),
|
||||||
|
withExifMerge(true),
|
||||||
timeoutSeconds(0),
|
timeoutSeconds(0),
|
||||||
convKernelWidth(0),
|
convKernelWidth(0),
|
||||||
convKernelHeight(0),
|
convKernelHeight(0),
|
||||||
@@ -365,9 +382,9 @@ struct PipelineBaton {
|
|||||||
extractChannel(-1),
|
extractChannel(-1),
|
||||||
removeAlpha(false),
|
removeAlpha(false),
|
||||||
ensureAlpha(-1.0),
|
ensureAlpha(-1.0),
|
||||||
colourspaceInput(VIPS_INTERPRETATION_LAST),
|
colourspacePipeline(VIPS_INTERPRETATION_LAST),
|
||||||
colourspace(VIPS_INTERPRETATION_LAST),
|
colourspace(VIPS_INTERPRETATION_LAST),
|
||||||
loop(-1),
|
loop(1),
|
||||||
tileSize(256),
|
tileSize(256),
|
||||||
tileOverlap(0),
|
tileOverlap(0),
|
||||||
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
|
|||||||
exports.Set("block", Napi::Function::New(env, block));
|
exports.Set("block", Napi::Function::New(env, block));
|
||||||
exports.Set("_maxColourDistance", Napi::Function::New(env, _maxColourDistance));
|
exports.Set("_maxColourDistance", Napi::Function::New(env, _maxColourDistance));
|
||||||
exports.Set("_isUsingJemalloc", Napi::Function::New(env, _isUsingJemalloc));
|
exports.Set("_isUsingJemalloc", Napi::Function::New(env, _isUsingJemalloc));
|
||||||
|
exports.Set("_isUsingX64V2", Napi::Function::New(env, _isUsingX64V2));
|
||||||
exports.Set("stats", Napi::Function::New(env, stats));
|
exports.Set("stats", Napi::Function::New(env, stats));
|
||||||
return exports;
|
return exports;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
baton->channelStats.push_back(cStats);
|
baton->channelStats.push_back(cStats);
|
||||||
}
|
}
|
||||||
// Image is not opaque when alpha layer is present and contains a non-mamixa value
|
// Image is not opaque when alpha layer is present and contains a non-mamixa value
|
||||||
if (sharp::HasAlpha(image)) {
|
if (image.has_alpha()) {
|
||||||
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
||||||
if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) {
|
if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) {
|
||||||
baton->isOpaque = false;
|
baton->isOpaque = false;
|
||||||
@@ -106,7 +106,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
// Handle warnings
|
// Handle warnings
|
||||||
std::string warning = sharp::VipsWarningPop();
|
std::string warning = sharp::VipsWarningPop();
|
||||||
while (!warning.empty()) {
|
while (!warning.empty()) {
|
||||||
debuglog.MakeCallback(Receiver().Value(), { Napi::String::New(env, warning) });
|
debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,9 +141,9 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
dominant.Set("g", baton->dominantGreen);
|
dominant.Set("g", baton->dominantGreen);
|
||||||
dominant.Set("b", baton->dominantBlue);
|
dominant.Set("b", baton->dominantBlue);
|
||||||
info.Set("dominant", dominant);
|
info.Set("dominant", dominant);
|
||||||
Callback().MakeCallback(Receiver().Value(), { env.Null(), info });
|
Callback().Call(Receiver().Value(), { env.Null(), info });
|
||||||
} else {
|
} else {
|
||||||
Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
||||||
}
|
}
|
||||||
|
|
||||||
delete baton->input;
|
delete baton->input;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
@@ -91,9 +92,23 @@ Napi::Value simd(const Napi::CallbackInfo& info) {
|
|||||||
Get libvips version
|
Get libvips version
|
||||||
*/
|
*/
|
||||||
Napi::Value libvipsVersion(const Napi::CallbackInfo& info) {
|
Napi::Value libvipsVersion(const Napi::CallbackInfo& info) {
|
||||||
char version[9];
|
Napi::Env env = info.Env();
|
||||||
g_snprintf(version, sizeof(version), "%d.%d.%d", vips_version(0), vips_version(1), vips_version(2));
|
Napi::Object version = Napi::Object::New(env);
|
||||||
return Napi::String::New(info.Env(), version);
|
|
||||||
|
char semver[9];
|
||||||
|
std::snprintf(semver, sizeof(semver), "%d.%d.%d", vips_version(0), vips_version(1), vips_version(2));
|
||||||
|
version.Set("semver", Napi::String::New(env, semver));
|
||||||
|
#ifdef SHARP_USE_GLOBAL_LIBVIPS
|
||||||
|
version.Set("isGlobal", Napi::Boolean::New(env, true));
|
||||||
|
#else
|
||||||
|
version.Set("isGlobal", Napi::Boolean::New(env, false));
|
||||||
|
#endif
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
version.Set("isWasm", Napi::Boolean::New(env, true));
|
||||||
|
#else
|
||||||
|
version.Set("isWasm", Napi::Boolean::New(env, false));
|
||||||
|
#endif
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -104,7 +119,7 @@ Napi::Value format(const Napi::CallbackInfo& info) {
|
|||||||
Napi::Object format = Napi::Object::New(env);
|
Napi::Object format = Napi::Object::New(env);
|
||||||
for (std::string const f : {
|
for (std::string const f : {
|
||||||
"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
|
"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
|
||||||
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl"
|
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad"
|
||||||
}) {
|
}) {
|
||||||
// Input
|
// Input
|
||||||
const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());
|
const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());
|
||||||
@@ -218,10 +233,10 @@ Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {
|
|||||||
double maxColourDistance;
|
double maxColourDistance;
|
||||||
try {
|
try {
|
||||||
// Premultiply and remove alpha
|
// Premultiply and remove alpha
|
||||||
if (sharp::HasAlpha(image1)) {
|
if (image1.has_alpha()) {
|
||||||
image1 = image1.premultiply().extract_band(1, VImage::option()->set("n", image1.bands() - 1));
|
image1 = image1.premultiply().extract_band(1, VImage::option()->set("n", image1.bands() - 1));
|
||||||
}
|
}
|
||||||
if (sharp::HasAlpha(image2)) {
|
if (image2.has_alpha()) {
|
||||||
image2 = image2.premultiply().extract_band(1, VImage::option()->set("n", image2.bands() - 1));
|
image2 = image2.premultiply().extract_band(1, VImage::option()->set("n", image2.bands() - 1));
|
||||||
}
|
}
|
||||||
// Calculate colour distance
|
// Calculate colour distance
|
||||||
@@ -252,3 +267,20 @@ Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {
|
|||||||
return Napi::Boolean::New(env, false);
|
return Napi::Boolean::New(env, false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && defined(__x86_64__)
|
||||||
|
// Are SSE 4.2 intrinsics available at runtime?
|
||||||
|
Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {
|
||||||
|
Napi::Env env = info.Env();
|
||||||
|
unsigned int eax, ebx, ecx, edx;
|
||||||
|
__asm__ __volatile__("cpuid"
|
||||||
|
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
|
||||||
|
: "a"(1));
|
||||||
|
return Napi::Boolean::New(env, (ecx & 1U << 20) != 0);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info) {
|
||||||
|
Napi::Env env = info.Env();
|
||||||
|
return Napi::Boolean::New(env, false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ Napi::Value format(const Napi::CallbackInfo& info);
|
|||||||
void block(const Napi::CallbackInfo& info);
|
void block(const Napi::CallbackInfo& info);
|
||||||
Napi::Value _maxColourDistance(const Napi::CallbackInfo& info);
|
Napi::Value _maxColourDistance(const Napi::CallbackInfo& info);
|
||||||
Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info);
|
Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info);
|
||||||
|
Napi::Value _isUsingX64V2(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
#endif // SRC_UTILITIES_H_
|
#endif // SRC_UTILITIES_H_
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
FROM ubuntu:22.04
|
FROM ubuntu:24.10
|
||||||
ARG BRANCH=main
|
ARG BRANCH=main
|
||||||
|
|
||||||
# Install basic dependencies
|
# Install basic dependencies
|
||||||
RUN apt-get -y update && apt-get install -y build-essential curl git
|
RUN apt-get -y update && apt-get install -y build-essential curl git ca-certificates gnupg
|
||||||
|
|
||||||
# Install latest Node.js LTS
|
# Install latest Node.js LTS
|
||||||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
RUN curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
|
||||||
|
RUN bash nodesource_setup.sh
|
||||||
RUN apt-get install -y nodejs
|
RUN apt-get install -y nodejs
|
||||||
|
|
||||||
# Install benchmark dependencies
|
# Install benchmark dependencies
|
||||||
@@ -24,8 +25,4 @@ RUN node -v
|
|||||||
|
|
||||||
WORKDIR /tmp/sharp/test/bench
|
WORKDIR /tmp/sharp/test/bench
|
||||||
|
|
||||||
# Workaround for: https://github.com/emscripten-core/emscripten/pull/16917
|
|
||||||
# This could be removed once Squoosh is an optional dependency.
|
|
||||||
ENV NODE_OPTIONS="--no-experimental-fetch"
|
|
||||||
|
|
||||||
CMD [ "node", "perf" ]
|
CMD [ "node", "perf" ]
|
||||||
|
|||||||
@@ -8,16 +8,14 @@
|
|||||||
"test": "node perf && node random && node parallel"
|
"test": "node perf && node random && node parallel"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@squoosh/cli": "0.7.3",
|
"async": "3.2.6",
|
||||||
"@squoosh/lib": "0.5.3",
|
|
||||||
"async": "3.2.4",
|
|
||||||
"benchmark": "2.1.4",
|
"benchmark": "2.1.4",
|
||||||
"gm": "1.25.0",
|
"gm": "1.25.1",
|
||||||
"imagemagick": "0.1.3",
|
"imagemagick": "0.1.3",
|
||||||
"jimp": "0.22.10"
|
"jimp": "1.6.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@tensorflow/tfjs-node": "4.11.0",
|
"@tensorflow/tfjs-node": "4.22.0",
|
||||||
"mapnik": "4.5.9"
|
"mapnik": "4.5.9"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0"
|
"license": "Apache-2.0"
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const width = 720;
|
|||||||
const height = 480;
|
const height = 480;
|
||||||
|
|
||||||
sharp.concurrency(1);
|
sharp.concurrency(1);
|
||||||
sharp.simd(true);
|
|
||||||
|
|
||||||
const timer = setInterval(function () {
|
const timer = setInterval(function () {
|
||||||
console.dir(sharp.counters());
|
console.dir(sharp.counters());
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const os = require('os');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { exec, execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const Benchmark = require('benchmark');
|
const Benchmark = require('benchmark');
|
||||||
@@ -22,8 +21,8 @@ const sharp = require('../../');
|
|||||||
const gm = require('gm');
|
const gm = require('gm');
|
||||||
const imagemagick = require('imagemagick');
|
const imagemagick = require('imagemagick');
|
||||||
const mapnik = safeRequire('mapnik');
|
const mapnik = safeRequire('mapnik');
|
||||||
const jimp = require('jimp');
|
const { Jimp, JimpMime } = require('jimp');
|
||||||
const squoosh = require('@squoosh/lib');
|
|
||||||
process.env.TF_CPP_MIN_LOG_LEVEL = 1;
|
process.env.TF_CPP_MIN_LOG_LEVEL = 1;
|
||||||
const tfjs = safeRequire('@tensorflow/tfjs-node');
|
const tfjs = safeRequire('@tensorflow/tfjs-node');
|
||||||
|
|
||||||
@@ -52,102 +51,21 @@ async.series({
|
|||||||
// jimp
|
// jimp
|
||||||
jpegSuite.add('jimp-buffer-buffer', {
|
jpegSuite.add('jimp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: async function (deferred) {
|
||||||
jimp.read(inputJpgBuffer, function (err, image) {
|
const image = await Jimp.read(inputJpgBuffer);
|
||||||
if (err) {
|
await image
|
||||||
throw err;
|
.resize({ w: width, h: height, mode: Jimp.RESIZE_BICUBIC })
|
||||||
} else {
|
.getBuffer(JimpMime.jpeg, { quality: 80 });
|
||||||
image
|
deferred.resolve();
|
||||||
.resize(width, height, jimp.RESIZE_BICUBIC)
|
|
||||||
.quality(80)
|
|
||||||
.getBuffer(jimp.MIME_JPEG, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
} else {
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).add('jimp-file-file', {
|
}).add('jimp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: async function (deferred) {
|
||||||
jimp.read(fixtures.inputJpg, function (err, image) {
|
const image = await Jimp.read(fixtures.inputJpg);
|
||||||
if (err) {
|
await image
|
||||||
throw err;
|
.resize({ w: width, h: height, mode: Jimp.RESIZE_BICUBIC })
|
||||||
} else {
|
.getBuffer(JimpMime.jpeg, { quality: 80 });
|
||||||
image
|
deferred.resolve();
|
||||||
.resize(width, height, jimp.RESIZE_BICUBIC)
|
|
||||||
.quality(80)
|
|
||||||
.write(outputJpg, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
} else {
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// squoosh-cli
|
|
||||||
jpegSuite.add('squoosh-cli-file-file', {
|
|
||||||
defer: true,
|
|
||||||
fn: function (deferred) {
|
|
||||||
exec(`./node_modules/.bin/squoosh-cli \
|
|
||||||
--output-dir ${os.tmpdir()} \
|
|
||||||
--resize '{"enabled":true,"width":${width},"height":${height},"method":"lanczos3","premultiply":false,"linearRGB":false}' \
|
|
||||||
--mozjpeg '{"quality":80,"progressive":false,"optimize_coding":true,"quant_table":0,"trellis_multipass":false,"chroma_subsample":2,"separate_chroma_quality":false}' \
|
|
||||||
"${fixtures.inputJpg}"`, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
deferred.resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// squoosh-lib (GPLv3)
|
|
||||||
jpegSuite.add('squoosh-lib-buffer-buffer', {
|
|
||||||
defer: true,
|
|
||||||
fn: function (deferred) {
|
|
||||||
const pool = new squoosh.ImagePool(os.cpus().length);
|
|
||||||
const image = pool.ingestImage(inputJpgBuffer);
|
|
||||||
image.decoded
|
|
||||||
.then(function () {
|
|
||||||
return image.preprocess({
|
|
||||||
resize: {
|
|
||||||
enabled: true,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
method: 'lanczos3',
|
|
||||||
premultiply: false,
|
|
||||||
linearRGB: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return image.encode({
|
|
||||||
mozjpeg: {
|
|
||||||
quality: 80,
|
|
||||||
progressive: false,
|
|
||||||
optimize_coding: true,
|
|
||||||
quant_table: 0,
|
|
||||||
trellis_multipass: false,
|
|
||||||
chroma_subsample: 2,
|
|
||||||
separate_chroma_quality: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return pool.close();
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return image.encodedWith.mozjpeg;
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
deferred.resolve();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// mapnik
|
// mapnik
|
||||||
@@ -648,98 +566,21 @@ async.series({
|
|||||||
// jimp
|
// jimp
|
||||||
pngSuite.add('jimp-buffer-buffer', {
|
pngSuite.add('jimp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: async function (deferred) {
|
||||||
jimp.read(inputPngBuffer, function (err, image) {
|
const image = await Jimp.read(inputPngBuffer);
|
||||||
if (err) {
|
await image
|
||||||
throw err;
|
.resize({ w: width, h: heightPng, mode: Jimp.RESIZE_BICUBIC })
|
||||||
} else {
|
.getBuffer(JimpMime.png, { deflateLevel: 6, filterType: 0 });
|
||||||
image
|
deferred.resolve();
|
||||||
.resize(width, heightPng, jimp.RESIZE_BICUBIC)
|
|
||||||
.deflateLevel(6)
|
|
||||||
.filterType(0)
|
|
||||||
.getBuffer(jimp.MIME_PNG, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
} else {
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).add('jimp-file-file', {
|
}).add('jimp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: async function (deferred) {
|
||||||
jimp.read(fixtures.inputPngAlphaPremultiplicationLarge, function (err, image) {
|
const image = await Jimp.read(fixtures.inputPngAlphaPremultiplicationLarge);
|
||||||
if (err) {
|
await image
|
||||||
throw err;
|
.resize({ w: width, h: heightPng, mode: Jimp.RESIZE_BICUBIC })
|
||||||
} else {
|
.write(outputPng, { deflateLevel: 6, filterType: 0 });
|
||||||
image
|
deferred.resolve();
|
||||||
.resize(width, heightPng, jimp.RESIZE_BICUBIC)
|
|
||||||
.deflateLevel(6)
|
|
||||||
.filterType(0)
|
|
||||||
.write(outputPng, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
} else {
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// squoosh-cli
|
|
||||||
pngSuite.add('squoosh-cli-file-file', {
|
|
||||||
defer: true,
|
|
||||||
fn: function (deferred) {
|
|
||||||
exec(`./node_modules/.bin/squoosh-cli \
|
|
||||||
--output-dir ${os.tmpdir()} \
|
|
||||||
--resize '{"enabled":true,"width":${width},"height":${heightPng},"method":"lanczos3","premultiply":true,"linearRGB":false}' \
|
|
||||||
--oxipng '{"level":1}' \
|
|
||||||
"${fixtures.inputPngAlphaPremultiplicationLarge}"`, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
deferred.resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// squoosh-lib (GPLv3)
|
|
||||||
pngSuite.add('squoosh-lib-buffer-buffer', {
|
|
||||||
defer: true,
|
|
||||||
fn: function (deferred) {
|
|
||||||
const pool = new squoosh.ImagePool(os.cpus().length);
|
|
||||||
const image = pool.ingestImage(inputPngBuffer);
|
|
||||||
image.decoded
|
|
||||||
.then(function () {
|
|
||||||
return image.preprocess({
|
|
||||||
resize: {
|
|
||||||
enabled: true,
|
|
||||||
width,
|
|
||||||
height: heightPng,
|
|
||||||
method: 'lanczos3',
|
|
||||||
premultiply: true,
|
|
||||||
linearRGB: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return image.encode({
|
|
||||||
oxipng: {
|
|
||||||
level: 1
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return pool.close();
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
return image.encodedWith.oxipng;
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
deferred.resolve();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// mapnik
|
// mapnik
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ const sharp = require('../../');
|
|||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
sharp.simd(true);
|
|
||||||
|
|
||||||
const min = 320;
|
const min = 320;
|
||||||
const max = 960;
|
const max = 960;
|
||||||
|
|||||||
BIN
test/fixtures/XCMYK 2017.icc
vendored
Normal file
BIN
test/fixtures/bgbn4a08.png
vendored
Normal file
|
After Width: | Height: | Size: 140 B |