Compare commits
232 Commits
v0.26.0-al
...
v0.29.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
978a788f40 | ||
|
|
6e91d55971 | ||
|
|
d4ce0a1e36 | ||
|
|
148608b377 | ||
|
|
f725f4acb7 | ||
|
|
d07a549438 | ||
|
|
551441cedd | ||
|
|
46c14e939b | ||
|
|
6084647795 | ||
|
|
e0a598ae62 | ||
|
|
28833eb04a | ||
|
|
b24c9c86d1 | ||
|
|
b7add480c7 | ||
|
|
eabb671b10 | ||
|
|
513ed02b76 | ||
|
|
b7ddbe71f7 | ||
|
|
21d1a7ca62 | ||
|
|
4c2d28a7ad | ||
|
|
2afec9e3ed | ||
|
|
69790421b7 | ||
|
|
3f08f6a359 | ||
|
|
719c2db8da | ||
|
|
a9aa55c32d | ||
|
|
3f6d9d6ee9 | ||
|
|
b32568159f | ||
|
|
bb48d0d857 | ||
|
|
536412515f | ||
|
|
fcc6eaadd3 | ||
|
|
7dc78e8796 | ||
|
|
c65de3fe6d | ||
|
|
d000f57773 | ||
|
|
75cddbdb6d | ||
|
|
e418d91511 | ||
|
|
6c2e6c5432 | ||
|
|
8c6d9fdc62 | ||
|
|
468e95427e | ||
|
|
6d7a5ace6b | ||
|
|
cbaec198a5 | ||
|
|
7467fa8b50 | ||
|
|
61640fb5c7 | ||
|
|
19cb4b62b0 | ||
|
|
81ee8bc30f | ||
|
|
9f384e1c6c | ||
|
|
35e8c8b25e | ||
|
|
dc53f1baff | ||
|
|
70139600b5 | ||
|
|
1b4d1521e0 | ||
|
|
ed3377cb2d | ||
|
|
d72852b3aa | ||
|
|
4b6b6189bf | ||
|
|
b69a54fc75 | ||
|
|
81e388a4cc | ||
|
|
5bd5e5052a | ||
|
|
a2d3fa729f | ||
|
|
cb6811bc47 | ||
|
|
53c6e80869 | ||
|
|
e71dca586c | ||
|
|
b3cd48db5f | ||
|
|
476448b9d4 | ||
|
|
070534df5b | ||
|
|
9a1e8ed574 | ||
|
|
309918a878 | ||
|
|
cac83b94c1 | ||
|
|
9c06df08a1 | ||
|
|
52e4543d31 | ||
|
|
a688468378 | ||
|
|
e1760d64fb | ||
|
|
84d4e3cf8f | ||
|
|
f8a76372ad | ||
|
|
4237f5520f | ||
|
|
8c0c01c702 | ||
|
|
9c100830e0 | ||
|
|
ed5d753b89 | ||
|
|
d1ca756bd8 | ||
|
|
16cf9f0ef2 | ||
|
|
133f69d66c | ||
|
|
bc60daff9e | ||
|
|
43a085d1ae | ||
|
|
8c33d0aa56 | ||
|
|
fe0767df13 | ||
|
|
08a25a0c8f | ||
|
|
cd410080bd | ||
|
|
7555378e3b | ||
|
|
80c95ee66a | ||
|
|
31563b210d | ||
|
|
861cd93324 | ||
|
|
abb344bb1a | ||
|
|
6147491d9e | ||
|
|
f1f18fbb4a | ||
|
|
9fc611f257 | ||
|
|
34a2e14a14 | ||
|
|
83fe65b9e9 | ||
|
|
ec26c8aa49 | ||
|
|
da43a3055f | ||
|
|
a38126c82f | ||
|
|
cb592ce588 | ||
|
|
d69c58a6da | ||
|
|
bdb1986e08 | ||
|
|
55356c78a8 | ||
|
|
a0f55252b1 | ||
|
|
013f5cffa9 | ||
|
|
d5d008f568 | ||
|
|
3b02134cdc | ||
|
|
a57d7b51b1 | ||
|
|
1a3c38d35f | ||
|
|
00aece0538 | ||
|
|
5a9cc835b3 | ||
|
|
58526cc849 | ||
|
|
955b5f43a5 | ||
|
|
447aec3fde | ||
|
|
473260a836 | ||
|
|
4d2784c10c | ||
|
|
d9af897595 | ||
|
|
23a48be315 | ||
|
|
ce8f48e5d1 | ||
|
|
6aaf839662 | ||
|
|
984a9e653e | ||
|
|
8dffa28b4d | ||
|
|
b05a4bdadd | ||
|
|
36087fe518 | ||
|
|
5eed87ec4d | ||
|
|
af66a73225 | ||
|
|
dcf913c17e | ||
|
|
68ccba8f74 | ||
|
|
956f7e29db | ||
|
|
4264c0577e | ||
|
|
cc37b59309 | ||
|
|
9f2f92095d | ||
|
|
0c1075c089 | ||
|
|
9c64710c8b | ||
|
|
f6f16b91db | ||
|
|
1986b5cfe6 | ||
|
|
6445b72d41 | ||
|
|
df7b8ba738 | ||
|
|
202083999e | ||
|
|
315f519e1d | ||
|
|
d7d580ae6f | ||
|
|
7017af303d | ||
|
|
0dc325daa4 | ||
|
|
6dffb47973 | ||
|
|
b19dad69d6 | ||
|
|
94c5ac64e9 | ||
|
|
c4bcd088fb | ||
|
|
aeecbe9396 | ||
|
|
171aade9cd | ||
|
|
67213ae86c | ||
|
|
24d9e53c3f | ||
|
|
573ed5f4b5 | ||
|
|
ceff628add | ||
|
|
0bb8cb9203 | ||
|
|
98349bde28 | ||
|
|
f09be932eb | ||
|
|
4c57ac2bbe | ||
|
|
1dd93c1b6b | ||
|
|
c9f85fe27f | ||
|
|
419cbe50f6 | ||
|
|
5031c8323f | ||
|
|
762d5913ce | ||
|
|
290df1b1c7 | ||
|
|
79170afc51 | ||
|
|
bba00c2bfe | ||
|
|
f7e2b3688f | ||
|
|
8d49b7dde1 | ||
|
|
138e60adb3 | ||
|
|
d6376c31e0 | ||
|
|
a7003e93c8 | ||
|
|
4821a11223 | ||
|
|
bf1b326988 | ||
|
|
39ddb6a175 | ||
|
|
b2a0b8c0f0 | ||
|
|
4debc46d0e | ||
|
|
f4e259d10f | ||
|
|
774d78228e | ||
|
|
0e62bde5c3 | ||
|
|
2bbd9b23e6 | ||
|
|
02676140e8 | ||
|
|
182beaa4a1 | ||
|
|
7c08a09529 | ||
|
|
ef964b5472 | ||
|
|
ee54ce9913 | ||
|
|
e59e146887 | ||
|
|
103ec0d58f | ||
|
|
a0d89ed514 | ||
|
|
c10888e6fe | ||
|
|
93455f8eb5 | ||
|
|
65acd96c8d | ||
|
|
fabe720b9b | ||
|
|
53dd313e97 | ||
|
|
2678d7a660 | ||
|
|
46718102c6 | ||
|
|
0f473fe3b1 | ||
|
|
2872602c9e | ||
|
|
ab653cae33 | ||
|
|
e6a035e575 | ||
|
|
fbe48d75dd | ||
|
|
20ba0f49dd | ||
|
|
c213e9878d | ||
|
|
9704ca4c18 | ||
|
|
49dce6219e | ||
|
|
260ff6c94f | ||
|
|
3ec281d104 | ||
|
|
c4c43d525b | ||
|
|
6c5cde363a | ||
|
|
d46b4d950f | ||
|
|
b369c4bb8a | ||
|
|
c3898487c4 | ||
|
|
ca3c5b400f | ||
|
|
97772b176c | ||
|
|
08a2965f1c | ||
|
|
76dcddfa3d | ||
|
|
79f476ae4d | ||
|
|
d406cb619c | ||
|
|
4f3890f1e4 | ||
|
|
7a9d58cc51 | ||
|
|
eef87da0e1 | ||
|
|
00e65f6f14 | ||
|
|
866e9824d1 | ||
|
|
482e6078e2 | ||
|
|
bc7ab296ef | ||
|
|
a5f4f53b56 | ||
|
|
b1227f526d | ||
|
|
78b42c8306 | ||
|
|
4b6d45ab8e | ||
|
|
7980341923 | ||
|
|
3917efdebd | ||
|
|
eaecb7347b | ||
|
|
05ca7d3129 | ||
|
|
4beae0de71 | ||
|
|
b711661784 | ||
|
|
0c4a45b1f4 | ||
|
|
ec2beb0039 | ||
|
|
cafb3e8bac |
77
.circleci/config.yml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
version: 2.1
|
||||||
|
|
||||||
|
workflows:
|
||||||
|
build:
|
||||||
|
jobs:
|
||||||
|
- linux-arm64-glibc-node-12:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /^v.*/
|
||||||
|
- linux-arm64-musl-node-12:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /^v.*/
|
||||||
|
- linux-arm64-glibc-node-16:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /^v.*/
|
||||||
|
- linux-arm64-musl-node-16:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /^v.*/
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
linux-arm64-glibc-node-12:
|
||||||
|
resource_class: arm.medium
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202101-01
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: |
|
||||||
|
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
||||||
|
sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl"
|
||||||
|
sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
|
||||||
|
sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_12.x sid main' >/etc/apt/sources.list.d/nodesource.list"
|
||||||
|
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
|
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"npx prebuild --runtime napi --target 5 --upload=$prebuild_upload\" || true"
|
||||||
|
linux-arm64-glibc-node-16:
|
||||||
|
resource_class: arm.medium
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202101-01
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: |
|
||||||
|
sudo chown 0.0 ${PWD}
|
||||||
|
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
||||||
|
sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl"
|
||||||
|
sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
|
||||||
|
sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_16.x sid main' >/etc/apt/sources.list.d/nodesource.list"
|
||||||
|
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
|
linux-arm64-musl-node-12:
|
||||||
|
resource_class: arm.medium
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202101-01
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: |
|
||||||
|
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:12-alpine3.11
|
||||||
|
sudo docker exec sharp sh -c "apk add build-base git python3 --update-cache"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
|
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"npx prebuild --runtime napi --target 5 --upload=$prebuild_upload\" || true"
|
||||||
|
linux-arm64-musl-node-16:
|
||||||
|
resource_class: arm.medium
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202101-01
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: |
|
||||||
|
sudo chown 0.0 ${PWD}
|
||||||
|
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:16-alpine3.11
|
||||||
|
sudo docker exec sharp sh -c "apk add build-base git python3 --update-cache"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
|
||||||
|
- run: sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -2,13 +2,15 @@ freebsd_instance:
|
|||||||
image_family: freebsd-13-0-snap
|
image_family: freebsd-13-0-snap
|
||||||
|
|
||||||
task:
|
task:
|
||||||
|
name: FreeBSD 13.0
|
||||||
env:
|
env:
|
||||||
IGNORE_OSVERSION: yes
|
IGNORE_OSVERSION: yes
|
||||||
|
skip_notifications: true
|
||||||
prerequisites_script:
|
prerequisites_script:
|
||||||
- pkg update -f
|
- pkg update -f
|
||||||
- pkg upgrade -y
|
- pkg upgrade -y
|
||||||
- pkg install -y pkgconf vips node npm
|
- pkg install -y pkgconf vips node npm
|
||||||
install_script:
|
install_script:
|
||||||
- npm install --unsafe-perm
|
- npm install --build-from-source --unsafe-perm
|
||||||
test_script:
|
test_script:
|
||||||
- npm test
|
- npm test
|
||||||
|
|||||||
6
.github/CONTRIBUTING.md
vendored
@@ -27,7 +27,7 @@ Please select the `master` branch as the destination for your Pull Request so yo
|
|||||||
|
|
||||||
Please squash your changes into a single commit using a command like `git rebase -i upstream/master`.
|
Please squash your changes into a single commit using a command like `git rebase -i upstream/master`.
|
||||||
|
|
||||||
To test C++ changes, you can compile the module using `npm install` and then run the tests using `npm test`.
|
To test C++ changes, you can compile the module using `npm install --build-from-source` and then run the tests using `npm test`.
|
||||||
|
|
||||||
## Submit a Pull Request with a new feature
|
## Submit a Pull Request with a new feature
|
||||||
|
|
||||||
@@ -42,10 +42,6 @@ You deserve to add your details to the [list of contributors](https://github.com
|
|||||||
|
|
||||||
Any change that modifies the existing public API should be added to the relevant work-in-progress branch for inclusion in the next major release.
|
Any change that modifies the existing public API should be added to the relevant work-in-progress branch for inclusion in the next major release.
|
||||||
|
|
||||||
| Release | WIP branch |
|
|
||||||
| ------: | :--------- |
|
|
||||||
| v0.26.0 | zoom |
|
|
||||||
|
|
||||||
Please squash your changes into a single commit using a command like `git rebase -i upstream/<wip-branch>`.
|
Please squash your changes into a single commit using a command like `git rebase -i upstream/<wip-branch>`.
|
||||||
|
|
||||||
### Add a new public method
|
### Add a new public method
|
||||||
|
|||||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Documentation
|
||||||
|
url: https://sharp.pixelplumbing.com/
|
||||||
|
about: Installation instructions, complete API documentation with examples, changelog
|
||||||
6
.github/ISSUE_TEMPLATE/installation.md
vendored
@@ -7,11 +7,13 @@ labels: installation
|
|||||||
|
|
||||||
Did you see the [documentation relating to installation](https://sharp.pixelplumbing.com/install)?
|
Did you see the [documentation relating to installation](https://sharp.pixelplumbing.com/install)?
|
||||||
|
|
||||||
Have you ensured the platform and version of Node.js used for `npm install` is the same as the platform and version of Node.js used at runtime?
|
Have you ensured the architecture and platform of Node.js used for `npm install` is the same as the architecture and platform of Node.js used at runtime?
|
||||||
|
|
||||||
Are you using the latest version? Is the version currently in use as reported by `npm ls sharp` the same as the latest version as reported by `npm view sharp dist-tags.latest`?
|
Are you using the latest version? Is the version currently in use as reported by `npm ls sharp` the same as the latest version as reported by `npm view sharp dist-tags.latest`?
|
||||||
|
|
||||||
If you are installing as a `root` or `sudo` user, have you tried with the `npm install --unsafe-perm` flag?
|
If you are using npm v6 or earlier and installing as a `root` or `sudo` user, have you tried with the `npm install --unsafe-perm` flag?
|
||||||
|
|
||||||
|
If you are using npm v7, does the user running `npm install` own the directory it is run in?
|
||||||
|
|
||||||
If you are using the `ignore-scripts` feature of `npm`, have you tried with the `npm install --ignore-scripts=false` flag?
|
If you are using the `ignore-scripts` feature of `npm`, have you tried with the `npm install --ignore-scripts=false` flag?
|
||||||
|
|
||||||
|
|||||||
27
.github/workflows/ci-darwin-arm64v8.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
name: CI (MacStadium)
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
jobs:
|
||||||
|
CI:
|
||||||
|
runs-on: macos-m1
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: /usr/bin/arch -arch arm64e /bin/bash -l {0}
|
||||||
|
steps:
|
||||||
|
- name: Dependencies
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
architecture: arm64
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Install
|
||||||
|
run: npm install --build-from-source --unsafe-perm
|
||||||
|
- name: Test
|
||||||
|
run: npm test
|
||||||
|
- name: Prebuild
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
env:
|
||||||
|
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: npx prebuild --runtime napi --target 5
|
||||||
81
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
name: CI (GitHub)
|
||||||
|
on:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
jobs:
|
||||||
|
CI:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
container: ${{ matrix.container }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: centos:7
|
||||||
|
nodejs_version: 12
|
||||||
|
coverage: true
|
||||||
|
prebuild: true
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: centos:7
|
||||||
|
nodejs_version: 14
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: centos:7
|
||||||
|
nodejs_version: 16
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: node:12-alpine3.11
|
||||||
|
prebuild: true
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: node:14-alpine3.11
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: node:14-alpine3.13
|
||||||
|
- os: ubuntu-20.04
|
||||||
|
container: node:16-alpine3.11
|
||||||
|
- os: macos-10.15
|
||||||
|
nodejs_version: 12
|
||||||
|
prebuild: true
|
||||||
|
- os: macos-10.15
|
||||||
|
nodejs_version: 14
|
||||||
|
- os: macos-10.15
|
||||||
|
nodejs_version: 16
|
||||||
|
- os: windows-2019
|
||||||
|
nodejs_version: 12
|
||||||
|
prebuild: true
|
||||||
|
- os: windows-2019
|
||||||
|
nodejs_version: 14
|
||||||
|
- os: windows-2019
|
||||||
|
nodejs_version: 16
|
||||||
|
steps:
|
||||||
|
- name: Dependencies (Linux glibc)
|
||||||
|
if: contains(matrix.container, 'centos')
|
||||||
|
run: |
|
||||||
|
curl -sL https://rpm.nodesource.com/setup_${{ matrix.nodejs_version }}.x | bash -
|
||||||
|
yum install -y centos-release-scl
|
||||||
|
yum install -y devtoolset-10-gcc-c++ make git python3 nodejs
|
||||||
|
echo "/opt/rh/devtoolset-10/root/usr/bin" >> $GITHUB_PATH
|
||||||
|
- name: Dependencies (Linux musl)
|
||||||
|
if: contains(matrix.container, 'alpine')
|
||||||
|
run: apk add build-base git python3 --update-cache
|
||||||
|
- name: Dependencies (macOS, Windows)
|
||||||
|
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.nodejs_version }}
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Fix working directory ownership
|
||||||
|
if: matrix.container
|
||||||
|
run: chown root.root .
|
||||||
|
- name: Install
|
||||||
|
run: npm install --build-from-source --unsafe-perm
|
||||||
|
- name: Test
|
||||||
|
run: npm test
|
||||||
|
- name: Coverage
|
||||||
|
if: matrix.coverage
|
||||||
|
uses: coverallsapp/github-action@v1.1.2
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Prebuild
|
||||||
|
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
|
||||||
|
env:
|
||||||
|
prebuild_upload: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: npx prebuild --runtime napi --target 5
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"include-regex": "(sharp\\.node|libvips-cpp\\.dll)",
|
"include-regex": "(sharp-.+\\.node|libvips-cpp\\.dll)",
|
||||||
"strip": true
|
"strip": true
|
||||||
}
|
}
|
||||||
|
|||||||
139
.travis.yml
@@ -1,139 +0,0 @@
|
|||||||
jobs:
|
|
||||||
include:
|
|
||||||
- name: "Linux x64 (CentOS 7, glibc 2.17) - Node.js 10"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --env prebuild_upload --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
|
||||||
- sudo docker exec sharp bash -c "curl -sL https://rpm.nodesource.com/setup_10.x | bash -"
|
|
||||||
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
|
||||||
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp bash -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux x64 (CentOS 7, glibc 2.17) - Node.js 12"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
|
||||||
- sudo docker exec sharp bash -c "curl -sL https://rpm.nodesource.com/setup_12.x | bash -"
|
|
||||||
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
|
||||||
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp bash -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux x64 (CentOS 7, glibc 2.17) - Node.js 14"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
|
||||||
- sudo docker exec sharp bash -c "curl -sL https://rpm.nodesource.com/setup_14.x | bash -"
|
|
||||||
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
|
||||||
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp bash -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux x64 (Alpine 3.9, musl 1.1.20) - Node.js 10"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --env prebuild_upload --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:10.17.0-alpine3.9 # https://github.com/nodejs/docker-node/issues/1158
|
|
||||||
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux x64 (Alpine 3.11, musl 1.1.20) - Node.js 12"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:12.0-alpine
|
|
||||||
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux x64 (Alpine 3.11, musl 1.1.20) - Node.js 14"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:14.0-alpine
|
|
||||||
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux ARM64v8 (Debian 11, glibc 2.29) - Node.js 10"
|
|
||||||
arch: arm64
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --env prebuild_upload --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python2 curl"
|
|
||||||
- sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
|
|
||||||
- sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_10.x buster main' >/etc/apt/sources.list.d/nodesource.list"
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs=10.*"
|
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux ARM64v8 (Debian 11, glibc 2.29) - Node.js 12"
|
|
||||||
arch: arm64
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python2 curl"
|
|
||||||
- sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
|
|
||||||
- sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_12.x buster main' >/etc/apt/sources.list.d/nodesource.list"
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
|
||||||
|
|
||||||
- name: "Linux ARM64v8 (Debian 11, glibc 2.29) - Node.js 14"
|
|
||||||
arch: arm64
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python2 curl"
|
|
||||||
- sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
|
|
||||||
- sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_14.x buster main' >/etc/apt/sources.list.d/nodesource.list"
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
|
||||||
|
|
||||||
- name: "macOS (10.13) - Node.js 10"
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode10.1
|
|
||||||
language: node_js
|
|
||||||
node_js: "10"
|
|
||||||
|
|
||||||
- name: "macOS (10.13) - Node.js 12"
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode10.1
|
|
||||||
language: node_js
|
|
||||||
node_js: "12"
|
|
||||||
before_install: unset prebuild_upload
|
|
||||||
|
|
||||||
- name: "macOS (10.13) - Node.js 14"
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode10.1
|
|
||||||
language: node_js
|
|
||||||
node_js: "14"
|
|
||||||
before_install: unset prebuild_upload
|
|
||||||
|
|
||||||
- name: "Unit test coverage report"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: node_js
|
|
||||||
node_js: "13"
|
|
||||||
before_install: unset prebuild_upload
|
|
||||||
after_success:
|
|
||||||
- npm install coveralls
|
|
||||||
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
|
|
||||||
|
|
||||||
cache:
|
|
||||||
npm: false
|
|
||||||
33
README.md
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
The typical use case for this high speed Node.js module
|
The typical use case for this high speed Node.js module
|
||||||
is to convert large images in common formats to
|
is to convert large images in common formats to
|
||||||
smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
smaller, web-friendly JPEG, PNG, WebP and AVIF images of varying dimensions.
|
||||||
|
|
||||||
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
|
||||||
@@ -16,9 +16,17 @@ 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 v10.16.0+
|
Most modern macOS, Windows and Linux systems running Node.js >= 12.13.0
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Visit [sharp.pixelplumbing.com](https://sharp.pixelplumbing.com/) for complete
|
||||||
|
[installation instructions](https://sharp.pixelplumbing.com/install),
|
||||||
|
[API documentation](https://sharp.pixelplumbing.com/api-constructor),
|
||||||
|
[benchmark tests](https://sharp.pixelplumbing.com/performance) and
|
||||||
|
[changelog](https://sharp.pixelplumbing.com/changelog).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -43,6 +51,7 @@ sharp(inputBuffer)
|
|||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(200)
|
.resize(200)
|
||||||
|
.jpeg({ mozjpeg: true })
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then( data => { ... })
|
.then( data => { ... })
|
||||||
.catch( err => { ... });
|
.catch( err => { ... });
|
||||||
@@ -84,25 +93,17 @@ readableStream
|
|||||||
.pipe(writableStream);
|
.pipe(writableStream);
|
||||||
```
|
```
|
||||||
|
|
||||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
## Contributing
|
||||||
[](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix)
|
|
||||||
|
|
||||||
### Documentation
|
|
||||||
|
|
||||||
Visit [sharp.pixelplumbing.com](https://sharp.pixelplumbing.com/) for complete
|
|
||||||
[installation instructions](https://sharp.pixelplumbing.com/install),
|
|
||||||
[API documentation](https://sharp.pixelplumbing.com/api-constructor),
|
|
||||||
[benchmark tests](https://sharp.pixelplumbing.com/performance) and
|
|
||||||
[changelog](https://sharp.pixelplumbing.com/changelog).
|
|
||||||
|
|
||||||
### Contributing
|
|
||||||
|
|
||||||
A [guide for contributors](https://github.com/lovell/sharp/blob/master/.github/CONTRIBUTING.md)
|
A [guide for contributors](https://github.com/lovell/sharp/blob/master/.github/CONTRIBUTING.md)
|
||||||
covers reporting bugs, requesting features and submitting code changes.
|
covers reporting bugs, requesting features and submitting code changes.
|
||||||
|
|
||||||
### Licensing
|
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||||
|
[](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix)
|
||||||
|
|
||||||
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Lovell Fuller and contributors.
|
## Licensing
|
||||||
|
|
||||||
|
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Lovell Fuller and contributors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
25
appveyor.yml
@@ -1,26 +1,17 @@
|
|||||||
os: Visual Studio 2017
|
os: Visual Studio 2019
|
||||||
version: "{build}"
|
version: "{build}"
|
||||||
build: off
|
build: off
|
||||||
|
platform: x86
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- nodejs_version: "10"
|
|
||||||
platform: x86
|
|
||||||
- nodejs_version: "10"
|
|
||||||
platform: x64
|
|
||||||
- nodejs_version: "12"
|
- nodejs_version: "12"
|
||||||
platform: x86
|
prebuild: true
|
||||||
prebuild_upload: ""
|
|
||||||
- nodejs_version: "12"
|
|
||||||
platform: x64
|
|
||||||
prebuild_upload: ""
|
|
||||||
- nodejs_version: "14.2.0"
|
|
||||||
platform: x86
|
|
||||||
prebuild_upload: ""
|
|
||||||
- nodejs_version: "14"
|
- nodejs_version: "14"
|
||||||
platform: x64
|
- nodejs_version: "16"
|
||||||
prebuild_upload: ""
|
|
||||||
install:
|
install:
|
||||||
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform
|
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
|
||||||
- npm install
|
- npm install --build-from-source
|
||||||
test_script:
|
test_script:
|
||||||
- npm test
|
- npm test
|
||||||
|
on_success:
|
||||||
|
- if [%prebuild%] == [true] if [%APPVEYOR_REPO_TAG%] == [true] npx prebuild --runtime napi --target 5
|
||||||
|
|||||||
31
binding.gyp
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
'variables': {
|
'variables': {
|
||||||
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
|
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
|
||||||
'sharp_vendor_dir': '<(module_root_dir)/vendor/<(vips_version)'
|
'platform_and_arch': '<!(node -p "require(\'./lib/platform\')()")',
|
||||||
|
'sharp_vendor_dir': './vendor/<(vips_version)/<(platform_and_arch)'
|
||||||
},
|
},
|
||||||
'targets': [{
|
'targets': [{
|
||||||
'target_name': 'libvips-cpp',
|
'target_name': 'libvips-cpp',
|
||||||
@@ -37,6 +38,7 @@
|
|||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
'ExceptionHandling': 1,
|
'ExceptionHandling': 1,
|
||||||
|
'Optimization': 1,
|
||||||
'WholeProgramOptimization': 'true'
|
'WholeProgramOptimization': 'true'
|
||||||
},
|
},
|
||||||
'VCLibrarianTool': {
|
'VCLibrarianTool': {
|
||||||
@@ -65,9 +67,9 @@
|
|||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
'target_name': 'sharp',
|
'target_name': 'sharp-<(platform_and_arch)',
|
||||||
'defines': [
|
'defines': [
|
||||||
'NAPI_VERSION=3'
|
'NAPI_VERSION=5'
|
||||||
],
|
],
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'<!(node -p "require(\'node-addon-api\').gyp")',
|
'<!(node -p "require(\'node-addon-api\').gyp")',
|
||||||
@@ -95,7 +97,7 @@
|
|||||||
'src/sharp.cc'
|
'src/sharp.cc'
|
||||||
],
|
],
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'<!@(node -p "require(\'node-addon-api\').include")',
|
'<!(node -p "require(\'node-addon-api\').include_dir")',
|
||||||
],
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['use_global_libvips == "true"', {
|
['use_global_libvips == "true"', {
|
||||||
@@ -138,32 +140,30 @@
|
|||||||
}],
|
}],
|
||||||
['OS == "mac"', {
|
['OS == "mac"', {
|
||||||
'link_settings': {
|
'link_settings': {
|
||||||
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
'library_dirs': ['../<(sharp_vendor_dir)/lib'],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'libvips-cpp.42.dylib',
|
'libvips-cpp.42.dylib'
|
||||||
'libvips.42.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/../../vendor/<(vips_version)/lib\''
|
'-Wl,-rpath,\'@loader_path/../../<(sharp_vendor_dir)/lib\''
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
['OS == "linux"', {
|
['OS == "linux"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
'_GLIBCXX_USE_CXX11_ABI=0'
|
'_GLIBCXX_USE_CXX11_ABI=1'
|
||||||
],
|
],
|
||||||
'link_settings': {
|
'link_settings': {
|
||||||
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
'library_dirs': ['../<(sharp_vendor_dir)/lib'],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'-l:libvips-cpp.so.42',
|
'-l:libvips-cpp.so.42'
|
||||||
'-l:libvips.so.42'
|
|
||||||
],
|
],
|
||||||
'ldflags': [
|
'ldflags': [
|
||||||
# Ensure runtime linking is relative to sharp.node
|
# Ensure runtime linking is relative to sharp.node
|
||||||
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../vendor/<(vips_version)/lib\''
|
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../<(sharp_vendor_dir)/lib\''
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
@@ -174,7 +174,7 @@
|
|||||||
'-std=c++0x',
|
'-std=c++0x',
|
||||||
'-fexceptions',
|
'-fexceptions',
|
||||||
'-Wall',
|
'-Wall',
|
||||||
'-O3'
|
'-Os'
|
||||||
],
|
],
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
||||||
@@ -184,7 +184,7 @@
|
|||||||
'OTHER_CPLUSPLUSFLAGS': [
|
'OTHER_CPLUSPLUSFLAGS': [
|
||||||
'-fexceptions',
|
'-fexceptions',
|
||||||
'-Wall',
|
'-Wall',
|
||||||
'-O3'
|
'-Oz'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'configurations': {
|
'configurations': {
|
||||||
@@ -204,6 +204,7 @@
|
|||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
'ExceptionHandling': 1,
|
'ExceptionHandling': 1,
|
||||||
|
'Optimization': 1,
|
||||||
'WholeProgramOptimization': 'true'
|
'WholeProgramOptimization': 'true'
|
||||||
},
|
},
|
||||||
'VCLibrarianTool': {
|
'VCLibrarianTool': {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
The typical use case for this high speed Node.js module
|
The typical use case for this high speed Node.js module
|
||||||
is to convert large images in common formats to
|
is to convert large images in common formats to
|
||||||
smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
smaller, web-friendly JPEG, PNG, AVIF and WebP images of varying dimensions.
|
||||||
|
|
||||||
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
|
||||||
@@ -16,14 +16,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 v10.16.0+
|
Most modern macOS, Windows and Linux systems running Node.js >= 12.13.0
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
### Formats
|
### Formats
|
||||||
|
|
||||||
This module supports reading JPEG, PNG, WebP, TIFF, GIF and SVG images.
|
This module supports reading JPEG, PNG, WebP, AVIF, TIFF, GIF and SVG images.
|
||||||
|
|
||||||
Output images can be in JPEG, PNG, WebP and TIFF formats as well as uncompressed raw pixel data.
|
Output images can be in JPEG, PNG, WebP, AVIF and TIFF formats as well as uncompressed raw pixel data.
|
||||||
|
|
||||||
Streams, Buffer objects and the filesystem can be used for input and output.
|
Streams, Buffer objects and the filesystem can be used for input and output.
|
||||||
|
|
||||||
@@ -50,6 +50,10 @@ no child processes are spawned and Promises/async/await are supported.
|
|||||||
|
|
||||||
### Optimal
|
### Optimal
|
||||||
|
|
||||||
|
The features of `mozjpeg` and `pngquant` can be used
|
||||||
|
to optimise the file size of JPEG and PNG images respectively,
|
||||||
|
without having to invoke separate `imagemin` processes.
|
||||||
|
|
||||||
Huffman tables are optimised when generating JPEG output images
|
Huffman tables are optimised when generating JPEG output images
|
||||||
without having to use separate command line tools like
|
without having to use separate command line tools like
|
||||||
[jpegoptim](https://github.com/tjko/jpegoptim) and
|
[jpegoptim](https://github.com/tjko/jpegoptim) and
|
||||||
@@ -66,7 +70,7 @@ covers reporting bugs, requesting features and submitting code changes.
|
|||||||
|
|
||||||
### Licensing
|
### Licensing
|
||||||
|
|
||||||
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Lovell Fuller and contributors.
|
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Lovell Fuller and contributors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
|
|
||||||
|
See also [flatten][1].
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -18,23 +20,38 @@ Returns **Sharp**
|
|||||||
|
|
||||||
## ensureAlpha
|
## ensureAlpha
|
||||||
|
|
||||||
Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
|
Ensure the output image has an alpha transparency channel.
|
||||||
|
If missing, the added alpha channel will have the specified
|
||||||
|
transparency level, defaulting to fully-opaque (1).
|
||||||
|
This is a no-op if the image already has an alpha channel.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `alpha` **[number][2]** alpha transparency level (0=fully-transparent, 1=fully-opaque) (optional, default `1`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('rgb.jpg')
|
// rgba.png will be a 4 channel image with a fully-opaque alpha channel
|
||||||
|
await sharp('rgb.jpg')
|
||||||
.ensureAlpha()
|
.ensureAlpha()
|
||||||
.toFile('rgba.png', function(err, info) {
|
.toFile('rgba.png')
|
||||||
// rgba.png is a 4 channel image with a fully opaque alpha channel
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// rgba is a 4 channel image with a fully-transparent alpha channel
|
||||||
|
const rgba = await sharp(rgb)
|
||||||
|
.ensureAlpha(0)
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][3]** Invalid alpha transparency level
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
**Meta**
|
**Meta**
|
||||||
|
|
||||||
- **since**: 0.21.2
|
* **since**: 0.21.2
|
||||||
|
|
||||||
## extractChannel
|
## extractChannel
|
||||||
|
|
||||||
@@ -42,21 +59,26 @@ Extract a single channel from a multi-channel image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `channel` **([number][1] \| [string][2])** zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
* `channel` **([number][2] | [string][4])** zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
// green.jpg is a greyscale image containing the green channel of the input
|
||||||
|
await sharp(input)
|
||||||
.extractChannel('green')
|
.extractChannel('green')
|
||||||
.toColourspace('b-w')
|
.toFile('green.jpg');
|
||||||
.toFile('green.jpg', function(err, info) {
|
|
||||||
// info.channels === 1
|
|
||||||
// green.jpg is a greyscale image containing the green channel of the input
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid channel
|
```javascript
|
||||||
|
// red1 is the red value of the first pixel, red2 the second pixel etc.
|
||||||
|
const [red1, red2, ...] = await sharp(input)
|
||||||
|
.extractChannel(0)
|
||||||
|
.raw()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][3]** Invalid channel
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -67,19 +89,20 @@ The meaning of the added channels depends on the output colourspace, set with `t
|
|||||||
By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||||
Channel ordering follows vips convention:
|
Channel ordering follows vips convention:
|
||||||
|
|
||||||
- sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
* sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
||||||
- CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
* CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
||||||
|
|
||||||
Buffers may be any of the image formats supported by sharp: JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data.
|
Buffers may be any of the image formats supported by sharp.
|
||||||
For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `images` **([Array][4]<([string][2] \| [Buffer][5])> | [string][2] \| [Buffer][5])** one or more images (file paths, Buffers).
|
* `images` **([Array][5]<([string][4] | [Buffer][6])> | [string][4] | [Buffer][6])** one or more images (file paths, Buffers).
|
||||||
- `options` **[Object][6]** image options, see `sharp()` constructor.
|
* `options` **[Object][7]** image options, see `sharp()` constructor.
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid parameters
|
* Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -89,7 +112,7 @@ Perform a bitwise boolean operation on all input image channels (bands) to produ
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `boolOp` **[string][2]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
* `boolOp` **[string][4]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -103,18 +126,20 @@ sharp('3-channel-rgb-input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid parameters
|
* Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[1]: /api-operation#flatten
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[5]: https://nodejs.org/api/buffer.html
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[6]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ An alpha channel may be present and will be unchanged by the operation.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `rgb` **([string][1] \| [Object][2])** parsed by the [color][3] module to extract chroma values.
|
* `rgb` **([string][1] | [Object][2])** parsed by the [color][3] module to extract chroma values.
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid parameter
|
* Throws **[Error][4]** Invalid parameter
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ An alpha channel may be present, and will be unchanged by the operation.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `greyscale` **[Boolean][5]** (optional, default `true`)
|
* `greyscale` **[Boolean][5]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -35,7 +36,52 @@ Alternative spelling of `greyscale`.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `grayscale` **[Boolean][5]** (optional, default `true`)
|
* `grayscale` **[Boolean][5]** (optional, default `true`)
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## pipelineColourspace
|
||||||
|
|
||||||
|
Set the pipeline colourspace.
|
||||||
|
|
||||||
|
The input image will be converted to the provided colourspace at the start of the pipeline.
|
||||||
|
All operations will use this colourspace before converting to the output colourspace, as defined by [toColourspace][6].
|
||||||
|
|
||||||
|
This feature is experimental and has not yet been fully-tested with all operations.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `colourspace` **[string][1]?** pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...][7]
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
|
||||||
|
await sharp(input)
|
||||||
|
.pipelineColourspace('rgb16')
|
||||||
|
.toColourspace('srgb')
|
||||||
|
.toFile('16bpc-pipeline-to-8bpc-output.png')
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
**Meta**
|
||||||
|
|
||||||
|
* **since**: 0.29.0
|
||||||
|
|
||||||
|
## pipelineColorspace
|
||||||
|
|
||||||
|
Alternative spelling of `pipelineColourspace`.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `colorspace` **[string][1]?** pipeline colorspace.
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -46,10 +92,18 @@ By default output image will be web-friendly sRGB, with additional channels inte
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `colourspace` **[string][1]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][6]
|
* `colourspace` **[string][1]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][8]
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid parameters
|
```javascript
|
||||||
|
// Output 16 bits per pixel RGB
|
||||||
|
await sharp(input)
|
||||||
|
.toColourspace('rgb16')
|
||||||
|
.toFile('16-bpp.png')
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -59,10 +113,11 @@ Alternative spelling of `toColourspace`.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `colorspace` **[string][1]?** output colorspace.
|
* `colorspace` **[string][1]?** output colorspace.
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid parameters
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -76,4 +131,8 @@ Returns **Sharp**
|
|||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[6]: https://github.com/libvips/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568
|
[6]: #tocolourspace
|
||||||
|
|
||||||
|
[7]: https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774
|
||||||
|
|
||||||
|
[8]: https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794
|
||||||
|
|||||||
@@ -19,24 +19,30 @@ and [https://www.cairographics.org/operators/][2]
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `images` **[Array][3]<[Object][4]>** Ordered list of images to composite
|
* `images` **[Array][3]<[Object][4]>** Ordered list of images to composite
|
||||||
- `images[].input` **([Buffer][5] \| [String][6])?** Buffer containing image data, String containing the path to an image file, or Create object (see below)
|
|
||||||
- `images[].input.create` **[Object][4]?** describes a blank overlay to be created.
|
* `images[].input` **([Buffer][5] | [String][6])?** Buffer containing image data, String containing the path to an image file, or Create object (see below)
|
||||||
- `images[].input.create.width` **[Number][7]?**
|
|
||||||
- `images[].input.create.height` **[Number][7]?**
|
* `images[].input.create` **[Object][4]?** describes a blank overlay to be created.
|
||||||
- `images[].input.create.channels` **[Number][7]?** 3-4
|
|
||||||
- `images[].input.create.background` **([String][6] \| [Object][4])?** parsed by the [color][8] module to extract values for red, green, blue and alpha.
|
* `images[].input.create.width` **[Number][7]?**
|
||||||
- `images[].blend` **[String][6]** how to blend this image with the image below. (optional, default `'over'`)
|
* `images[].input.create.height` **[Number][7]?**
|
||||||
- `images[].gravity` **[String][6]** gravity at which to place the overlay. (optional, default `'centre'`)
|
* `images[].input.create.channels` **[Number][7]?** 3-4
|
||||||
- `images[].top` **[Number][7]?** the pixel offset from the top edge.
|
* `images[].input.create.background` **([String][6] | [Object][4])?** parsed by the [color][8] module to extract values for red, green, blue and alpha.
|
||||||
- `images[].left` **[Number][7]?** the pixel offset from the left edge.
|
* `images[].blend` **[String][6]** how to blend this image with the image below. (optional, default `'over'`)
|
||||||
- `images[].tile` **[Boolean][9]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
* `images[].gravity` **[String][6]** gravity at which to place the overlay. (optional, default `'centre'`)
|
||||||
- `images[].premultiplied` **[Boolean][9]** set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option. (optional, default `false`)
|
* `images[].top` **[Number][7]?** the pixel offset from the top edge.
|
||||||
- `images[].density` **[Number][7]** number representing the DPI for vector overlay image. (optional, default `72`)
|
* `images[].left` **[Number][7]?** the pixel offset from the left edge.
|
||||||
- `images[].raw` **[Object][4]?** describes overlay when using raw pixel data.
|
* `images[].tile` **[Boolean][9]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
||||||
- `images[].raw.width` **[Number][7]?**
|
* `images[].premultiplied` **[Boolean][9]** set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option. (optional, default `false`)
|
||||||
- `images[].raw.height` **[Number][7]?**
|
* `images[].density` **[Number][7]** number representing the DPI for vector overlay image. (optional, default `72`)
|
||||||
- `images[].raw.channels` **[Number][7]?**
|
* `images[].raw` **[Object][4]?** describes overlay when using raw pixel data.
|
||||||
|
|
||||||
|
* `images[].raw.width` **[Number][7]?**
|
||||||
|
* `images[].raw.height` **[Number][7]?**
|
||||||
|
* `images[].raw.channels` **[Number][7]?**
|
||||||
|
* `images[].failOnError` **[boolean][9]** @see [constructor parameters][10] (optional, default `true`)
|
||||||
|
* `images[].limitInputPixels` **([number][7] | [boolean][9])** @see [constructor parameters][10] (optional, default `268402689`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -57,13 +63,13 @@ sharp('input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][10]** Invalid parameters
|
* Throws **[Error][11]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
**Meta**
|
**Meta**
|
||||||
|
|
||||||
- **since**: 0.22.0
|
* **since**: 0.22.0
|
||||||
|
|
||||||
[1]: https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsBlendMode
|
[1]: https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsBlendMode
|
||||||
|
|
||||||
@@ -83,4 +89,6 @@ Returns **Sharp**
|
|||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[10]: /api-constructor#parameters
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
||||||
|
|
||||||
JPEG, PNG, WebP or TIFF format image data can be streamed out from this object.
|
JPEG, PNG, WebP, AVIF or TIFF format image data can be streamed out from this object.
|
||||||
When using Stream based output, derived attributes are available from the `info` event.
|
When using Stream based output, derived attributes are available from the `info` event.
|
||||||
|
|
||||||
Non-critical problems encountered during processing are emitted as `warning` events.
|
Non-critical problems encountered during processing are emitted as `warning` events.
|
||||||
@@ -13,31 +13,44 @@ Implements the [stream.Duplex][1] class.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `input` **([Buffer][2] \| [string][3])?** if present, can be
|
* `input` **([Buffer][2] | [Uint8Array][3] | [Uint8ClampedArray][4] | [Int8Array][5] | [Uint16Array][6] | [Int16Array][7] | [Uint32Array][8] | [Int32Array][9] | [Float32Array][10] | [Float64Array][11] | [string][12])?** if present, can be
|
||||||
a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
a Buffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
|
||||||
a String containing the filesystem path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
a TypedArray containing raw pixel image data, or
|
||||||
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
|
||||||
- `options` **[Object][4]?** if present, is an Object with optional attributes.
|
JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||||
- `options.failOnError` **[boolean][5]** by default halt processing and raise an error when loading invalid images.
|
* `options` **[Object][13]?** if present, is an Object with optional attributes.
|
||||||
Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid. (optional, default `true`)
|
|
||||||
- `options.limitInputPixels` **([number][6] \| [boolean][5])** Do not process input images where the number of pixels
|
* `options.failOnError` **[boolean][14]** by default halt processing and raise an error when loading invalid images.
|
||||||
(width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid. (optional, default `true`)
|
||||||
An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default `268402689`)
|
* `options.limitInputPixels` **([number][15] | [boolean][14])** Do not process input images where the number of pixels
|
||||||
- `options.sequentialRead` **[boolean][5]** Set this to `true` to use sequential rather than random access where possible.
|
(width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
||||||
This can reduce memory usage and might improve performance on some systems. (optional, default `false`)
|
An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default `268402689`)
|
||||||
- `options.density` **[number][6]** number representing the DPI for vector images. (optional, default `72`)
|
* `options.sequentialRead` **[boolean][14]** Set this to `true` to use sequential rather than random access where possible.
|
||||||
- `options.pages` **[number][6]** number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages. (optional, default `1`)
|
This can reduce memory usage and might improve performance on some systems. (optional, default `false`)
|
||||||
- `options.page` **[number][6]** page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default `0`)
|
* `options.density` **[number][15]** number representing the DPI for vector images in the range 1 to 100000. (optional, default `72`)
|
||||||
- `options.level` **[number][6]** level to extract from a multi-level input (OpenSlide), zero based. (optional, default `0`)
|
* `options.pages` **[number][15]** number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages. (optional, default `1`)
|
||||||
- `options.raw` **[Object][4]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
* `options.page` **[number][15]** page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based. (optional, default `0`)
|
||||||
- `options.raw.width` **[number][6]?**
|
* `options.subifd` **[number][15]** subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. (optional, default `-1`)
|
||||||
- `options.raw.height` **[number][6]?**
|
* `options.level` **[number][15]** level to extract from a multi-level input (OpenSlide), zero based. (optional, default `0`)
|
||||||
- `options.raw.channels` **[number][6]?** 1-4
|
* `options.animated` **[boolean][14]** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default `false`)
|
||||||
- `options.create` **[Object][4]?** describes a new image to be created.
|
* `options.raw` **[Object][13]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
- `options.create.width` **[number][6]?**
|
|
||||||
- `options.create.height` **[number][6]?**
|
* `options.raw.width` **[number][15]?** integral number of pixels wide.
|
||||||
- `options.create.channels` **[number][6]?** 3-4
|
* `options.raw.height` **[number][15]?** integral number of pixels high.
|
||||||
- `options.create.background` **([string][3] \| [Object][4])?** parsed by the [color][7] module to extract values for red, green, blue and alpha.
|
* `options.raw.channels` **[number][15]?** integral number of channels, between 1 and 4.
|
||||||
|
* `options.raw.premultiplied` **[boolean][14]?** specifies that the raw input has already been premultiplied, set to `true`
|
||||||
|
to avoid sharp premultiplying the image. (optional, default `false`)
|
||||||
|
* `options.create` **[Object][13]?** describes a new image to be created.
|
||||||
|
|
||||||
|
* `options.create.width` **[number][15]?** integral number of pixels wide.
|
||||||
|
* `options.create.height` **[number][15]?** integral number of pixels high.
|
||||||
|
* `options.create.channels` **[number][15]?** integral number of channels, either 3 (RGB) or 4 (RGBA).
|
||||||
|
* `options.create.background` **([string][12] | [Object][13])?** parsed by the [color][16] module to extract values for red, green, blue and alpha.
|
||||||
|
* `options.create.noise` **[Object][13]?** describes a noise to be created.
|
||||||
|
|
||||||
|
* `options.create.noise.type` **[string][12]?** type of generated noise, currently only `gaussian` is supported.
|
||||||
|
* `options.create.noise.mean` **[number][15]?** mean of pixels in generated noise.
|
||||||
|
* `options.create.noise.sigma` **[number][15]?** standard deviation of pixels in generated noise.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -78,9 +91,45 @@ sharp({
|
|||||||
.then( ... );
|
.then( ... );
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][8]** Invalid parameters
|
```javascript
|
||||||
|
// Convert an animated GIF to an animated WebP
|
||||||
|
await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||||
|
```
|
||||||
|
|
||||||
Returns **[Sharp][9]**
|
```javascript
|
||||||
|
// Read a raw array of pixels and save it to a png
|
||||||
|
const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
|
||||||
|
const image = sharp(input, {
|
||||||
|
// because the input does not contain its dimensions or how many channels it has
|
||||||
|
// we need to specify it in the constructor options
|
||||||
|
raw: {
|
||||||
|
width: 2,
|
||||||
|
height: 1,
|
||||||
|
channels: 3
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await image.toFile('my-two-pixels.png');
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Generate RGB Gaussian noise
|
||||||
|
await sharp({
|
||||||
|
create: {
|
||||||
|
width: 300,
|
||||||
|
height: 200,
|
||||||
|
channels: 3,
|
||||||
|
noise: {
|
||||||
|
type: 'gaussian',
|
||||||
|
mean: 128,
|
||||||
|
sigma: 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).toFile('noise.png');
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][17]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **[Sharp][18]**
|
||||||
|
|
||||||
## clone
|
## clone
|
||||||
|
|
||||||
@@ -148,22 +197,40 @@ Promise.all(promises)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Sharp][9]**
|
Returns **[Sharp][18]**
|
||||||
|
|
||||||
[1]: http://nodejs.org/api/stream.html#stream_class_stream_duplex
|
[1]: http://nodejs.org/api/stream.html#stream_class_stream_duplex
|
||||||
|
|
||||||
[2]: https://nodejs.org/api/buffer.html
|
[2]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
|
||||||
|
|
||||||
[7]: https://www.npmjs.org/package/color
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
|
||||||
|
|
||||||
[9]: #sharp
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
|
||||||
|
|
||||||
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
|
||||||
|
|
||||||
|
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[16]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
|
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[18]: #sharp
|
||||||
|
|||||||
@@ -5,34 +5,37 @@
|
|||||||
Fast access to (uncached) image metadata without decoding any compressed image data.
|
Fast access to (uncached) image metadata without decoding any compressed image data.
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
* `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||||
- `size`: Total size of image in bytes, for Stream and Buffer input only
|
* `size`: Total size of image in bytes, for Stream and Buffer input only
|
||||||
- `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
|
* `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
|
||||||
- `height`: Number of pixels high (EXIF orientation is not taken into consideration)
|
* `height`: Number of pixels high (EXIF orientation is not taken into consideration)
|
||||||
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][1]
|
* `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][1]
|
||||||
- `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
* `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||||
- `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][2]
|
* `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][2]
|
||||||
- `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
|
||||||
- `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.
|
||||||
- `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
|
||||||
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
* `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||||
- `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
* `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||||
- `orientation`: Number value of the EXIF Orientation header, if present
|
* `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||||
- `exif`: Buffer containing raw EXIF data, if present
|
* `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
- `icc`: Buffer containing raw [ICC][3] profile data, if present
|
* `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
||||||
- `iptc`: Buffer containing raw IPTC data, if present
|
* `orientation`: Number value of the EXIF Orientation header, if present
|
||||||
- `xmp`: Buffer containing raw XMP data, if present
|
* `exif`: Buffer containing raw EXIF data, if present
|
||||||
- `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
* `icc`: Buffer containing raw [ICC][3] profile data, if present
|
||||||
|
* `iptc`: Buffer containing raw IPTC data, if present
|
||||||
|
* `xmp`: Buffer containing raw XMP data, if present
|
||||||
|
* `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `callback` **[Function][4]?** called with the arguments `(err, metadata)`
|
* `callback` **[Function][4]?** called with the arguments `(err, metadata)`
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -51,32 +54,35 @@ image
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **([Promise][5]<[Object][6]> | Sharp)**
|
Returns **([Promise][5]<[Object][6]> | Sharp)**
|
||||||
|
|
||||||
## stats
|
## stats
|
||||||
|
|
||||||
Access to pixel-derived image statistics for every channel in the image.
|
Access to pixel-derived image statistics for every channel in the image.
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
* `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||||
- `min` (minimum value in the channel)
|
* `min` (minimum value in the channel)
|
||||||
- `max` (maximum value in the channel)
|
* `max` (maximum value in the channel)
|
||||||
- `sum` (sum of all values in a channel)
|
* `sum` (sum of all values in a channel)
|
||||||
- `squaresSum` (sum of squared values in a channel)
|
* `squaresSum` (sum of squared values in a channel)
|
||||||
- `mean` (mean of the values in a channel)
|
* `mean` (mean of the values in a channel)
|
||||||
- `stdev` (standard deviation for the values in a channel)
|
* `stdev` (standard deviation for the values in a channel)
|
||||||
- `minX` (x-coordinate of one of the pixel where the minimum lies)
|
* `minX` (x-coordinate of one of the pixel where the minimum lies)
|
||||||
- `minY` (y-coordinate of one of the pixel where the minimum lies)
|
* `minY` (y-coordinate of one of the pixel where the minimum lies)
|
||||||
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
* `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||||
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
* `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||||
- `isOpaque`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
|
* `isOpaque`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
|
||||||
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)
|
* `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)
|
||||||
- `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental)
|
* `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental)
|
||||||
- `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
* `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
||||||
|
|
||||||
|
**Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
||||||
|
written to a buffer in order to run `stats` on the result (see third example).
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `callback` **[Function][4]?** called with the arguments `(err, stats)`
|
* `callback` **[Function][4]?** called with the arguments `(err, stats)`
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -94,7 +100,15 @@ const { entropy, sharpness, dominant } = await sharp(input).stats();
|
|||||||
const { r, g, b } = dominant;
|
const { r, g, b } = dominant;
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][5]<[Object][6]>**
|
```javascript
|
||||||
|
const image = sharp(input);
|
||||||
|
// store intermediate result
|
||||||
|
const part = await image.extract(region).toBuffer();
|
||||||
|
// create new instance to obtain statistics of extracted region
|
||||||
|
const stats = await sharp(part).stats();
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **[Promise][5]<[Object][6]>**
|
||||||
|
|
||||||
[1]: https://libvips.github.io/libvips/API/current/VipsImage.html#VipsInterpretation
|
[1]: https://libvips.github.io/libvips/API/current/VipsImage.html#VipsInterpretation
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ for example `rotate(x).extract(y)` will produce a different result to `extract(y
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `angle` **[number][1]** angle of rotation. (optional, default `auto`)
|
* `angle` **[number][1]** angle of rotation. (optional, default `auto`)
|
||||||
- `options` **[Object][2]?** if present, is an Object with optional attributes.
|
* `options` **[Object][2]?** if present, is an Object with optional attributes.
|
||||||
- `options.background` **([string][3] \| [Object][2])** parsed by the [color][4] module to extract values for red, green, blue and alpha. (optional, default `"#000000"`)
|
|
||||||
|
* `options.background` **([string][3] | [Object][2])** parsed by the [color][4] module to extract values for red, green, blue and alpha. (optional, default `"#000000"`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ const pipeline = sharp()
|
|||||||
readableStream.pipe(pipeline);
|
readableStream.pipe(pipeline);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `flip` **[Boolean][6]** (optional, default `true`)
|
* `flip` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -61,10 +62,66 @@ The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `flop` **[Boolean][6]** (optional, default `true`)
|
* `flop` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## affine
|
||||||
|
|
||||||
|
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.
|
||||||
|
By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||||
|
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolator` Object e.g. `sharp.interpolator.nohalo`.
|
||||||
|
|
||||||
|
In the case of a 2x2 matrix, the transform is:
|
||||||
|
|
||||||
|
* X = `matrix[0, 0]` \* (x + `idx`) + `matrix[0, 1]` \* (y + `idy`) + `odx`
|
||||||
|
* Y = `matrix[1, 0]` \* (x + `idx`) + `matrix[1, 1]` \* (y + `idy`) + `ody`
|
||||||
|
|
||||||
|
where:
|
||||||
|
|
||||||
|
* x and y are the coordinates in input image.
|
||||||
|
* X and Y are the coordinates in output image.
|
||||||
|
* (0,0) is the upper left corner.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `matrix` **([Array][7]<[Array][7]<[number][1]>> | [Array][7]<[number][1]>)** affine transformation matrix
|
||||||
|
* `options` **[Object][2]?** if present, is an Object with optional attributes.
|
||||||
|
|
||||||
|
* `options.background` **([String][3] | [Object][2])** parsed by the [color][4] module to extract values for red, green, blue and alpha. (optional, default `"#000000"`)
|
||||||
|
* `options.idx` **[Number][1]** input horizontal offset (optional, default `0`)
|
||||||
|
* `options.idy` **[Number][1]** input vertical offset (optional, default `0`)
|
||||||
|
* `options.odx` **[Number][1]** output horizontal offset (optional, default `0`)
|
||||||
|
* `options.ody` **[Number][1]** output vertical offset (optional, default `0`)
|
||||||
|
* `options.interpolator` **[String][3]** interpolator (optional, default `sharp.interpolators.bicubic`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const pipeline = sharp()
|
||||||
|
.affine([[1, 0.3], [0.1, 0.7]], {
|
||||||
|
background: 'white',
|
||||||
|
interpolate: sharp.interpolators.nohalo
|
||||||
|
})
|
||||||
|
.toBuffer((err, outputBuffer, info) => {
|
||||||
|
// outputBuffer contains the transformed image
|
||||||
|
// info.width and info.height contain the new dimensions
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream
|
||||||
|
.pipe(pipeline);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
**Meta**
|
||||||
|
|
||||||
|
* **since**: 0.27.0
|
||||||
|
|
||||||
## sharpen
|
## sharpen
|
||||||
|
|
||||||
Sharpen the image.
|
Sharpen the image.
|
||||||
@@ -74,12 +131,13 @@ Separate control over the level of sharpening in "flat" and "jagged" areas is av
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `sigma` **[number][1]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
* `sigma` **[number][1]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
- `flat` **[number][1]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
|
* `flat` **[number][1]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
|
||||||
- `jagged` **[number][1]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
* `jagged` **[number][1]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -90,10 +148,11 @@ When used without parameters the default window is 3x3.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `size` **[number][1]** square mask size: size x size (optional, default `3`)
|
* `size` **[number][1]** square mask size: size x size (optional, default `3`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -105,21 +164,33 @@ When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `sigma` **[number][1]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
* `sigma` **[number][1]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## flatten
|
## flatten
|
||||||
|
|
||||||
Merge alpha transparency channel, if any, with a background.
|
Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
||||||
|
|
||||||
|
See also [removeAlpha][8].
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][2]?**
|
* `options` **[Object][2]?**
|
||||||
- `options.background` **([string][3] \| [Object][2])** background colour, parsed by the [color][4] module, defaults to black. (optional, default `{r:0,g:0,b:0}`)
|
|
||||||
|
* `options.background` **([string][3] | [Object][2])** background colour, parsed by the [color][4] module, defaults to black. (optional, default `{r:0,g:0,b:0}`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await sharp(rgbaInput)
|
||||||
|
.flatten({ background: '#F0A703' })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -135,11 +206,12 @@ Supply a second argument to use a different output gamma value, otherwise the fi
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `gamma` **[number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
* `gamma` **[number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
||||||
- `gammaOut` **[number][1]?** value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
* `gammaOut` **[number][1]?** value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -149,7 +221,9 @@ Produce the "negative" of the image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `negate` **[Boolean][6]** (optional, default `true`)
|
* `options` **[Object][2]?**
|
||||||
|
|
||||||
|
* `options.alpha` **[Boolean][6]** Whether or not to negate any alpha channel (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -159,7 +233,7 @@ Enhance output image contrast by stretching its luminance to cover the full dyna
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `normalise` **[Boolean][6]** (optional, default `true`)
|
* `normalise` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -169,22 +243,50 @@ Alternative spelling of normalise.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `normalize` **[Boolean][6]** (optional, default `true`)
|
* `normalize` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## clahe
|
||||||
|
|
||||||
|
Perform contrast limiting adaptive histogram equalization
|
||||||
|
[CLAHE][9].
|
||||||
|
|
||||||
|
This will, in general, enhance the clarity of the image by bringing out darker details.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `options` **[Object][2]**
|
||||||
|
|
||||||
|
* `options.width` **[number][1]** integer width of the region in pixels.
|
||||||
|
* `options.height` **[number][1]** integer height of the region in pixels.
|
||||||
|
* `options.maxSlope` **[number][1]** maximum value for the slope of the
|
||||||
|
cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
||||||
|
are integers in the range 0-100 (inclusive) (optional, default `3`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
**Meta**
|
||||||
|
|
||||||
|
* **since**: 0.28.3
|
||||||
|
|
||||||
## convolve
|
## convolve
|
||||||
|
|
||||||
Convolve the image with the specified kernel.
|
Convolve the image with the specified kernel.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `kernel` **[Object][2]**
|
* `kernel` **[Object][2]**
|
||||||
- `kernel.width` **[number][1]** width of the kernel in pixels.
|
|
||||||
- `kernel.height` **[number][1]** width of the kernel in pixels.
|
* `kernel.width` **[number][1]** width of the kernel in pixels.
|
||||||
- `kernel.kernel` **[Array][7]<[number][1]>** Array of length `width*height` containing the kernel values.
|
* `kernel.height` **[number][1]** height of the kernel in pixels.
|
||||||
- `kernel.scale` **[number][1]** the scale of the kernel in pixels. (optional, default `sum`)
|
* `kernel.kernel` **[Array][7]<[number][1]>** Array of length `width*height` containing the kernel values.
|
||||||
- `kernel.offset` **[number][1]** the offset of the kernel in pixels. (optional, default `0`)
|
* `kernel.scale` **[number][1]** the scale of the kernel in pixels. (optional, default `sum`)
|
||||||
|
* `kernel.offset` **[number][1]** the offset of the kernel in pixels. (optional, default `0`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -202,23 +304,25 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## threshold
|
## threshold
|
||||||
|
|
||||||
Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `threshold` **[number][1]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
* `threshold` **[number][1]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
||||||
- `options` **[Object][2]?**
|
* `options` **[Object][2]?**
|
||||||
- `options.greyscale` **[Boolean][6]** convert to single channel greyscale. (optional, default `true`)
|
|
||||||
- `options.grayscale` **[Boolean][6]** alternative spelling for greyscale. (optional, default `true`)
|
|
||||||
|
|
||||||
|
* `options.greyscale` **[Boolean][6]** convert to single channel greyscale. (optional, default `true`)
|
||||||
|
* `options.grayscale` **[Boolean][6]** alternative spelling for greyscale. (optional, default `true`)
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -231,16 +335,19 @@ the selected bitwise boolean `operation` between the corresponding pixels of the
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `operand` **([Buffer][8] \| [string][3])** Buffer containing image data or string containing the path to an image file.
|
* `operand` **([Buffer][10] | [string][3])** Buffer containing image data or string containing the path to an image file.
|
||||||
- `operator` **[string][3]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
* `operator` **[string][3]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||||
- `options` **[Object][2]?**
|
* `options` **[Object][2]?**
|
||||||
- `options.raw` **[Object][2]?** describes operand when using raw pixel data.
|
|
||||||
- `options.raw.width` **[number][1]?**
|
|
||||||
- `options.raw.height` **[number][1]?**
|
|
||||||
- `options.raw.channels` **[number][1]?**
|
|
||||||
|
|
||||||
|
* `options.raw` **[Object][2]?** describes operand when using raw pixel data.
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* `options.raw.width` **[number][1]?**
|
||||||
|
* `options.raw.height` **[number][1]?**
|
||||||
|
* `options.raw.channels` **[number][1]?**
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -250,11 +357,12 @@ Apply the linear formula a \* input + b to the image (levels adjustment)
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `a` **[number][1]** multiplier (optional, default `1.0`)
|
* `a` **[number][1]** multiplier (optional, default `1.0`)
|
||||||
- `b` **[number][1]** offset (optional, default `0.0`)
|
* `b` **[number][1]** offset (optional, default `0.0`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -264,7 +372,7 @@ Recomb the image with the specified matrix.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `inputMatrix` **[Array][7]<[Array][7]<[number][1]>>** 3x3 Recombination matrix
|
* `inputMatrix` **[Array][7]<[Array][7]<[number][1]>>** 3x3 Recombination matrix
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -282,13 +390,13 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
**Meta**
|
**Meta**
|
||||||
|
|
||||||
- **since**: 0.21.1
|
* **since**: 0.21.1
|
||||||
|
|
||||||
## modulate
|
## modulate
|
||||||
|
|
||||||
@@ -296,10 +404,11 @@ Transforms the image using brightness, saturation and hue rotation.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][2]?**
|
* `options` **[Object][2]?**
|
||||||
- `options.brightness` **[number][1]?** Brightness multiplier
|
|
||||||
- `options.saturation` **[number][1]?** Saturation multiplier
|
* `options.brightness` **[number][1]?** Brightness multiplier
|
||||||
- `options.hue` **[number][1]?** Degrees for hue rotation
|
* `options.saturation` **[number][1]?** Saturation multiplier
|
||||||
|
* `options.hue` **[number][1]?** Degrees for hue rotation
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -327,7 +436,7 @@ Returns **Sharp**
|
|||||||
|
|
||||||
**Meta**
|
**Meta**
|
||||||
|
|
||||||
- **since**: 0.22.1
|
* **since**: 0.22.1
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
@@ -343,4 +452,8 @@ Returns **Sharp**
|
|||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
[8]: https://nodejs.org/api/buffer.html
|
[8]: /api-channel#removealpha
|
||||||
|
|
||||||
|
[9]: https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
|
||||||
|
|
||||||
|
[10]: https://nodejs.org/api/buffer.html
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
Write output image data to a file.
|
Write output image data to a file.
|
||||||
|
|
||||||
If an explicit output format is not selected, it will be inferred from the extension,
|
If an explicit output format is not selected, it will be inferred from the extension,
|
||||||
with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
|
with JPEG, PNG, WebP, AVIF, TIFF, DZI, and libvips' V format supported.
|
||||||
Note that raw pixel data is only supported for buffer output.
|
Note that raw pixel data is only supported for buffer output.
|
||||||
|
|
||||||
By default all metadata will be removed, which includes EXIF-based orientation.
|
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
@@ -15,8 +15,8 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `fileOut` **[string][2]** the path to write the image data to.
|
* `fileOut` **[string][2]** the path to write the image data to.
|
||||||
- `callback` **[Function][3]?** called on completion with two arguments `(err, info)`.
|
* `callback` **[Function][3]?** called on completion with two arguments `(err, info)`.
|
||||||
`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`.
|
||||||
@@ -35,14 +35,14 @@ sharp(input)
|
|||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid parameters
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **[Promise][5]<[Object][6]>** when no callback is provided
|
Returns **[Promise][5]<[Object][6]>** when no callback is provided
|
||||||
|
|
||||||
## toBuffer
|
## toBuffer
|
||||||
|
|
||||||
Write output to a Buffer.
|
Write output to a Buffer.
|
||||||
JPEG, PNG, WebP, TIFF and RAW output are supported.
|
JPEG, PNG, WebP, AVIF, TIFF and raw pixel data output are supported.
|
||||||
|
|
||||||
If no explicit format is set, the output format will match the input image, except GIF and SVG input which become PNG output.
|
If no explicit format is set, the output format will match the input image, except GIF and SVG input which become PNG output.
|
||||||
|
|
||||||
@@ -51,19 +51,21 @@ See [withMetadata][1] for control over this.
|
|||||||
|
|
||||||
`callback`, if present, gets three arguments `(err, data, info)` where:
|
`callback`, if present, gets three arguments `(err, data, info)` where:
|
||||||
|
|
||||||
- `err` is an error, if any.
|
* `err` is an error, if any.
|
||||||
- `data` is the output image data.
|
* `data` is the output image data.
|
||||||
- `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).
|
|
||||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?**
|
* `options` **[Object][6]?**
|
||||||
- `options.resolveWithObject` **[boolean][7]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
|
||||||
- `callback` **[Function][3]?**
|
* `options.resolveWithObject` **[boolean][7]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
|
* `callback` **[Function][3]?**
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -86,20 +88,42 @@ sharp(input)
|
|||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][5]<[Buffer][8]>** when no callback is provided
|
```javascript
|
||||||
|
const { data, info } = await sharp('my-image.jpg')
|
||||||
|
// output the raw pixels
|
||||||
|
.raw()
|
||||||
|
.toBuffer({ resolveWithObject: true });
|
||||||
|
|
||||||
|
// create a more type safe way to work with the raw pixel data
|
||||||
|
// this will not copy the data, instead it will change `data`s underlying ArrayBuffer
|
||||||
|
// so `data` and `pixelArray` point to the same memory location
|
||||||
|
const pixelArray = new Uint8ClampedArray(data.buffer);
|
||||||
|
|
||||||
|
// When you are done changing the pixelArray, sharp takes the `pixelArray` as an input
|
||||||
|
const { width, height, channels } = info;
|
||||||
|
await sharp(pixelArray, { raw: { width, height, channels } })
|
||||||
|
.toFile('my-changed-image.jpg');
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **[Promise][5]<[Buffer][8]>** when no callback is provided
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
|
|
||||||
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.
|
||||||
This will also convert to and add a web-friendly sRGB ICC profile.
|
This will also convert to and add a web-friendly sRGB ICC profile unless a custom
|
||||||
|
output profile is provided.
|
||||||
|
|
||||||
The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
|
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.
|
sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?**
|
* `options` **[Object][6]?**
|
||||||
- `options.orientation` **[number][9]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
|
||||||
|
* `options.orientation` **[number][9]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
|
* `options.icc` **[string][2]?** filesystem path to output ICC profile, defaults to sRGB.
|
||||||
|
* `options.exif` **[Object][6]<[Object][6]>** Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. (optional, default `{}`)
|
||||||
|
* `options.density` **[number][9]?** Number of pixels per inch (DPI).
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -110,7 +134,26 @@ sharp('input.jpg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid parameters
|
```javascript
|
||||||
|
// Set "IFD0-Copyright" in output EXIF metadata
|
||||||
|
const data = await sharp(input)
|
||||||
|
.withMetadata({
|
||||||
|
exif: {
|
||||||
|
IFD0: {
|
||||||
|
Copyright: 'Wernham Hogg'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
* @example
|
||||||
|
// Set output metadata to 96 DPI
|
||||||
|
const data = await sharp(input)
|
||||||
|
.withMetadata({ density: 96 })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -120,8 +163,8 @@ Force output to a given format.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `format` **([string][2] \| [Object][6])** as a string or an Object with an 'id' attribute
|
* `format` **([string][2] | [Object][6])** as a string or an Object with an 'id' attribute
|
||||||
- `options` **[Object][6]** output options
|
* `options` **[Object][6]** output options
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -132,7 +175,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** unsupported format or options
|
* Throws **[Error][4]** unsupported format or options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -140,23 +183,23 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these JPEG options for output image.
|
Use these JPEG options for output image.
|
||||||
|
|
||||||
Some of these options require the use of a globally-installed libvips compiled with support for mozjpeg.
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?** output options
|
* `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
|
||||||
- `options.progressive` **[boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
* `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.chromaSubsampling` **[string][2]** set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling (optional, default `'4:2:0'`)
|
* `options.progressive` **[boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.optimiseCoding` **[boolean][7]** optimise Huffman coding tables (optional, default `true`)
|
* `options.chromaSubsampling` **[string][2]** set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling (optional, default `'4:2:0'`)
|
||||||
- `options.optimizeCoding` **[boolean][7]** alternative spelling of optimiseCoding (optional, default `true`)
|
* `options.optimiseCoding` **[boolean][7]** optimise Huffman coding tables (optional, default `true`)
|
||||||
- `options.trellisQuantisation` **[boolean][7]** apply trellis quantisation, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
* `options.optimizeCoding` **[boolean][7]** alternative spelling of optimiseCoding (optional, default `true`)
|
||||||
- `options.overshootDeringing` **[boolean][7]** apply overshoot deringing, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
* `options.mozjpeg` **[boolean][7]** use mozjpeg defaults, equivalent to `{ trellisQuantisation: true, overshootDeringing: true, optimiseScans: true, quantisationTable: 3 }` (optional, default `false`)
|
||||||
- `options.optimiseScans` **[boolean][7]** optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
* `options.trellisQuantisation` **[boolean][7]** apply trellis quantisation (optional, default `false`)
|
||||||
- `options.optimizeScans` **[boolean][7]** alternative spelling of optimiseScans, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
* `options.overshootDeringing` **[boolean][7]** apply overshoot deringing (optional, default `false`)
|
||||||
- `options.quantisationTable` **[number][9]** quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg (optional, default `0`)
|
* `options.optimiseScans` **[boolean][7]** optimise progressive scans, forces progressive (optional, default `false`)
|
||||||
- `options.quantizationTable` **[number][9]** alternative spelling of quantisationTable, requires libvips compiled with support for mozjpeg (optional, default `0`)
|
* `options.optimizeScans` **[boolean][7]** alternative spelling of optimiseScans (optional, default `false`)
|
||||||
- `options.force` **[boolean][7]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
* `options.quantisationTable` **[number][9]** quantization table to use, integer 0-8 (optional, default `0`)
|
||||||
|
* `options.quantizationTable` **[number][9]** alternative spelling of quantisationTable (optional, default `0`)
|
||||||
|
* `options.force` **[boolean][7]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -170,7 +213,14 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
```javascript
|
||||||
|
// Use mozjpeg to reduce output JPEG file size (slower)
|
||||||
|
const data = await sharp(input)
|
||||||
|
.jpeg({ mozjpeg: true })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -178,34 +228,41 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these PNG options for output image.
|
Use these PNG options for output image.
|
||||||
|
|
||||||
PNG output is always full colour at 8 or 16 bits per pixel.
|
By default, PNG output is full colour at 8 or 16 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.
|
||||||
Some of these options require the use of a globally-installed libvips compiled with support for libimagequant (GPL).
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?**
|
* `options` **[Object][6]?**
|
||||||
- `options.progressive` **[boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
|
||||||
- `options.compressionLevel` **[number][9]** zlib compression level, 0-9 (optional, default `9`)
|
* `options.progressive` **[boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.adaptiveFiltering` **[boolean][7]** use adaptive row filtering (optional, default `false`)
|
* `options.compressionLevel` **[number][9]** zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest) (optional, default `6`)
|
||||||
- `options.palette` **[boolean][7]** quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant (optional, default `false`)
|
* `options.adaptiveFiltering` **[boolean][7]** use adaptive row filtering (optional, default `false`)
|
||||||
- `options.quality` **[number][9]** use the lowest number of colours needed to achieve given quality, sets `palette` to `true`, requires libvips compiled with support for libimagequant (optional, default `100`)
|
* `options.palette` **[boolean][7]** quantise to a palette-based image with alpha transparency support (optional, default `false`)
|
||||||
- `options.colours` **[number][9]** maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant (optional, default `256`)
|
* `options.quality` **[number][9]** use the lowest number of colours needed to achieve given quality, sets `palette` to `true` (optional, default `100`)
|
||||||
- `options.colors` **[number][9]** alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant (optional, default `256`)
|
* `options.colours` **[number][9]** maximum number of palette entries, sets `palette` to `true` (optional, default `256`)
|
||||||
- `options.dither` **[number][9]** level of Floyd-Steinberg error diffusion, sets `palette` to `true`, requires libvips compiled with support for libimagequant (optional, default `1.0`)
|
* `options.colors` **[number][9]** alternative spelling of `options.colours`, sets `palette` to `true` (optional, default `256`)
|
||||||
- `options.force` **[boolean][7]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
* `options.dither` **[number][9]** level of Floyd-Steinberg error diffusion, sets `palette` to `true` (optional, default `1.0`)
|
||||||
|
* `options.force` **[boolean][7]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Convert any input to PNG output
|
// Convert any input to full colour PNG output
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.png()
|
.png()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
```javascript
|
||||||
|
// Convert any input to indexed PNG output (slower)
|
||||||
|
const data = await sharp(input)
|
||||||
|
.png({ palette: true })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -215,17 +272,18 @@ Use these WebP options for output image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?** output options
|
* `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
|
||||||
- `options.alphaQuality` **[number][9]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
* `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.lossless` **[boolean][7]** use lossless compression mode (optional, default `false`)
|
* `options.alphaQuality` **[number][9]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
||||||
- `options.nearLossless` **[boolean][7]** use near_lossless compression mode (optional, default `false`)
|
* `options.lossless` **[boolean][7]** use lossless compression mode (optional, default `false`)
|
||||||
- `options.smartSubsample` **[boolean][7]** use high quality chroma subsampling (optional, default `false`)
|
* `options.nearLossless` **[boolean][7]** use near_lossless compression mode (optional, default `false`)
|
||||||
- `options.reductionEffort` **[number][9]** level of CPU effort to reduce file size, integer 0-6 (optional, default `4`)
|
* `options.smartSubsample` **[boolean][7]** use high quality chroma subsampling (optional, default `false`)
|
||||||
- `options.pageHeight` **[number][9]?** page height for animated output
|
* `options.reductionEffort` **[number][9]** level of CPU effort to reduce file size, integer 0-6 (optional, default `4`)
|
||||||
- `options.loop` **[number][9]** number of animation iterations, use 0 for infinite animation (optional, default `0`)
|
* `options.pageHeight` **[number][9]?** page height for animated output
|
||||||
- `options.delay` **[Array][10]<[number][9]>?** list of delays between animation frames (in milliseconds)
|
* `options.loop` **[number][9]** number of animation iterations, use 0 for infinite animation (optional, default `0`)
|
||||||
- `options.force` **[boolean][7]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
* `options.delay` **[Array][10]<[number][9]>?** list of delays between animation frames (in milliseconds)
|
||||||
|
* `options.force` **[boolean][7]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -236,7 +294,14 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
```javascript
|
||||||
|
// Optimise the file size of an animated WebP
|
||||||
|
const outputWebp = await sharp(inputWebp, { animated: true })
|
||||||
|
.webp({ reductionEffort: 6 })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -250,14 +315,16 @@ The prebuilt binaries do not include this - see
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?** output options
|
* `options` **[Object][6]?** output options
|
||||||
- `options.pageHeight` **[number][9]?** page height for animated output
|
|
||||||
- `options.loop` **[number][9]** number of animation iterations, use 0 for infinite animation (optional, default `0`)
|
|
||||||
- `options.delay` **[Array][10]<[number][9]>?** list of delays between animation frames (in milliseconds)
|
|
||||||
- `options.force` **[boolean][7]** force GIF output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
|
|
||||||
|
* `options.pageHeight` **[number][9]?** page height for animated output
|
||||||
|
* `options.loop` **[number][9]** number of animation iterations, use 0 for infinite animation (optional, default `0`)
|
||||||
|
* `options.delay` **[Array][10]<[number][9]>?** list of delays between animation frames (in milliseconds)
|
||||||
|
* `options.force` **[boolean][7]** force GIF output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -267,18 +334,19 @@ Use these TIFF options for output image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?** output options
|
* `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
|
||||||
- `options.force` **[boolean][7]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
* `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.compression` **[boolean][7]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
* `options.force` **[boolean][7]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
||||||
- `options.predictor` **[boolean][7]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
* `options.compression` **[string][2]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
||||||
- `options.pyramid` **[boolean][7]** write an image pyramid (optional, default `false`)
|
* `options.predictor` **[string][2]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
||||||
- `options.tile` **[boolean][7]** write a tiled tiff (optional, default `false`)
|
* `options.pyramid` **[boolean][7]** write an image pyramid (optional, default `false`)
|
||||||
- `options.tileWidth` **[boolean][7]** horizontal tile size (optional, default `256`)
|
* `options.tile` **[boolean][7]** write a tiled tiff (optional, default `false`)
|
||||||
- `options.tileHeight` **[boolean][7]** vertical tile size (optional, default `256`)
|
* `options.tileWidth` **[number][9]** horizontal tile size (optional, default `256`)
|
||||||
- `options.xres` **[number][9]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
* `options.tileHeight` **[number][9]** vertical tile size (optional, default `256`)
|
||||||
- `options.yres` **[number][9]** vertical resolution in pixels/mm (optional, default `1.0`)
|
* `options.xres` **[number][9]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
||||||
- `options.bitdepth` **[boolean][7]** reduce bitdepth to 1, 2 or 4 bit (optional, default `8`)
|
* `options.yres` **[number][9]** vertical resolution in pixels/mm (optional, default `1.0`)
|
||||||
|
* `options.bitdepth` **[number][9]** reduce bitdepth to 1, 2 or 4 bit (optional, default `8`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -293,63 +361,95 @@ sharp('input.svg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## heif
|
## avif
|
||||||
|
|
||||||
Use these HEIF options for output image.
|
Use these AVIF options for output image.
|
||||||
|
|
||||||
Support for HEIF (HEIC/AVIF) is experimental.
|
Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
||||||
Do not use this in production systems.
|
most web browsers do not display these properly.
|
||||||
|
|
||||||
Requires a custom, globally-installed libvips compiled with support for libheif.
|
|
||||||
|
|
||||||
Most versions of libheif support only the patent-encumbered HEVC compression format.
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?** output options
|
* `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
|
||||||
- `options.compression` **[boolean][7]** compression format: hevc, avc, jpeg, av1 (optional, default `'hevc'`)
|
|
||||||
- `options.lossless` **[boolean][7]** use lossless compression (optional, default `false`)
|
|
||||||
|
|
||||||
|
* `options.quality` **[number][9]** quality, integer 1-100 (optional, default `50`)
|
||||||
|
* `options.lossless` **[boolean][7]** use lossless compression (optional, default `false`)
|
||||||
|
* `options.speed` **[number][9]** CPU effort vs file size, 0 (slowest/smallest) to 8 (fastest/largest) (optional, default `5`)
|
||||||
|
* `options.chromaSubsampling` **[string][2]** set to '4:2:0' to use chroma subsampling (optional, default `'4:4:4'`)
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
**Meta**
|
**Meta**
|
||||||
|
|
||||||
- **since**: 0.23.0
|
* **since**: 0.27.0
|
||||||
|
|
||||||
|
## heif
|
||||||
|
|
||||||
|
Use these HEIF options for output image.
|
||||||
|
|
||||||
|
Support for patent-encumbered HEIC images requires the use of a
|
||||||
|
globally-installed libvips compiled with support for libheif, libde265 and x265.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `options` **[Object][6]?** output options
|
||||||
|
|
||||||
|
* `options.quality` **[number][9]** quality, integer 1-100 (optional, default `50`)
|
||||||
|
* `options.compression` **[string][2]** compression format: av1, hevc (optional, default `'av1'`)
|
||||||
|
* `options.lossless` **[boolean][7]** use lossless compression (optional, default `false`)
|
||||||
|
* `options.speed` **[number][9]** CPU effort vs file size, 0 (slowest/smallest) to 8 (fastest/largest) (optional, default `5`)
|
||||||
|
* `options.chromaSubsampling` **[string][2]** set to '4:2:0' to use chroma subsampling (optional, default `'4:4:4'`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
**Meta**
|
||||||
|
|
||||||
|
* **since**: 0.23.0
|
||||||
|
|
||||||
## raw
|
## raw
|
||||||
|
|
||||||
Force output to be raw, uncompressed, 8-bit unsigned integer (unit8) pixel data.
|
Force output to be raw, uncompressed pixel data.
|
||||||
Pixel ordering is left-to-right, top-to-bottom, without padding.
|
Pixel ordering is left-to-right, top-to-bottom, without padding.
|
||||||
Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `options` **[Object][6]?** output options
|
||||||
|
|
||||||
|
* `options.depth` **[string][2]** bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex (optional, default `'uchar'`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Extract raw RGB pixel data from JPEG input
|
// Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
||||||
const { data, info } = await sharp('input.jpg')
|
const { data, info } = await sharp('input.jpg')
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer({ resolveWithObject: true });
|
.toBuffer({ resolveWithObject: true });
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Extract alpha channel as raw pixel data from PNG input
|
// Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
||||||
const data = await sharp('input.png')
|
const data = await sharp('input.png')
|
||||||
.ensureAlpha()
|
.ensureAlpha()
|
||||||
.extractChannel(3)
|
.extractChannel(3)
|
||||||
.toColourspace('b-w')
|
.toColourspace('b-w')
|
||||||
.raw()
|
.raw({ depth: 'ushort' })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
* Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
## tile
|
## tile
|
||||||
|
|
||||||
@@ -361,15 +461,19 @@ Warning: multiple sharp instances concurrently producing tile output can expose
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?**
|
* `options` **[Object][6]?**
|
||||||
- `options.size` **[number][9]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
|
||||||
- `options.overlap` **[number][9]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
* `options.size` **[number][9]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
||||||
- `options.angle` **[number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
* `options.overlap` **[number][9]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
- `options.background` **([string][2] \| [Object][6])** background colour, parsed by the [color][12] module, defaults to white without transparency. (optional, default `{r:255,g:255,b:255,alpha:1}`)
|
* `options.angle` **[number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
||||||
- `options.depth` **[string][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
* `options.background` **([string][2] | [Object][6])** background colour, parsed by the [color][12] module, defaults to white without transparency. (optional, default `{r:255,g:255,b:255,alpha:1}`)
|
||||||
- `options.skipBlanks` **[number][9]** threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images (optional, default `-1`)
|
* `options.depth` **[string][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
- `options.container` **[string][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
* `options.skipBlanks` **[number][9]** threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images (optional, default `-1`)
|
||||||
- `options.layout` **[string][2]** filesystem layout, possible values are `dz`, `iiif`, `zoomify` or `google`. (optional, default `'dz'`)
|
* `options.container` **[string][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
|
* `options.layout` **[string][2]** filesystem layout, possible values are `dz`, `iiif`, `zoomify` or `google`. (optional, default `'dz'`)
|
||||||
|
* `options.centre` **[boolean][7]** centre image in tile. (optional, default `false`)
|
||||||
|
* `options.center` **[boolean][7]** alternative spelling of centre. (optional, default `false`)
|
||||||
|
* `options.id` **[string][2]** when `layout` is `iiif`, sets the `@id` attribute of `info.json` (optional, default `'https://example.com/iiif'`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -385,7 +489,7 @@ sharp('input.tiff')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid parameters
|
* Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
|||||||
@@ -6,49 +6,50 @@ Resize image to `width`, `height` or `width x height`.
|
|||||||
|
|
||||||
When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
||||||
|
|
||||||
- `cover`: (default) Preserving aspect ratio, ensure the image covers both provided dimensions by cropping/clipping to fit.
|
* `cover`: (default) Preserving aspect ratio, ensure the image covers both provided dimensions by cropping/clipping to fit.
|
||||||
- `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
* `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
||||||
- `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
* `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
||||||
- `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
* `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
||||||
- `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
* `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
||||||
|
|
||||||
Some of these values are based on the [object-fit][1] CSS property.
|
Some of these values are based on the [object-fit][1] CSS property.
|
||||||
|
|
||||||
When using a `fit` of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
When using a `fit` of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
||||||
|
|
||||||
- `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
* `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
||||||
- `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
|
* `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
|
||||||
- `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
|
* `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
|
||||||
|
|
||||||
Some of these values are based on the [object-position][2] CSS property.
|
Some of these values are based on the [object-position][2] CSS property.
|
||||||
|
|
||||||
The experimental strategy-based approach resizes so one dimension is at its target length
|
The experimental strategy-based approach 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][3].
|
* `entropy`: focus on the region with the highest [Shannon entropy][3].
|
||||||
- `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 interpolation kernels are:
|
||||||
|
|
||||||
- `nearest`: Use [nearest neighbour interpolation][4].
|
* `nearest`: Use [nearest neighbour interpolation][4].
|
||||||
- `cubic`: Use a [Catmull-Rom spline][5].
|
* `cubic`: Use a [Catmull-Rom spline][5].
|
||||||
- `mitchell`: Use a [Mitchell-Netravali spline][6].
|
* `mitchell`: Use a [Mitchell-Netravali spline][6].
|
||||||
- `lanczos2`: Use a [Lanczos kernel][7] with `a=2`.
|
* `lanczos2`: Use a [Lanczos kernel][7] with `a=2`.
|
||||||
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
* `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `width` **[number][8]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
* `width` **[number][8]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
||||||
- `height` **[number][8]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
* `height` **[number][8]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
||||||
- `options` **[Object][9]?**
|
* `options` **[Object][9]?**
|
||||||
- `options.width` **[String][10]?** alternative means of specifying `width`. If both are present this take priority.
|
|
||||||
- `options.height` **[String][10]?** alternative means of specifying `height`. If both are present this take priority.
|
* `options.width` **[String][10]?** alternative means of specifying `width`. If both are present this take priority.
|
||||||
- `options.fit` **[String][10]** how the image should be resized to fit both provided dimensions, one of `cover`, `contain`, `fill`, `inside` or `outside`. (optional, default `'cover'`)
|
* `options.height` **[String][10]?** alternative means of specifying `height`. If both are present this take priority.
|
||||||
- `options.position` **[String][10]** position, gravity or strategy to use when `fit` is `cover` or `contain`. (optional, default `'centre'`)
|
* `options.fit` **[String][10]** how the image should be resized to fit both provided dimensions, one of `cover`, `contain`, `fill`, `inside` or `outside`. (optional, default `'cover'`)
|
||||||
- `options.background` **([String][10] \| [Object][9])** background colour when using a `fit` of `contain`, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
* `options.position` **[String][10]** position, gravity or strategy to use when `fit` is `cover` or `contain`. (optional, default `'centre'`)
|
||||||
- `options.kernel` **[String][10]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
* `options.background` **([String][10] | [Object][9])** background colour when using a `fit` of `contain`, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
||||||
- `options.withoutEnlargement` **[Boolean][12]** do not enlarge if the width _or_ height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. (optional, default `false`)
|
* `options.kernel` **[String][10]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
||||||
- `options.fastShrinkOnLoad` **[Boolean][12]** take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default `true`)
|
* `options.withoutEnlargement` **[Boolean][12]** do not enlarge if the width *or* height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. (optional, default `false`)
|
||||||
|
* `options.fastShrinkOnLoad` **[Boolean][12]** take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ const scaleByHalf = await sharp(input)
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
* Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -136,12 +137,13 @@ This operation will always occur after resizing and extraction, if any.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `extend` **([number][8] \| [Object][9])** single pixel count to add to all edges or an Object with per-edge counts
|
* `extend` **([number][8] | [Object][9])** single pixel count to add to all edges or an Object with per-edge counts
|
||||||
- `extend.top` **[number][8]?**
|
|
||||||
- `extend.left` **[number][8]?**
|
* `extend.top` **[number][8]** (optional, default `0`)
|
||||||
- `extend.bottom` **[number][8]?**
|
* `extend.left` **[number][8]** (optional, default `0`)
|
||||||
- `extend.right` **[number][8]?**
|
* `extend.bottom` **[number][8]** (optional, default `0`)
|
||||||
- `extend.background` **([String][10] \| [Object][9])** background colour, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
* `extend.right` **[number][8]** (optional, default `0`)
|
||||||
|
* `extend.background` **([String][10] | [Object][9])** background colour, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -160,7 +162,17 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
```javascript
|
||||||
|
// Add a row of 10 red pixels to the bottom
|
||||||
|
sharp(input)
|
||||||
|
.extend({
|
||||||
|
bottom: 10,
|
||||||
|
background: 'red'
|
||||||
|
})
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
* Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -168,17 +180,18 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Extract/crop a region of the image.
|
Extract/crop a region of the image.
|
||||||
|
|
||||||
- Use `extract` before `resize` for pre-resize extraction.
|
* Use `extract` before `resize` for pre-resize extraction.
|
||||||
- Use `extract` after `resize` for post-resize extraction.
|
* Use `extract` after `resize` for post-resize extraction.
|
||||||
- Use `extract` before and after for both.
|
* Use `extract` before and after for both.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][9]** describes the region to extract using integral pixel values
|
* `options` **[Object][9]** describes the region to extract using integral pixel values
|
||||||
- `options.left` **[number][8]** zero-indexed offset from left edge
|
|
||||||
- `options.top` **[number][8]** zero-indexed offset from top edge
|
* `options.left` **[number][8]** zero-indexed offset from left edge
|
||||||
- `options.width` **[number][8]** width of region to extract
|
* `options.top` **[number][8]** zero-indexed offset from top edge
|
||||||
- `options.height` **[number][8]** height of region to extract
|
* `options.width` **[number][8]** width of region to extract
|
||||||
|
* `options.height` **[number][8]** height of region to extract
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -200,7 +213,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
* Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -209,14 +222,16 @@ Returns **Sharp**
|
|||||||
Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
||||||
Images consisting entirely of a single colour will calculate "boring" using the alpha channel, if any.
|
Images consisting entirely of a single colour will calculate "boring" using the alpha channel, if any.
|
||||||
|
|
||||||
The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
The `info` response Object, obtained from callback of `.toFile()` or `.toBuffer()`,
|
||||||
|
will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `threshold` **[number][8]** the allowed difference from the top-left pixel, a number greater than zero. (optional, default `10`)
|
* `threshold` **[number][8]** the allowed difference from the top-left pixel, a number greater than zero. (optional, default `10`)
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
* Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,36 @@ console.log(sharp.format);
|
|||||||
|
|
||||||
Returns **[Object][1]**
|
Returns **[Object][1]**
|
||||||
|
|
||||||
|
## interpolators
|
||||||
|
|
||||||
|
An Object containing the available interpolators and their proper values
|
||||||
|
|
||||||
|
Type: [string][2]
|
||||||
|
|
||||||
|
### nearest
|
||||||
|
|
||||||
|
[Nearest neighbour interpolation][3]. Suitable for image enlargement only.
|
||||||
|
|
||||||
|
### bilinear
|
||||||
|
|
||||||
|
[Bilinear interpolation][4]. Faster than bicubic but with less smooth results.
|
||||||
|
|
||||||
|
### bicubic
|
||||||
|
|
||||||
|
[Bicubic interpolation][5] (the default).
|
||||||
|
|
||||||
|
### locallyBoundedBicubic
|
||||||
|
|
||||||
|
[LBB interpolation][6]. Prevents some "[acutance][7]" but typically reduces performance by a factor of 2.
|
||||||
|
|
||||||
|
### nohalo
|
||||||
|
|
||||||
|
[Nohalo interpolation][8]. Prevents acutance but typically reduces performance by a factor of 3.
|
||||||
|
|
||||||
|
### vertexSplitQuadraticBasisSpline
|
||||||
|
|
||||||
|
[VSQBS interpolation][9]. Prevents "staircasing" when enlarging.
|
||||||
|
|
||||||
## versions
|
## versions
|
||||||
|
|
||||||
An Object containing the version numbers of libvips and its dependencies.
|
An Object containing the version numbers of libvips and its dependencies.
|
||||||
@@ -24,17 +54,18 @@ console.log(sharp.versions);
|
|||||||
|
|
||||||
## cache
|
## cache
|
||||||
|
|
||||||
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.
|
||||||
This method always returns cache statistics,
|
This method always returns cache statistics,
|
||||||
useful for determining how much working memory is required for a particular task.
|
useful for determining how much working memory is required for a particular task.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **([Object][1] \| [boolean][2])** Object with the following attributes, or boolean where true uses default cache settings and false removes all caching (optional, default `true`)
|
* `options` **([Object][1] | [boolean][10])** Object with the following attributes, or boolean where true uses default cache settings and false removes all caching (optional, default `true`)
|
||||||
- `options.memory` **[number][3]** is the maximum memory in MB to use for this cache (optional, default `50`)
|
|
||||||
- `options.files` **[number][3]** is the maximum number of files to hold open (optional, default `20`)
|
* `options.memory` **[number][11]** is the maximum memory in MB to use for this cache (optional, default `50`)
|
||||||
- `options.items` **[number][3]** is the maximum number of operations to cache (optional, default `100`)
|
* `options.files` **[number][11]** is the maximum number of files to hold open (optional, default `20`)
|
||||||
|
* `options.items` **[number][11]** is the maximum number of operations to cache (optional, default `100`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -53,9 +84,13 @@ Returns **[Object][1]**
|
|||||||
## concurrency
|
## concurrency
|
||||||
|
|
||||||
Gets or, when a concurrency is provided, sets
|
Gets or, when a concurrency is provided, sets
|
||||||
the number of threads _libvips'_ should create to process each image.
|
the number of threads *libvips'* should create to process each image.
|
||||||
The default value is the number of CPU cores.
|
|
||||||
A value of `0` will reset to this default.
|
The default value is the number of CPU cores,
|
||||||
|
except when using glibc-based Linux without jemalloc,
|
||||||
|
where the default is `1` to help reduce memory fragmentation.
|
||||||
|
|
||||||
|
A value of `0` will reset this to the number of CPU cores.
|
||||||
|
|
||||||
The maximum number of images that can be processed in parallel
|
The maximum number of images that can be processed in parallel
|
||||||
is limited by libuv's `UV_THREADPOOL_SIZE` environment variable.
|
is limited by libuv's `UV_THREADPOOL_SIZE` environment variable.
|
||||||
@@ -64,7 +99,7 @@ This method always returns the current concurrency.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `concurrency` **[number][3]?**
|
* `concurrency` **[number][11]?**
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -74,14 +109,14 @@ sharp.concurrency(2); // 2
|
|||||||
sharp.concurrency(0); // 4
|
sharp.concurrency(0); // 4
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[number][3]** concurrency
|
Returns **[number][11]** concurrency
|
||||||
|
|
||||||
## queue
|
## queue
|
||||||
|
|
||||||
An EventEmitter that emits a `change` event when a task is either:
|
An EventEmitter that emits a `change` event when a task is either:
|
||||||
|
|
||||||
- queued, waiting for _libuv_ to provide a worker thread
|
* queued, waiting for *libuv* to provide a worker thread
|
||||||
- complete
|
* complete
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -95,8 +130,8 @@ sharp.queue.on('change', function(queueLength) {
|
|||||||
|
|
||||||
Provides access to internal task counters.
|
Provides access to internal task counters.
|
||||||
|
|
||||||
- queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
|
* queue is the number of tasks this module has queued waiting for *libuv* to provide a worker thread from its pool.
|
||||||
- process is the number of resize tasks currently being processed.
|
* process is the number of resize tasks currently being processed.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -116,7 +151,7 @@ by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM N
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `simd` **[boolean][2]** (optional, default `true`)
|
* `simd` **[boolean][10]** (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -130,10 +165,26 @@ const simd = sharp.simd(false);
|
|||||||
// prevent libvips from using liborc at runtime
|
// prevent libvips from using liborc at runtime
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[boolean][2]**
|
Returns **[boolean][10]**
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[3]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
|
||||||
|
|
||||||
|
[4]: http://en.wikipedia.org/wiki/Bilinear_interpolation
|
||||||
|
|
||||||
|
[5]: http://en.wikipedia.org/wiki/Bicubic_interpolation
|
||||||
|
|
||||||
|
[6]: https://github.com/jcupitt/libvips/blob/master/libvips/resample/lbb.cpp#L100
|
||||||
|
|
||||||
|
[7]: http://en.wikipedia.org/wiki/Acutance
|
||||||
|
|
||||||
|
[8]: http://eprints.soton.ac.uk/268086/
|
||||||
|
|
||||||
|
[9]: https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48
|
||||||
|
|
||||||
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|||||||
25
docs/build.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const path = require('path');
|
||||||
|
const documentation = require('documentation');
|
||||||
|
|
||||||
|
[
|
||||||
|
'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 documentation.build(input, { shallow: true });
|
||||||
|
const markdown = await documentation.formats.md(ast, { markdownToc: false });
|
||||||
|
|
||||||
|
await fs.writeFile(output, markdown);
|
||||||
|
});
|
||||||
@@ -1,10 +1,224 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v0.29 - *circle*
|
||||||
|
|
||||||
|
Requires libvips v8.11.3
|
||||||
|
|
||||||
|
### v0.29.0 - 17th August 2021
|
||||||
|
|
||||||
|
* Drop support for Node.js 10, now requires Node.js >= 12.13.0.
|
||||||
|
|
||||||
|
* Add `background` property to PNG and GIF image metadata.
|
||||||
|
|
||||||
|
* Add `compression` property to HEIF image metadata.
|
||||||
|
[#2504](https://github.com/lovell/sharp/issues/2504)
|
||||||
|
|
||||||
|
* AVIF encoding now defaults to `4:4:4` chroma subsampling.
|
||||||
|
[#2562](https://github.com/lovell/sharp/issues/2562)
|
||||||
|
|
||||||
|
* Allow multiple platform-arch binaries in same `node_modules` installation tree.
|
||||||
|
[#2575](https://github.com/lovell/sharp/issues/2575)
|
||||||
|
|
||||||
|
* Default to single-channel `b-w` space when `extractChannel` is used.
|
||||||
|
[#2658](https://github.com/lovell/sharp/issues/2658)
|
||||||
|
|
||||||
|
* Allow installation directory to contain spaces (regression in v0.26.0).
|
||||||
|
[#2777](https://github.com/lovell/sharp/issues/2777)
|
||||||
|
|
||||||
|
* Add `pipelineColourspace` operator to set the processing space.
|
||||||
|
[#2704](https://github.com/lovell/sharp/pull/2704)
|
||||||
|
[@Daiz](https://github.com/Daiz)
|
||||||
|
|
||||||
|
* Allow bit depth to be set when using raw input and output.
|
||||||
|
[#2762](https://github.com/lovell/sharp/pull/2762)
|
||||||
|
[@mart-jansink](https://github.com/mart-jansink)
|
||||||
|
|
||||||
|
* Allow `negate` to act only on non-alpha channels.
|
||||||
|
[#2808](https://github.com/lovell/sharp/pull/2808)
|
||||||
|
[@rexxars](https://github.com/rexxars)
|
||||||
|
|
||||||
|
## v0.28 - *bijou*
|
||||||
|
|
||||||
|
Requires libvips v8.10.6
|
||||||
|
|
||||||
|
### v0.28.3 - 24th May 2021
|
||||||
|
|
||||||
|
* Ensure presence of libvips, vendored or global, before invoking node-gyp.
|
||||||
|
|
||||||
|
* Skip shrink-on-load for multi-page WebP.
|
||||||
|
[#2714](https://github.com/lovell/sharp/issues/2714)
|
||||||
|
|
||||||
|
* Add contrast limiting adaptive histogram equalization (CLAHE) operator.
|
||||||
|
[#2726](https://github.com/lovell/sharp/pull/2726)
|
||||||
|
[@baparham](https://github.com/baparham)
|
||||||
|
|
||||||
|
### v0.28.2 - 10th May 2021
|
||||||
|
|
||||||
|
* Allow `withMetadata` to set `density`.
|
||||||
|
[#967](https://github.com/lovell/sharp/issues/967)
|
||||||
|
|
||||||
|
* Skip shrink-on-load where one dimension <4px.
|
||||||
|
[#2653](https://github.com/lovell/sharp/issues/2653)
|
||||||
|
|
||||||
|
* Allow escaped proxy credentials.
|
||||||
|
[#2664](https://github.com/lovell/sharp/pull/2664)
|
||||||
|
[@msalettes](https://github.com/msalettes)
|
||||||
|
|
||||||
|
* Add `premultiplied` flag for raw pixel data input.
|
||||||
|
[#2685](https://github.com/lovell/sharp/pull/2685)
|
||||||
|
[@mnutt](https://github.com/mnutt)
|
||||||
|
|
||||||
|
* Detect empty input and throw a helpful error.
|
||||||
|
[#2687](https://github.com/lovell/sharp/pull/2687)
|
||||||
|
[@JakobJingleheimer](https://github.com/JakobJingleheimer)
|
||||||
|
|
||||||
|
* Add install-time flag to skip version compatibility checks.
|
||||||
|
[#2692](https://github.com/lovell/sharp/pull/2692)
|
||||||
|
[@xemle](https://github.com/xemle)
|
||||||
|
|
||||||
|
### v0.28.1 - 5th April 2021
|
||||||
|
|
||||||
|
* Ensure all installation errors are logged with a more obvious prefix.
|
||||||
|
|
||||||
|
* Allow `withMetadata` to set and update EXIF metadata.
|
||||||
|
[#650](https://github.com/lovell/sharp/issues/650)
|
||||||
|
|
||||||
|
* Add support for OME-TIFF Sub Image File Directories (subIFD).
|
||||||
|
[#2557](https://github.com/lovell/sharp/issues/2557)
|
||||||
|
|
||||||
|
* Allow `ensureAlpha` to set the alpha transparency level.
|
||||||
|
[#2634](https://github.com/lovell/sharp/issues/2634)
|
||||||
|
|
||||||
|
### v0.28.0 - 29th March 2021
|
||||||
|
|
||||||
|
* Prebuilt binaries now include mozjpeg and libimagequant (BSD 2-Clause).
|
||||||
|
|
||||||
|
* Prebuilt binaries limit AVIF support to the most common 8-bit depth.
|
||||||
|
|
||||||
|
* Add `mozjpeg` option to `jpeg` method, sets mozjpeg defaults.
|
||||||
|
|
||||||
|
* Reduce the default PNG `compressionLevel` to the more commonly used 6.
|
||||||
|
|
||||||
|
* Reduce concurrency on glibc-based Linux when using the default memory allocator to help prevent fragmentation.
|
||||||
|
|
||||||
|
* Default missing edge properties of extend operation to zero.
|
||||||
|
[#2578](https://github.com/lovell/sharp/issues/2578)
|
||||||
|
|
||||||
|
* Ensure composite does not clip top and left offsets.
|
||||||
|
[#2594](https://github.com/lovell/sharp/pull/2594)
|
||||||
|
[@SHG42](https://github.com/SHG42)
|
||||||
|
|
||||||
|
* Improve error handling of network failure at install time.
|
||||||
|
[#2608](https://github.com/lovell/sharp/pull/2608)
|
||||||
|
[@abradley](https://github.com/abradley)
|
||||||
|
|
||||||
|
* Ensure `@id` attribute can be set for IIIF tile-based output.
|
||||||
|
[#2612](https://github.com/lovell/sharp/issues/2612)
|
||||||
|
[@edsilv](https://github.com/edsilv)
|
||||||
|
|
||||||
|
* Ensure composite replicates the correct number of tiles for centred gravities.
|
||||||
|
[#2626](https://github.com/lovell/sharp/issues/2626)
|
||||||
|
|
||||||
|
## v0.27 - *avif*
|
||||||
|
|
||||||
|
Requires libvips v8.10.5
|
||||||
|
|
||||||
|
### v0.27.2 - 22nd February 2021
|
||||||
|
|
||||||
|
* macOS: Prevent use of globally-installed ARM64 libvips with Rosetta x64 emulation.
|
||||||
|
[#2460](https://github.com/lovell/sharp/issues/2460)
|
||||||
|
|
||||||
|
* Linux (musl): Prevent use of prebuilt linuxmusl-x64 binaries with musl >= 1.2.0.
|
||||||
|
[#2570](https://github.com/lovell/sharp/issues/2570)
|
||||||
|
|
||||||
|
* Improve 16-bit grey+alpha support by using libvips' `has_alpha` detection.
|
||||||
|
[#2569](https://github.com/lovell/sharp/issues/2569)
|
||||||
|
|
||||||
|
* Allow the use of non lower case extensions with `toFormat`.
|
||||||
|
[#2581](https://github.com/lovell/sharp/pull/2581)
|
||||||
|
[@florian-busch](https://github.com/florian-busch)
|
||||||
|
|
||||||
|
* Allow use of `recomb` operation with single channel input.
|
||||||
|
[#2584](https://github.com/lovell/sharp/issues/2584)
|
||||||
|
|
||||||
|
### v0.27.1 - 27th January 2021
|
||||||
|
|
||||||
|
* Ensure TIFF is cast when using float predictor.
|
||||||
|
[#2502](https://github.com/lovell/sharp/pull/2502)
|
||||||
|
[@randyridge](https://github.com/randyridge)
|
||||||
|
|
||||||
|
* Add support for Uint8Array and Uint8ClampedArray input.
|
||||||
|
[#2511](https://github.com/lovell/sharp/pull/2511)
|
||||||
|
[@leon](https://github.com/leon)
|
||||||
|
|
||||||
|
* Revert: ensure all platforms use fontconfig for font rendering.
|
||||||
|
[#2515](https://github.com/lovell/sharp/issues/2515)
|
||||||
|
|
||||||
|
* Expose libvips gaussnoise operation to allow creation of Gaussian noise.
|
||||||
|
[#2527](https://github.com/lovell/sharp/pull/2527)
|
||||||
|
[@alza54](https://github.com/alza54)
|
||||||
|
|
||||||
|
### v0.27.0 - 22nd December 2020
|
||||||
|
|
||||||
|
* Add support for AVIF to prebuilt binaries.
|
||||||
|
|
||||||
|
* Remove experimental status from `heif` output, defaults are now AVIF-centric.
|
||||||
|
|
||||||
|
* Allow negative top/left offsets for composite operation.
|
||||||
|
[#2391](https://github.com/lovell/sharp/pull/2391)
|
||||||
|
[@CurosMJ](https://github.com/CurosMJ)
|
||||||
|
|
||||||
|
* Ensure all platforms use fontconfig for font rendering.
|
||||||
|
[#2399](https://github.com/lovell/sharp/issues/2399)
|
||||||
|
|
||||||
## v0.26 - *zoom*
|
## v0.26 - *zoom*
|
||||||
|
|
||||||
Requires libvips v8.10.0
|
Requires libvips v8.10.0
|
||||||
|
|
||||||
### v0.26.0 - TBD
|
### v0.26.3 - 16th November 2020
|
||||||
|
|
||||||
|
* Expose libvips' affine operation.
|
||||||
|
[#2336](https://github.com/lovell/sharp/pull/2336)
|
||||||
|
[@guillevc](https://github.com/guillevc)
|
||||||
|
|
||||||
|
* Fallback to tar.gz for prebuilt libvips when Brotli not available.
|
||||||
|
[#2412](https://github.com/lovell/sharp/pull/2412)
|
||||||
|
[@ascorbic](https://github.com/ascorbic)
|
||||||
|
|
||||||
|
### v0.26.2 - 14th October 2020
|
||||||
|
|
||||||
|
* Add support for EXR input. Requires libvips compiled with OpenEXR.
|
||||||
|
[#698](https://github.com/lovell/sharp/issues/698)
|
||||||
|
|
||||||
|
* Ensure support for yarn v2.
|
||||||
|
[#2379](https://github.com/lovell/sharp/pull/2379)
|
||||||
|
[@jalovatt](https://github.com/jalovatt)
|
||||||
|
|
||||||
|
* Add centre/center option to tile-based output.
|
||||||
|
[#2397](https://github.com/lovell/sharp/pull/2397)
|
||||||
|
[@beig](https://github.com/beig)
|
||||||
|
|
||||||
|
### v0.26.1 - 20th September 2020
|
||||||
|
|
||||||
|
* Ensure correct pageHeight when verifying multi-page image dimensions.
|
||||||
|
[#2343](https://github.com/lovell/sharp/pull/2343)
|
||||||
|
[@derom](https://github.com/derom)
|
||||||
|
|
||||||
|
* Allow input density range up to 100000 DPI.
|
||||||
|
[#2348](https://github.com/lovell/sharp/pull/2348)
|
||||||
|
[@stefanprobst](https://github.com/stefanprobst)
|
||||||
|
|
||||||
|
* Ensure animation-related properties can be set for Stream-based input.
|
||||||
|
[#2369](https://github.com/lovell/sharp/pull/2369)
|
||||||
|
[@AcrylicShrimp](https://github.com/AcrylicShrimp)
|
||||||
|
|
||||||
|
* Ensure `stats` can be calculated for 1x1 input.
|
||||||
|
[#2372](https://github.com/lovell/sharp/issues/2372)
|
||||||
|
|
||||||
|
* Ensure animated GIF output is optimised.
|
||||||
|
[#2376](https://github.com/lovell/sharp/issues/2376)
|
||||||
|
|
||||||
|
### v0.26.0 - 25th August 2020
|
||||||
|
|
||||||
* Prebuilt libvips binaries are now statically-linked and Brotli-compressed, requiring Node.js 10.16.0+.
|
* Prebuilt libvips binaries are now statically-linked and Brotli-compressed, requiring Node.js 10.16.0+.
|
||||||
|
|
||||||
@@ -27,6 +241,10 @@ Requires libvips v8.10.0
|
|||||||
[#2259](https://github.com/lovell/sharp/pull/2259)
|
[#2259](https://github.com/lovell/sharp/pull/2259)
|
||||||
[@vouillon](https://github.com/vouillon)
|
[@vouillon](https://github.com/vouillon)
|
||||||
|
|
||||||
|
* Add support to `withMetadata` for custom ICC profile.
|
||||||
|
[#2271](https://github.com/lovell/sharp/pull/2271)
|
||||||
|
[@roborourke](https://github.com/roborourke)
|
||||||
|
|
||||||
* Ensure prebuilt binaries for ARM default to v7 when using Electron.
|
* Ensure prebuilt binaries for ARM default to v7 when using Electron.
|
||||||
[#2292](https://github.com/lovell/sharp/pull/2292)
|
[#2292](https://github.com/lovell/sharp/pull/2292)
|
||||||
[@diegodev3](https://github.com/diegodev3)
|
[@diegodev3](https://github.com/diegodev3)
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
"public": ".",
|
"public": ".",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
".*",
|
".*",
|
||||||
|
"build.js",
|
||||||
"firebase.json",
|
"firebase.json",
|
||||||
"*.md",
|
|
||||||
"image/**",
|
"image/**",
|
||||||
"search-index/**"
|
"search-index/**"
|
||||||
],
|
],
|
||||||
@@ -13,10 +13,9 @@
|
|||||||
{
|
{
|
||||||
"source": "**",
|
"source": "**",
|
||||||
"headers": [
|
"headers": [
|
||||||
{
|
{ "key": "Cache-Control", "value": "max-age=86400" },
|
||||||
"key": "Cache-Control",
|
{ "key": "X-Content-Type-Options", "value": "nosniff" },
|
||||||
"value": "max-age=86400"
|
{ "key": "X-Frame-Options", "value": "SAMEORIGIN" }
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -194,3 +194,27 @@ GitHub: https://github.com/vouillon
|
|||||||
|
|
||||||
Name: Tomáš Szabo
|
Name: Tomáš Szabo
|
||||||
GitHub: https://github.com/deftomat
|
GitHub: https://github.com/deftomat
|
||||||
|
|
||||||
|
Name: Robert O'Rourke
|
||||||
|
GitHub: https://github.com/roborourke
|
||||||
|
|
||||||
|
Name: Denis Soldatov
|
||||||
|
GitHub: https://github.com/derom
|
||||||
|
|
||||||
|
Name: Stefan Probst
|
||||||
|
GitHub: https://github.com/stefanprobst
|
||||||
|
|
||||||
|
Name: Thomas Beiganz
|
||||||
|
GitHub: https://github.com/beig
|
||||||
|
|
||||||
|
Name: Florian Busch
|
||||||
|
GitHub: https://github.com/florian-busch
|
||||||
|
|
||||||
|
Name: Matthieu Salettes
|
||||||
|
GitHub: https://github.com/msalettes
|
||||||
|
|
||||||
|
Name: Taneli Vatanen
|
||||||
|
GitHub: https://github.com/Daiz
|
||||||
|
|
||||||
|
Name: Mart Jansink
|
||||||
|
GitHub: https://github.com/mart-jansink
|
||||||
|
|||||||
11
docs/image/sharp-logo-mono.svg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||||
|
<!-- Creative Commons CC0 1.0 Universal Public Domain Dedication -->
|
||||||
|
<defs>
|
||||||
|
<mask id="c">
|
||||||
|
<path fill="none" stroke="#fff" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66m.001 0V238.484m0-150.121v171.572l178.725-23.917m-359.843 19.584V477.22m2.387 156.95V462.591L93.984 486.515"/>
|
||||||
|
<path fill="none" stroke="#000" stroke-width="112" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||||
|
</mask>
|
||||||
|
</defs>
|
||||||
|
<path mask="url(#c)" fill="none" stroke="#000" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66m.001 0V238.484m0-150.121v171.572l178.725-23.917m-359.843 19.584V477.22m2.387 156.95V462.591L93.984 486.515"/>
|
||||||
|
<path fill="none" stroke="#000" stroke-width="80" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 929 B |
@@ -1,5 +1,5 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||||
<!-- Copyright 2019 Lovell Fuller. This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License. -->
|
<!-- 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="#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"/>
|
<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>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 592 B After Width: | Height: | Size: 508 B |
@@ -4,11 +4,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<meta name="description" content="Resize large images in common formats to smaller, web-friendly JPEG, PNG and WebP images of varying dimensions">
|
<meta name="description" content="Resize large images in common formats to smaller, web-friendly JPEG, PNG, WebP and AVIF images of varying dimensions">
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; object-src 'none'; style-src 'unsafe-inline';
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; object-src 'none'; style-src 'unsafe-inline';
|
||||||
img-src 'unsafe-inline' data: https://pixel.plumbing/px/ https://cdn.jsdelivr.net/gh/lovell/ https://www.google-analytics.com;
|
img-src 'unsafe-inline' data: https://pixel.plumbing/px/ https://cdn.jsdelivr.net/gh/lovell/ https://www.google-analytics.com;
|
||||||
connect-src 'self' https://cdn.jsdelivr.net/gh/lovell/ https://www.google-analytics.com;
|
connect-src 'self' https://www.google-analytics.com;
|
||||||
script-src 'sha256-iXDHv+t2aGdJcmEvwHfqmGH4SrOSx+P8rCF6+WLLwXA=' 'unsafe-eval'
|
script-src 'unsafe-inline' 'unsafe-eval'
|
||||||
https://cdn.jsdelivr.net/npm/docute@4/dist/docute.min.js
|
https://cdn.jsdelivr.net/npm/docute@4/dist/docute.min.js
|
||||||
https://www.google-analytics.com/analytics.js;">
|
https://www.google-analytics.com/analytics.js;">
|
||||||
<link rel="icon" type="image/png" href="https://pixel.plumbing/px/32x32/sharp-logo.svg">
|
<link rel="icon" type="image/png" href="https://pixel.plumbing/px/32x32/sharp-logo.svg">
|
||||||
@@ -19,8 +19,6 @@
|
|||||||
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="https://pixel.plumbing/px/72x72/sharp-logo.svg">
|
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="https://pixel.plumbing/px/72x72/sharp-logo.svg">
|
||||||
<link rel="apple-touch-icon-precomposed" href="https://pixel.plumbing/px/57x57/sharp-logo.svg">
|
<link rel="apple-touch-icon-precomposed" href="https://pixel.plumbing/px/57x57/sharp-logo.svg">
|
||||||
<link rel="author" href="/humans.txt" type="text/plain">
|
<link rel="author" href="/humans.txt" type="text/plain">
|
||||||
<link rel="preload" href="https://cdn.jsdelivr.net/gh/lovell/sharp@v0.25.4/docs/README.md" as="fetch" type="text/markdown" crossorigin>
|
|
||||||
<link rel="preload" href="https://cdn.jsdelivr.net/gh/lovell/sharp@master/docs/image/sharp-logo.svg" as="image" type="image/svg+xml" crossorigin>
|
|
||||||
<link rel="dns-prefetch" href="https://pixel.plumbing">
|
<link rel="dns-prefetch" href="https://pixel.plumbing">
|
||||||
<link rel="dns-prefetch" href="https://www.google-analytics.com">
|
<link rel="dns-prefetch" href="https://www.google-analytics.com">
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
@@ -38,7 +36,7 @@
|
|||||||
"@type": "Person",
|
"@type": "Person",
|
||||||
"name": "Lovell Fuller"
|
"name": "Lovell Fuller"
|
||||||
},
|
},
|
||||||
"copyrightYear": [2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020],
|
"copyrightYear": [2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021],
|
||||||
"license": "https://www.apache.org/licenses/LICENSE-2.0"
|
"license": "https://www.apache.org/licenses/LICENSE-2.0"
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -105,7 +103,7 @@
|
|||||||
.then(function (entries) {
|
.then(function (entries) {
|
||||||
const results = [];
|
const results = [];
|
||||||
entries.forEach(function (entry) {
|
entries.forEach(function (entry) {
|
||||||
if (entry.k.includes(keyword)) {
|
if (entry.k.includes(keyword.trim().toLowerCase())) {
|
||||||
results.push({
|
results.push({
|
||||||
title: entry.t,
|
title: entry.t,
|
||||||
link: entry.l,
|
link: entry.l,
|
||||||
@@ -139,7 +137,6 @@
|
|||||||
docuteApiTitlePlugin,
|
docuteApiTitlePlugin,
|
||||||
docuteApiSearchPlugin
|
docuteApiSearchPlugin
|
||||||
],
|
],
|
||||||
sourcePath: 'https://cdn.jsdelivr.net/gh/lovell/sharp@v0.25.4/docs',
|
|
||||||
nav: [
|
nav: [
|
||||||
{
|
{
|
||||||
title: 'Funding',
|
title: 'Funding',
|
||||||
|
|||||||
133
docs/install.md
@@ -10,34 +10,36 @@ yarn add sharp
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* Node.js v10.16.0+
|
* Node.js >= 12.13.0
|
||||||
|
|
||||||
## Prebuilt binaries
|
## Prebuilt binaries
|
||||||
|
|
||||||
Ready-compiled sharp and libvips binaries are provided for use with
|
Ready-compiled sharp and libvips binaries are provided for use on the most common platforms:
|
||||||
Node.js v10.16.0+ on the most common platforms:
|
|
||||||
|
|
||||||
* macOS x64 (>= 10.13)
|
* macOS x64 (>= 10.13)
|
||||||
|
* macOS ARM64
|
||||||
* Linux x64 (glibc >= 2.17, musl >= 1.1.24)
|
* Linux x64 (glibc >= 2.17, musl >= 1.1.24)
|
||||||
* Linux ARM64 (glibc >= 2.29)
|
* Linux ARM64 (glibc >= 2.29, musl >= 1.1.24)
|
||||||
* Windows
|
* Windows x64
|
||||||
|
* Windows x86
|
||||||
|
|
||||||
A ~7MB tarball containing libvips and its most commonly used dependencies
|
An ~7MB tarball containing libvips and its most commonly used dependencies
|
||||||
is downloaded via HTTPS and stored within `node_modules/sharp/vendor` during `npm install`.
|
is downloaded via HTTPS and stored within `node_modules/sharp/vendor` during `npm install`.
|
||||||
|
|
||||||
This provides support for the
|
This provides support for the
|
||||||
JPEG, PNG, WebP, TIFF, GIF (input) and SVG (input) image formats.
|
JPEG, PNG, WebP, AVIF, TIFF, GIF (input) and SVG (input) image formats.
|
||||||
|
|
||||||
The following platforms have prebuilt libvips but not sharp:
|
The following platforms have prebuilt libvips but not sharp:
|
||||||
|
|
||||||
* Linux ARMv6
|
* Linux ARMv6
|
||||||
* Linux ARMv7 (glibc >= 2.28)
|
* Linux ARMv7 (glibc >= 2.28)
|
||||||
|
* Windows ARM64
|
||||||
|
|
||||||
The following platforms require compilation of both libvips and sharp from source:
|
The following platforms require compilation of both libvips and sharp from source:
|
||||||
|
|
||||||
* Linux x86
|
* Linux x86
|
||||||
* Linux x64 (glibc <= 2.16, includes RHEL/CentOS 6)
|
* Linux x64 (glibc <= 2.16, includes RHEL/CentOS 6)
|
||||||
* Linux ARM64 (glibc <= 2.28, musl)
|
* Linux ARM64 (glibc <= 2.28)
|
||||||
* Linux PowerPC
|
* Linux PowerPC
|
||||||
* FreeBSD
|
* FreeBSD
|
||||||
* OpenBSD
|
* OpenBSD
|
||||||
@@ -46,13 +48,49 @@ The following platforms require compilation of both libvips and sharp from sourc
|
|||||||
|
|
||||||
The architecture and platform of Node.js used for `npm install`
|
The architecture and platform of Node.js used for `npm install`
|
||||||
must be the same as the architecture and platform of Node.js used at runtime.
|
must be the same as the architecture and platform of Node.js used at runtime.
|
||||||
|
See the [cross-platform](#cross-platform) section if this is not the case.
|
||||||
|
|
||||||
The `npm install --unsafe-perm` flag must be used when installing as `root` or a `sudo` user.
|
When using npm v6 or earlier, the `npm install --unsafe-perm` flag must be used when installing as `root` or a `sudo` user.
|
||||||
|
|
||||||
|
When using npm v7, the user running `npm install` must own the directory it is run in.
|
||||||
|
|
||||||
The `npm install --ignore-scripts=false` flag must be used when `npm` has been configured to ignore installation scripts.
|
The `npm install --ignore-scripts=false` flag must be used when `npm` has been configured to ignore installation scripts.
|
||||||
|
|
||||||
Check the output of running `npm install --verbose sharp` for useful error messages.
|
Check the output of running `npm install --verbose sharp` for useful error messages.
|
||||||
|
|
||||||
|
## Apple M1
|
||||||
|
|
||||||
|
Prebuilt sharp and libvips binaries are provided for macOS on ARM64 from sharp v0.29.0.
|
||||||
|
|
||||||
|
Prebuilt libvips binaries were provided for macOS on ARM64 from sharp v0.28.0.
|
||||||
|
|
||||||
|
## Cross-platform
|
||||||
|
|
||||||
|
At `npm install` time, prebuilt binaries are automatically selected for the
|
||||||
|
current OS platform and CPU architecture, where available.
|
||||||
|
|
||||||
|
The target platform and/or architecture can be manually selected using the following flags.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --platform=... --arch=... --arm-version=... sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
* `--platform`: one of `linux`, `linuxmusl`, `darwin` or `win32`.
|
||||||
|
* `--arch`: one of `x64`, `ia32`, `arm` or `arm64`.
|
||||||
|
* `--arm-version`: one of `6`, `7` or `8` (`arm` defaults to `6`, `arm64` defaults to `8`).
|
||||||
|
* `--sharp-install-force`: skip version compatibility checks.
|
||||||
|
|
||||||
|
These values can also be set via environment variables,
|
||||||
|
`npm_config_platform`, `npm_config_arch`, `npm_config_arm_version`
|
||||||
|
and `SHARP_INSTALL_FORCE` respectively.
|
||||||
|
|
||||||
|
For example, if the target machine has a 64-bit ARM CPU and is running Alpine Linux,
|
||||||
|
use the following flags:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --arch=arm64 --platform=linuxmusl sharp
|
||||||
|
```
|
||||||
|
|
||||||
## 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,
|
||||||
@@ -69,7 +107,7 @@ The use of a globally-installed libvips is unsupported on Windows.
|
|||||||
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),
|
* a globally-installed libvips is detected (set the `SHARP_IGNORE_GLOBAL_LIBVIPS` environment variable to skip this),
|
||||||
* prebuilt binaries do not exist for the current platform and Node.js version, or
|
* prebuilt sharp binaries do not exist for the current platform, or
|
||||||
* when the `npm install --build-from-source` flag is used.
|
* when the `npm install --build-from-source` flag is used.
|
||||||
|
|
||||||
Building from source requires:
|
Building from source requires:
|
||||||
@@ -85,12 +123,15 @@ To install the prebuilt sharp binaries from a custom URL,
|
|||||||
set the `sharp_binary_host` npm config option
|
set the `sharp_binary_host` npm config option
|
||||||
or the `npm_config_sharp_binary_host` environment variable.
|
or the `npm_config_sharp_binary_host` environment variable.
|
||||||
|
|
||||||
|
To install the prebuilt sharp binaries from a directory on the local filesystem,
|
||||||
|
set the `sharp_local_prebuilds` npm config option
|
||||||
|
or the `npm_config_sharp_local_prebuilds` environment variable.
|
||||||
|
|
||||||
To install the prebuilt libvips binaries from a custom URL,
|
To install the prebuilt libvips binaries from a custom URL,
|
||||||
set the `sharp_libvips_binary_host` npm config option
|
set the `sharp_libvips_binary_host` npm config option
|
||||||
or the `npm_config_sharp_libvips_binary_host` environment variable.
|
or the `npm_config_sharp_libvips_binary_host` environment variable.
|
||||||
|
|
||||||
The version subpath and file name are appended to these.
|
The version subpath and file name are appended to these.
|
||||||
|
|
||||||
For example, if `sharp_libvips_binary_host` is set to `https://hostname/path`
|
For example, if `sharp_libvips_binary_host` is set to `https://hostname/path`
|
||||||
and the libvips version is `1.2.3` then the resultant URL will be
|
and the libvips version is `1.2.3` then the resultant URL will be
|
||||||
`https://hostname/path/v1.2.3/libvips-1.2.3-platform-arch.tar.br`.
|
`https://hostname/path/v1.2.3/libvips-1.2.3-platform-arch.tar.br`.
|
||||||
@@ -99,7 +140,7 @@ See the Chinese mirror below for a further example.
|
|||||||
|
|
||||||
## Chinese mirror
|
## Chinese mirror
|
||||||
|
|
||||||
Alibaba provide a mirror site based in China containing binaries for both sharp and libvips.
|
A mirror site based in China, provided by Alibaba, contains binaries for both sharp and libvips.
|
||||||
|
|
||||||
To use this either set the following configuration:
|
To use this either set the following configuration:
|
||||||
|
|
||||||
@@ -129,6 +170,23 @@ pkg install -y pkgconf vips
|
|||||||
cd /usr/ports/graphics/vips/ && make install clean
|
cd /usr/ports/graphics/vips/ && make install clean
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Linux memory allocator
|
||||||
|
|
||||||
|
The default memory allocator on most glibc-based Linux systems
|
||||||
|
(e.g. Debian, Red Hat) is unsuitable for long-running, multi-threaded
|
||||||
|
processes that involve lots of small memory allocations.
|
||||||
|
|
||||||
|
For this reason, by default, sharp will limit the use of thread-based
|
||||||
|
[concurrency](api-utility#concurrency) when the glibc allocator is
|
||||||
|
detected at runtime.
|
||||||
|
|
||||||
|
To help avoid fragmentation and improve performance on these systems,
|
||||||
|
the use of an alternative memory allocator such as
|
||||||
|
[jemalloc](https://github.com/jemalloc/jemalloc) is recommended.
|
||||||
|
|
||||||
|
Those using musl-based Linux (e.g. Alpine) and non-Linux systems are
|
||||||
|
unaffected.
|
||||||
|
|
||||||
## Heroku
|
## Heroku
|
||||||
|
|
||||||
Add the
|
Add the
|
||||||
@@ -141,46 +199,49 @@ to `false` when using the `yarn` package manager.
|
|||||||
|
|
||||||
## AWS Lambda
|
## AWS Lambda
|
||||||
|
|
||||||
Set the Lambda runtime to `nodejs12.x`.
|
The `node_modules` directory of the
|
||||||
|
|
||||||
The binaries in the `node_modules` directory of the
|
|
||||||
[deployment package](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html)
|
[deployment package](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html)
|
||||||
must be for the Linux x64 platform.
|
must include binaries for the Linux x64 platform.
|
||||||
|
|
||||||
On machines other than Linux x64, such as macOS and Windows, run the following:
|
When building your deployment package on machines other than Linux x64 (glibc),
|
||||||
|
run the following additional command after `npm install`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
rm -rf node_modules/sharp
|
npm install
|
||||||
npm install --arch=x64 --platform=linux sharp
|
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux sharp
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively a Docker container closely matching the Lambda runtime can be used:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
rm -rf node_modules/sharp
|
|
||||||
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs12.x npm install sharp
|
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
## Electron
|
## Webpack
|
||||||
|
|
||||||
Electron provides versions of the V8 JavaScript engine
|
Ensure sharp is added to the
|
||||||
that are incompatible with Node.js.
|
[externals](https://webpack.js.org/configuration/externals/)
|
||||||
To ensure the correct binaries are used, run the following:
|
configuration.
|
||||||
|
|
||||||
```sh
|
```js
|
||||||
npm install
|
externals: {
|
||||||
npx electron-rebuild
|
'sharp': 'commonjs sharp'
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Further help can be found at
|
|
||||||
[https://electronjs.org/docs/tutorial/using-native-node-modules](https://electronjs.org/docs/tutorial/using-native-node-modules)
|
|
||||||
|
|
||||||
## Worker threads
|
## Worker threads
|
||||||
|
|
||||||
The main thread must call `require('sharp')`
|
The main thread must call `require('sharp')`
|
||||||
before worker threads are created
|
before worker threads are created
|
||||||
to ensure shared libraries remain loaded in memory
|
to ensure shared libraries remain loaded in memory
|
||||||
until after all threads are complete.
|
until after all threads are complete.
|
||||||
|
|
||||||
|
## Known conflicts
|
||||||
|
|
||||||
|
### Canvas and Windows
|
||||||
|
|
||||||
|
The prebuilt binaries provided by `canvas` for Windows depend on the unmaintained GTK 2, last updated in 2011.
|
||||||
|
|
||||||
|
These conflict with the modern, up-to-date binaries provided by sharp.
|
||||||
|
|
||||||
|
If both modules are used in the same Windows process, the following error will occur:
|
||||||
|
```
|
||||||
|
The specified procedure could not be found.
|
||||||
|
```
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ A test to benchmark the performance of this module relative to alternatives.
|
|||||||
|
|
||||||
## The contenders
|
## The contenders
|
||||||
|
|
||||||
* [jimp](https://www.npmjs.com/package/jimp) v0.9.3 - Image processing in pure JavaScript. Provides bicubic interpolation.
|
* [jimp](https://www.npmjs.com/package/jimp) v0.16.1 - Image processing in pure JavaScript. Provides bicubic interpolation.
|
||||||
* [mapnik](https://www.npmjs.org/package/mapnik) v4.3.1 - Whilst primarily a map renderer, Mapnik contains bitmap image utilities.
|
* [mapnik](https://www.npmjs.org/package/mapnik) v4.5.8 - Whilst primarily a map renderer, Mapnik contains bitmap image utilities.
|
||||||
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
||||||
* [gm](https://www.npmjs.com/package/gm) v1.23.1 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
* [gm](https://www.npmjs.com/package/gm) v1.23.1 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
||||||
* sharp v0.24.0 / libvips v8.9.0 - Caching within libvips disabled to ensure a fair comparison.
|
* [@squoosh/lib](https://www.npmjs.com/package/@squoosh/lib) v0.4.0 - Image libraries transpiled to WebAssembly, includes GPLv3 code.
|
||||||
|
* [@squoosh/cli](https://www.npmjs.com/package/@squoosh/cli) v0.7.2 - Command line wrapper around `@squoosh/lib`, avoids GPLv3 by spawning process.
|
||||||
|
* sharp v0.28.0 / libvips v8.10.6 - Caching within libvips disabled to ensure a fair comparison.
|
||||||
|
|
||||||
## The task
|
## The task
|
||||||
|
|
||||||
@@ -18,22 +20,24 @@ then compress to JPEG at a "quality" setting of 80.
|
|||||||
|
|
||||||
## Test environment
|
## Test environment
|
||||||
|
|
||||||
* AWS EC2 eu-west-1 [c5.large](https://aws.amazon.com/ec2/instance-types/c5/) (2x Xeon Platinum 8124M CPU @ 3.00GHz)
|
* AWS EC2 eu-west-1 [c5ad.xlarge](https://aws.amazon.com/ec2/instance-types/c5/) (4x AMD EPYC 7R32)
|
||||||
* Ubuntu 18.04 (hvm-ssd/ubuntu-bionic-18.04-amd64-server-20180912 ami-00035f41c82244dab)
|
* Ubuntu 21.04 (ami-0d7626a9c2ceab1ac)
|
||||||
* Node.js v12.14.1
|
* Node.js 16.6.2
|
||||||
|
|
||||||
## Results
|
## Results
|
||||||
|
|
||||||
| Module | Input | Output | Ops/sec | Speed-up |
|
| Module | Input | Output | Ops/sec | Speed-up |
|
||||||
| :----------------- | :----- | :----- | ------: | -------: |
|
| :----------------- | :----- | :----- | ------: | -------: |
|
||||||
| jimp | buffer | buffer | 0.72 | 1.0 |
|
| jimp | buffer | buffer | 0.83 | 1.0 |
|
||||||
| mapnik | buffer | buffer | 3.02 | 4.2 |
|
| squoosh-cli | file | file | 1.09 | 1.3 |
|
||||||
| gm | buffer | buffer | 3.90 | 5.4 |
|
| squoosh-lib | buffer | buffer | 1.83 | 2.2 |
|
||||||
| gm | file | file | 3.94 | 5.5 |
|
| mapnik | buffer | buffer | 3.41 | 4.1 |
|
||||||
| imagemagick | file | file | 4.30 | 6.0 |
|
| gm | buffer | buffer | 8.34 | 10.0 |
|
||||||
| sharp | stream | stream | 23.65 | 32.8 |
|
| imagemagick | file | file | 8.67 | 10.4 |
|
||||||
| sharp | file | file | 24.66 | 34.3 |
|
| gm | file | file | 8.82 | 10.6 |
|
||||||
| sharp | buffer | buffer | 25.14 | 34.9 |
|
| sharp | stream | stream | 29.44 | 35.5 |
|
||||||
|
| sharp | file | file | 29.64 | 35.7 |
|
||||||
|
| sharp | buffer | buffer | 31.09 | 37.5 |
|
||||||
|
|
||||||
Greater libvips performance can be expected with caching enabled (default)
|
Greater libvips performance can be expected with caching enabled (default)
|
||||||
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
||||||
@@ -51,7 +55,7 @@ brew install mapnik
|
|||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo apt-get install imagemagick libmagick++-dev graphicsmagick libmapnik-dev
|
sudo apt-get install build-essential imagemagick libmagick++-dev graphicsmagick libmapnik-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -61,7 +65,7 @@ sudo yum install ImageMagick-devel ImageMagick-c++-devel GraphicsMagick mapnik-d
|
|||||||
```sh
|
```sh
|
||||||
git clone https://github.com/lovell/sharp.git
|
git clone https://github.com/lovell/sharp.git
|
||||||
cd sharp
|
cd sharp
|
||||||
npm install
|
npm install --build-from-source
|
||||||
cd test/bench
|
cd test/bench
|
||||||
npm install
|
npm install
|
||||||
npm test
|
npm test
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { extractDescription, extractKeywords } = require('./extract');
|
const path = require('path');
|
||||||
|
const { extractDescription, extractKeywords, extractParameters } = require('./extract');
|
||||||
|
|
||||||
const searchIndex = [];
|
const searchIndex = [];
|
||||||
|
|
||||||
// Install
|
// Install
|
||||||
const contents = fs.readFileSync(`${__dirname}/../install.md`, 'utf8');
|
const contents = fs.readFileSync(path.join(__dirname, '..', 'install.md'), 'utf8');
|
||||||
const matches = contents.matchAll(
|
const matches = contents.matchAll(
|
||||||
/## (?<title>[A-Za-z ]+)\n\n(?<body>[^#]+)/gs
|
/## (?<title>[A-Za-z0-9 ]+)\n\n(?<body>[^#]+)/gs
|
||||||
);
|
);
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const { title, body } = match.groups;
|
const { title, body } = match.groups;
|
||||||
@@ -34,26 +35,27 @@ for (const match of matches) {
|
|||||||
'colour',
|
'colour',
|
||||||
'utility'
|
'utility'
|
||||||
].forEach((section) => {
|
].forEach((section) => {
|
||||||
const contents = fs.readFileSync(`${__dirname}/../api-${section}.md`, 'utf8');
|
const contents = fs.readFileSync(path.join(__dirname, '..', `api-${section}.md`), 'utf8');
|
||||||
const matches = contents.matchAll(
|
const matches = contents.matchAll(
|
||||||
/\n## (?<title>[A-Za-z]+)\n\n(?<firstparagraph>.+?)\n\n/gs
|
/\n## (?<title>[A-Za-z]+)\n\n(?<firstparagraph>.+?)\n\n(?<parameters>### Parameters.+?Returns)?/gs
|
||||||
);
|
);
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const { title, firstparagraph } = match.groups;
|
const { title, firstparagraph, parameters } = match.groups;
|
||||||
const description = firstparagraph.startsWith('###')
|
const description = firstparagraph.startsWith('###')
|
||||||
? 'Constructor'
|
? 'Constructor'
|
||||||
: extractDescription(firstparagraph);
|
: extractDescription(firstparagraph);
|
||||||
|
const parameterNames = parameters ? extractParameters(parameters) : '';
|
||||||
|
|
||||||
searchIndex.push({
|
searchIndex.push({
|
||||||
t: title,
|
t: title,
|
||||||
d: description,
|
d: description,
|
||||||
k: extractKeywords(`${title} ${description}`),
|
k: extractKeywords(`${title} ${description} ${parameterNames}`),
|
||||||
l: `/api-${section}#${title.toLowerCase()}`
|
l: `/api-${section}#${title.toLowerCase()}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
`${__dirname}/../search-index.json`,
|
path.join(__dirname, '..', 'search-index.json'),
|
||||||
JSON.stringify(searchIndex)
|
JSON.stringify(searchIndex)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,80 +1,30 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const stopWords = [
|
const stopWords = require('./stop-words');
|
||||||
'a',
|
|
||||||
'about',
|
|
||||||
'all',
|
|
||||||
'already',
|
|
||||||
'always',
|
|
||||||
'an',
|
|
||||||
'and',
|
|
||||||
'any',
|
|
||||||
'are',
|
|
||||||
'as',
|
|
||||||
'at',
|
|
||||||
'be',
|
|
||||||
'been',
|
|
||||||
'by',
|
|
||||||
'can',
|
|
||||||
'do',
|
|
||||||
'does',
|
|
||||||
'each',
|
|
||||||
'either',
|
|
||||||
'etc',
|
|
||||||
'for',
|
|
||||||
'from',
|
|
||||||
'get',
|
|
||||||
'gets',
|
|
||||||
'has',
|
|
||||||
'have',
|
|
||||||
'how',
|
|
||||||
'if',
|
|
||||||
'in',
|
|
||||||
'is',
|
|
||||||
'it',
|
|
||||||
'its',
|
|
||||||
'may',
|
|
||||||
'more',
|
|
||||||
'much',
|
|
||||||
'no',
|
|
||||||
'not',
|
|
||||||
'of',
|
|
||||||
'on',
|
|
||||||
'or',
|
|
||||||
'over',
|
|
||||||
'set',
|
|
||||||
'sets',
|
|
||||||
'should',
|
|
||||||
'that',
|
|
||||||
'the',
|
|
||||||
'their',
|
|
||||||
'there',
|
|
||||||
'therefore',
|
|
||||||
'these',
|
|
||||||
'this',
|
|
||||||
'to',
|
|
||||||
'use',
|
|
||||||
'using',
|
|
||||||
'when',
|
|
||||||
'which',
|
|
||||||
'will',
|
|
||||||
'with'
|
|
||||||
];
|
|
||||||
|
|
||||||
const extractDescription = (str) =>
|
const extractDescription = (str) =>
|
||||||
str
|
str
|
||||||
|
.replace(/### Examples.*/sg, '')
|
||||||
.replace(/\(http[^)]+/g, '')
|
.replace(/\(http[^)]+/g, '')
|
||||||
.replace(/\s+/g, ' ')
|
.replace(/\s+/g, ' ')
|
||||||
.replace(/[^A-Za-z0-9_/\-,. ]/g, '')
|
.replace(/[^A-Za-z0-9_/\-,. ]/g, '')
|
||||||
.replace(/\s+/g, ' ')
|
.replace(/\s+/g, ' ')
|
||||||
.substr(0, 140)
|
.substr(0, 180)
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
const extractKeywords = (str) =>
|
const extractParameters = (str) =>
|
||||||
str
|
[...str.matchAll(/options\.(?<name>[^.`]+)/gs)]
|
||||||
.split(/[ -/]/)
|
.map((match) => match.groups.name)
|
||||||
.map((word) => word.toLowerCase().replace(/[^a-z]/g, ''))
|
|
||||||
.filter((word) => word.length > 2 && !stopWords.includes(word))
|
|
||||||
.join(' ');
|
.join(' ');
|
||||||
|
|
||||||
module.exports = { extractDescription, extractKeywords };
|
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 };
|
||||||
|
|||||||
100
docs/search-index/stop-words.js
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
'about',
|
||||||
|
'after',
|
||||||
|
'all',
|
||||||
|
'allows',
|
||||||
|
'already',
|
||||||
|
'also',
|
||||||
|
'alternative',
|
||||||
|
'always',
|
||||||
|
'and',
|
||||||
|
'any',
|
||||||
|
'are',
|
||||||
|
'based',
|
||||||
|
'been',
|
||||||
|
'before',
|
||||||
|
'both',
|
||||||
|
'call',
|
||||||
|
'callback',
|
||||||
|
'can',
|
||||||
|
'containing',
|
||||||
|
'default',
|
||||||
|
'does',
|
||||||
|
'each',
|
||||||
|
'either',
|
||||||
|
'ensure',
|
||||||
|
'etc',
|
||||||
|
'every',
|
||||||
|
'except',
|
||||||
|
'for',
|
||||||
|
'from',
|
||||||
|
'get',
|
||||||
|
'gets',
|
||||||
|
'given',
|
||||||
|
'has',
|
||||||
|
'have',
|
||||||
|
'how',
|
||||||
|
'image',
|
||||||
|
'involve',
|
||||||
|
'its',
|
||||||
|
'least',
|
||||||
|
'lots',
|
||||||
|
'may',
|
||||||
|
'more',
|
||||||
|
'most',
|
||||||
|
'much',
|
||||||
|
'must',
|
||||||
|
'non',
|
||||||
|
'not',
|
||||||
|
'occur',
|
||||||
|
'occurs',
|
||||||
|
'options',
|
||||||
|
'other',
|
||||||
|
'out',
|
||||||
|
'over',
|
||||||
|
'perform',
|
||||||
|
'performs',
|
||||||
|
'provide',
|
||||||
|
'provided',
|
||||||
|
'ready',
|
||||||
|
'requires',
|
||||||
|
'returned',
|
||||||
|
'same',
|
||||||
|
'see',
|
||||||
|
'set',
|
||||||
|
'sets',
|
||||||
|
'should',
|
||||||
|
'since',
|
||||||
|
'spelling',
|
||||||
|
'such',
|
||||||
|
'support',
|
||||||
|
'supported',
|
||||||
|
'sure',
|
||||||
|
'take',
|
||||||
|
'than',
|
||||||
|
'that',
|
||||||
|
'the',
|
||||||
|
'their',
|
||||||
|
'then',
|
||||||
|
'there',
|
||||||
|
'therefore',
|
||||||
|
'these',
|
||||||
|
'this',
|
||||||
|
'under',
|
||||||
|
'unless',
|
||||||
|
'until',
|
||||||
|
'use',
|
||||||
|
'used',
|
||||||
|
'using',
|
||||||
|
'value',
|
||||||
|
'values',
|
||||||
|
'when',
|
||||||
|
'which',
|
||||||
|
'while',
|
||||||
|
'will',
|
||||||
|
'with',
|
||||||
|
'without',
|
||||||
|
'you'
|
||||||
|
];
|
||||||
11
install/can-compile.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const libvips = require('../lib/libvips');
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!(libvips.useGlobalLibvips() || libvips.hasVendoredLibvips())) {
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
||||||
@@ -4,21 +4,20 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
const npmLog = require('npmlog');
|
const platform = require('../lib/platform');
|
||||||
|
|
||||||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||||
|
|
||||||
const platform = process.env.npm_config_platform || process.platform;
|
const platformAndArch = platform();
|
||||||
if (platform === 'win32') {
|
|
||||||
const buildDir = path.join(__dirname, '..', 'build');
|
if (platformAndArch.startsWith('win32')) {
|
||||||
const buildReleaseDir = path.join(buildDir, 'Release');
|
const buildReleaseDir = path.join(__dirname, '..', 'build', 'Release');
|
||||||
npmLog.info('sharp', `Creating ${buildReleaseDir}`);
|
libvips.log(`Creating ${buildReleaseDir}`);
|
||||||
try {
|
try {
|
||||||
libvips.mkdirSync(buildDir);
|
|
||||||
libvips.mkdirSync(buildReleaseDir);
|
libvips.mkdirSync(buildReleaseDir);
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, 'lib');
|
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch, 'lib');
|
||||||
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
libvips.log(`Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
||||||
try {
|
try {
|
||||||
fs
|
fs
|
||||||
.readdirSync(vendorLibDir)
|
.readdirSync(vendorLibDir)
|
||||||
@@ -32,6 +31,7 @@ if (platform === 'win32') {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
npmLog.error('sharp', err.message);
|
libvips.log(err);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ const stream = require('stream');
|
|||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
const npmLog = require('npmlog');
|
const semverLessThan = require('semver/functions/lt');
|
||||||
const semver = require('semver');
|
const semverSatisfies = require('semver/functions/satisfies');
|
||||||
const simpleGet = require('simple-get');
|
const simpleGet = require('simple-get');
|
||||||
const tarFs = require('tar-fs');
|
const tarFs = require('tar-fs');
|
||||||
|
|
||||||
@@ -22,33 +22,56 @@ const minimumGlibcVersionByArch = {
|
|||||||
x64: '2.17'
|
x64: '2.17'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasSharpPrebuild = [
|
||||||
|
'darwin-x64',
|
||||||
|
'darwin-arm64',
|
||||||
|
'linux-arm64',
|
||||||
|
'linux-x64',
|
||||||
|
'linuxmusl-x64',
|
||||||
|
'linuxmusl-arm64',
|
||||||
|
'win32-ia32',
|
||||||
|
'win32-x64'
|
||||||
|
];
|
||||||
|
|
||||||
const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
|
const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
|
||||||
const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download';
|
const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download';
|
||||||
const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`;
|
const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`;
|
||||||
|
const installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE);
|
||||||
|
|
||||||
const fail = function (err) {
|
const fail = function (err) {
|
||||||
npmLog.error('sharp', err.message);
|
libvips.log(err);
|
||||||
if (err.code === 'EACCES') {
|
if (err.code === 'EACCES') {
|
||||||
npmLog.info('sharp', 'Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag');
|
libvips.log('Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag');
|
||||||
}
|
}
|
||||||
npmLog.info('sharp', 'Attempting to build from source via node-gyp but this may fail due to the above error');
|
libvips.log('Please see https://sharp.pixelplumbing.com/install for required dependencies');
|
||||||
npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/install for required dependencies');
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractTarball = function (tarPath) {
|
const handleError = function (err) {
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
if (installationForced) {
|
||||||
libvips.mkdirSync(vendorPath);
|
libvips.log(`Installation warning: ${err.message}`);
|
||||||
const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion);
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const extractTarball = function (tarPath, platformAndArch) {
|
||||||
|
const versionedVendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platformAndArch);
|
||||||
libvips.mkdirSync(versionedVendorPath);
|
libvips.mkdirSync(versionedVendorPath);
|
||||||
|
|
||||||
|
const ignoreVendorInclude = hasSharpPrebuild.includes(platformAndArch) && !process.env.npm_config_build_from_source;
|
||||||
|
const ignore = function (name) {
|
||||||
|
return ignoreVendorInclude && name.includes('include/');
|
||||||
|
};
|
||||||
|
|
||||||
stream.pipeline(
|
stream.pipeline(
|
||||||
fs.createReadStream(tarPath),
|
fs.createReadStream(tarPath),
|
||||||
new zlib.BrotliDecompress(),
|
new zlib.BrotliDecompress(),
|
||||||
tarFs.extract(versionedVendorPath),
|
tarFs.extract(versionedVendorPath, { ignore }),
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (/unexpected end of file/.test(err.message)) {
|
if (/unexpected end of file/.test(err.message)) {
|
||||||
npmLog.error('sharp', `Please delete ${tarPath} as it is not a valid tarball`);
|
fail(new Error(`Please delete ${tarPath} as it is not a valid tarball`));
|
||||||
}
|
}
|
||||||
fail(err);
|
fail(err);
|
||||||
}
|
}
|
||||||
@@ -58,13 +81,14 @@ const extractTarball = function (tarPath) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const useGlobalLibvips = libvips.useGlobalLibvips();
|
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||||
|
|
||||||
if (useGlobalLibvips) {
|
if (useGlobalLibvips) {
|
||||||
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
||||||
npmLog.info('sharp', `Detected globally-installed libvips v${globalLibvipsVersion}`);
|
libvips.log(`Detected globally-installed libvips v${globalLibvipsVersion}`);
|
||||||
npmLog.info('sharp', 'Building from source via node-gyp');
|
libvips.log('Building from source via node-gyp');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if (libvips.hasVendoredLibvips()) {
|
} else if (libvips.hasVendoredLibvips()) {
|
||||||
npmLog.info('sharp', `Using existing vendored libvips v${minimumLibvipsVersion}`);
|
libvips.log(`Using existing vendored libvips v${minimumLibvipsVersion}`);
|
||||||
} else {
|
} else {
|
||||||
// Is this arch/platform supported?
|
// Is this arch/platform supported?
|
||||||
const arch = process.env.npm_config_arch || process.arch;
|
const arch = process.env.npm_config_arch || process.arch;
|
||||||
@@ -72,25 +96,38 @@ try {
|
|||||||
if (arch === 'ia32' && !platformAndArch.startsWith('win32')) {
|
if (arch === 'ia32' && !platformAndArch.startsWith('win32')) {
|
||||||
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
|
if (platformAndArch === 'darwin-arm64') {
|
||||||
|
throw new Error("Please run 'brew install vips' to install libvips on Apple M1 (ARM64) systems");
|
||||||
|
}
|
||||||
if (platformAndArch === 'freebsd-x64' || platformAndArch === 'openbsd-x64' || platformAndArch === 'sunos-x64') {
|
if (platformAndArch === 'freebsd-x64' || platformAndArch === 'openbsd-x64' || platformAndArch === 'sunos-x64') {
|
||||||
throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version) {
|
// Linux libc version check
|
||||||
if (semver.lt(`${detectLibc.version}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) {
|
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && minimumGlibcVersionByArch[arch]) {
|
||||||
throw new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
if (semverLessThan(`${detectLibc.version}.0`, `${minimumGlibcVersionByArch[arch]}.0`)) {
|
||||||
|
handleError(new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (detectLibc.family === detectLibc.MUSL && detectLibc.version) {
|
||||||
|
if (semverLessThan(detectLibc.version, '1.1.24')) {
|
||||||
|
handleError(new Error(`Use with musl ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Node.js minimum version check
|
||||||
|
const supportedNodeVersion = process.env.npm_package_engines_node || require('../package.json').engines.node;
|
||||||
|
if (!semverSatisfies(process.versions.node, supportedNodeVersion)) {
|
||||||
|
handleError(new Error(`Expected Node.js version ${supportedNodeVersion} but found ${process.versions.node}`));
|
||||||
|
}
|
||||||
|
|
||||||
// Download to per-process temporary file
|
// Download to per-process temporary file
|
||||||
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.br';
|
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.br';
|
||||||
const tarPathCache = path.join(libvips.cachePath(), tarFilename);
|
const tarPathCache = path.join(libvips.cachePath(), tarFilename);
|
||||||
if (fs.existsSync(tarPathCache)) {
|
if (fs.existsSync(tarPathCache)) {
|
||||||
npmLog.info('sharp', `Using cached ${tarPathCache}`);
|
libvips.log(`Using cached ${tarPathCache}`);
|
||||||
extractTarball(tarPathCache);
|
extractTarball(tarPathCache, platformAndArch);
|
||||||
} else {
|
} else {
|
||||||
const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`);
|
|
||||||
const tmpFile = fs.createWriteStream(tarPathTemp);
|
|
||||||
const url = distBaseUrl + tarFilename;
|
const url = distBaseUrl + tarFilename;
|
||||||
npmLog.info('sharp', `Downloading ${url}`);
|
libvips.log(`Downloading ${url}`);
|
||||||
simpleGet({ url: url, agent: agent() }, function (err, response) {
|
simpleGet({ url: url, agent: agent() }, function (err, response) {
|
||||||
if (err) {
|
if (err) {
|
||||||
fail(err);
|
fail(err);
|
||||||
@@ -99,24 +136,39 @@ try {
|
|||||||
} else if (response.statusCode !== 200) {
|
} else if (response.statusCode !== 200) {
|
||||||
fail(new Error(`Status ${response.statusCode} ${response.statusMessage}`));
|
fail(new Error(`Status ${response.statusCode} ${response.statusMessage}`));
|
||||||
} else {
|
} else {
|
||||||
|
const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`);
|
||||||
|
const tmpFileStream = fs.createWriteStream(tarPathTemp);
|
||||||
response
|
response
|
||||||
.on('error', fail)
|
.on('error', function (err) {
|
||||||
.pipe(tmpFile);
|
tmpFileStream.destroy(err);
|
||||||
|
})
|
||||||
|
.on('close', function () {
|
||||||
|
if (!response.complete) {
|
||||||
|
tmpFileStream.destroy(new Error('Download incomplete (connection was terminated)'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.pipe(tmpFileStream);
|
||||||
|
tmpFileStream
|
||||||
|
.on('error', function (err) {
|
||||||
|
// Clean up temporary file
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(tarPathTemp);
|
||||||
|
} catch (e) {}
|
||||||
|
fail(err);
|
||||||
|
})
|
||||||
|
.on('close', function () {
|
||||||
|
try {
|
||||||
|
// Attempt to rename
|
||||||
|
fs.renameSync(tarPathTemp, tarPathCache);
|
||||||
|
} catch (err) {
|
||||||
|
// Fall back to copy and unlink
|
||||||
|
fs.copyFileSync(tarPathTemp, tarPathCache);
|
||||||
|
fs.unlinkSync(tarPathTemp);
|
||||||
|
}
|
||||||
|
extractTarball(tarPathCache, platformAndArch);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tmpFile
|
|
||||||
.on('error', fail)
|
|
||||||
.on('close', function () {
|
|
||||||
try {
|
|
||||||
// Attempt to rename
|
|
||||||
fs.renameSync(tarPathTemp, tarPathCache);
|
|
||||||
} catch (err) {
|
|
||||||
// Fall back to copy and unlink
|
|
||||||
fs.copyFileSync(tarPathTemp, tarPathCache);
|
|
||||||
fs.unlinkSync(tarPathTemp);
|
|
||||||
}
|
|
||||||
extractTarball(tarPathCache);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const { execFileSync } = require('child_process');
|
|
||||||
|
|
||||||
const { prebuild_upload: hasToken, APPVEYOR_REPO_TAG_NAME, TRAVIS_TAG } = process.env;
|
|
||||||
|
|
||||||
if (hasToken && (APPVEYOR_REPO_TAG_NAME || TRAVIS_TAG)) {
|
|
||||||
execFileSync('prebuild', ['--runtime', 'napi', '--target', '3'], { stdio: 'inherit' });
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@ module.exports = function () {
|
|||||||
? tunnelAgent.httpsOverHttps
|
? tunnelAgent.httpsOverHttps
|
||||||
: tunnelAgent.httpsOverHttp;
|
: tunnelAgent.httpsOverHttp;
|
||||||
const proxyAuth = proxy.username && proxy.password
|
const proxyAuth = proxy.username && proxy.password
|
||||||
? `${proxy.username}:${proxy.password}`
|
? `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`
|
||||||
: null;
|
: null;
|
||||||
return tunnel({
|
return tunnel({
|
||||||
proxy: {
|
proxy: {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const bool = {
|
|||||||
/**
|
/**
|
||||||
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
*
|
*
|
||||||
|
* See also {@link /api-operation#flatten|flatten}.
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('rgba.png')
|
* sharp('rgba.png')
|
||||||
* .removeAlpha()
|
* .removeAlpha()
|
||||||
@@ -30,21 +32,39 @@ function removeAlpha () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
|
* Ensure the output image has an alpha transparency channel.
|
||||||
|
* If missing, the added alpha channel will have the specified
|
||||||
|
* transparency level, defaulting to fully-opaque (1).
|
||||||
|
* This is a no-op if the image already has an alpha channel.
|
||||||
*
|
*
|
||||||
* @since 0.21.2
|
* @since 0.21.2
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('rgb.jpg')
|
* // rgba.png will be a 4 channel image with a fully-opaque alpha channel
|
||||||
|
* await sharp('rgb.jpg')
|
||||||
* .ensureAlpha()
|
* .ensureAlpha()
|
||||||
* .toFile('rgba.png', function(err, info) {
|
* .toFile('rgba.png')
|
||||||
* // rgba.png is a 4 channel image with a fully opaque alpha channel
|
|
||||||
* });
|
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // rgba is a 4 channel image with a fully-transparent alpha channel
|
||||||
|
* const rgba = await sharp(rgb)
|
||||||
|
* .ensureAlpha(0)
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* @param {number} [alpha=1] - alpha transparency level (0=fully-transparent, 1=fully-opaque)
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid alpha transparency level
|
||||||
*/
|
*/
|
||||||
function ensureAlpha () {
|
function ensureAlpha (alpha) {
|
||||||
this.options.ensureAlpha = true;
|
if (is.defined(alpha)) {
|
||||||
|
if (is.number(alpha) && is.inRange(alpha, 0, 1)) {
|
||||||
|
this.options.ensureAlpha = alpha;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('alpha', 'number between 0 and 1', alpha);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.options.ensureAlpha = 1;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,13 +72,17 @@ function ensureAlpha () {
|
|||||||
* Extract a single channel from a multi-channel image.
|
* Extract a single channel from a multi-channel image.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp(input)
|
* // green.jpg is a greyscale image containing the green channel of the input
|
||||||
|
* await sharp(input)
|
||||||
* .extractChannel('green')
|
* .extractChannel('green')
|
||||||
* .toColourspace('b-w')
|
* .toFile('green.jpg');
|
||||||
* .toFile('green.jpg', function(err, info) {
|
*
|
||||||
* // info.channels === 1
|
* @example
|
||||||
* // green.jpg is a greyscale image containing the green channel of the input
|
* // red1 is the red value of the first pixel, red2 the second pixel etc.
|
||||||
* });
|
* const [red1, red2, ...] = await sharp(input)
|
||||||
|
* .extractChannel(0)
|
||||||
|
* .raw()
|
||||||
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
* @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -74,7 +98,7 @@ function extractChannel (channel) {
|
|||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
|
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
|
||||||
}
|
}
|
||||||
return this;
|
return this.toColourspace('b-w');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +109,7 @@ function extractChannel (channel) {
|
|||||||
* - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
* - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
||||||
* - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
* - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
||||||
*
|
*
|
||||||
* Buffers may be any of the image formats supported by sharp: JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data.
|
* Buffers may be any of the image formats supported by sharp.
|
||||||
* For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
* For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
||||||
*
|
*
|
||||||
* @param {Array<string|Buffer>|string|Buffer} images - one or more images (file paths, Buffers).
|
* @param {Array<string|Buffer>|string|Buffer} images - one or more images (file paths, Buffers).
|
||||||
|
|||||||
@@ -54,10 +54,56 @@ function grayscale (grayscale) {
|
|||||||
return this.greyscale(grayscale);
|
return this.greyscale(grayscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pipeline colourspace.
|
||||||
|
*
|
||||||
|
* The input image will be converted to the provided colourspace at the start of the pipeline.
|
||||||
|
* All operations will use this colourspace before converting to the output colourspace, as defined by {@link toColourspace}.
|
||||||
|
*
|
||||||
|
* This feature is experimental and has not yet been fully-tested with all operations.
|
||||||
|
*
|
||||||
|
* @since 0.29.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
|
||||||
|
* await sharp(input)
|
||||||
|
* .pipelineColourspace('rgb16')
|
||||||
|
* .toColourspace('srgb')
|
||||||
|
* .toFile('16bpc-pipeline-to-8bpc-output.png')
|
||||||
|
*
|
||||||
|
* @param {string} [colourspace] - pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774)
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function pipelineColourspace (colourspace) {
|
||||||
|
if (!is.string(colourspace)) {
|
||||||
|
throw is.invalidParameterError('colourspace', 'string', colourspace);
|
||||||
|
}
|
||||||
|
this.options.colourspaceInput = colourspace;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative spelling of `pipelineColourspace`.
|
||||||
|
* @param {string} [colorspace] - pipeline colorspace.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function pipelineColorspace (colorspace) {
|
||||||
|
return this.pipelineColourspace(colorspace);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the output colourspace.
|
* Set the output colourspace.
|
||||||
* By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
* By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||||
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568)
|
*
|
||||||
|
* @example
|
||||||
|
* // Output 16 bits per pixel RGB
|
||||||
|
* await sharp(input)
|
||||||
|
* .toColourspace('rgb16')
|
||||||
|
* .toFile('16-bpp.png')
|
||||||
|
*
|
||||||
|
* @param {string} [colourspace] - output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794)
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -112,6 +158,8 @@ module.exports = function (Sharp) {
|
|||||||
tint,
|
tint,
|
||||||
greyscale,
|
greyscale,
|
||||||
grayscale,
|
grayscale,
|
||||||
|
pipelineColourspace,
|
||||||
|
pipelineColorspace,
|
||||||
toColourspace,
|
toColourspace,
|
||||||
toColorspace,
|
toColorspace,
|
||||||
// Private
|
// Private
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ const blend = {
|
|||||||
* @param {Number} [images[].raw.width]
|
* @param {Number} [images[].raw.width]
|
||||||
* @param {Number} [images[].raw.height]
|
* @param {Number} [images[].raw.height]
|
||||||
* @param {Number} [images[].raw.channels]
|
* @param {Number} [images[].raw.channels]
|
||||||
|
* @param {boolean} [images[].failOnError=true] - @see {@link /api-constructor#parameters|constructor parameters}
|
||||||
|
* @param {number|boolean} [images[].limitInputPixels=268402689] - @see {@link /api-constructor#parameters|constructor parameters}
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -105,8 +107,9 @@ function composite (images) {
|
|||||||
input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }),
|
input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }),
|
||||||
blend: 'over',
|
blend: 'over',
|
||||||
tile: false,
|
tile: false,
|
||||||
left: -1,
|
left: 0,
|
||||||
top: -1,
|
top: 0,
|
||||||
|
hasOffset: false,
|
||||||
gravity: 0,
|
gravity: 0,
|
||||||
premultiplied: false
|
premultiplied: false
|
||||||
};
|
};
|
||||||
@@ -125,21 +128,23 @@ function composite (images) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(image.left)) {
|
if (is.defined(image.left)) {
|
||||||
if (is.integer(image.left) && image.left >= 0) {
|
if (is.integer(image.left)) {
|
||||||
composite.left = image.left;
|
composite.left = image.left;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('left', 'positive integer', image.left);
|
throw is.invalidParameterError('left', 'integer', image.left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(image.top)) {
|
if (is.defined(image.top)) {
|
||||||
if (is.integer(image.top) && image.top >= 0) {
|
if (is.integer(image.top)) {
|
||||||
composite.top = image.top;
|
composite.top = image.top;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('top', 'positive integer', image.top);
|
throw is.invalidParameterError('top', 'integer', image.top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (composite.left !== composite.top && Math.min(composite.left, composite.top) === -1) {
|
if (is.defined(image.top) !== is.defined(image.left)) {
|
||||||
throw new Error('Expected both left and top to be set');
|
throw new Error('Expected both left and top to be set');
|
||||||
|
} else {
|
||||||
|
composite.hasOffset = is.integer(image.top) && is.integer(image.left);
|
||||||
}
|
}
|
||||||
if (is.defined(image.gravity)) {
|
if (is.defined(image.gravity)) {
|
||||||
if (is.integer(image.gravity) && is.inRange(image.gravity, 0, 8)) {
|
if (is.integer(image.gravity) && is.inRange(image.gravity, 0, 8)) {
|
||||||
|
|||||||
@@ -5,34 +5,7 @@ const stream = require('stream');
|
|||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
require('./libvips').hasVendoredLibvips();
|
require('./libvips').hasVendoredLibvips();
|
||||||
|
require('./sharp');
|
||||||
/* istanbul ignore next */
|
|
||||||
try {
|
|
||||||
require('../build/Release/sharp.node');
|
|
||||||
} catch (err) {
|
|
||||||
// Bail early if bindings aren't available
|
|
||||||
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, ''];
|
|
||||||
if (/NODE_MODULE_VERSION/.test(err.message)) {
|
|
||||||
help.push('- Ensure the version of Node.js used at install time matches that used at runtime');
|
|
||||||
} else if (/invalid ELF header/.test(err.message)) {
|
|
||||||
help.push(`- Ensure "${process.platform}" is used at install time as well as runtime`);
|
|
||||||
} else if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
|
|
||||||
help.push('- Run "brew update && brew upgrade vips"');
|
|
||||||
} else if (/Cannot find module/.test(err.message)) {
|
|
||||||
help.push('- Run "npm rebuild --verbose sharp" and look for errors');
|
|
||||||
} else {
|
|
||||||
help.push(
|
|
||||||
'- Remove the "node_modules/sharp" directory then run',
|
|
||||||
' "npm install --ignore-scripts=false --verbose" and look for errors'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
help.push(
|
|
||||||
'- Consult the installation documentation at https://sharp.pixelplumbing.com/install',
|
|
||||||
'- Search for this error at https://github.com/lovell/sharp/issues', ''
|
|
||||||
);
|
|
||||||
const error = help.join('\n');
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use NODE_DEBUG=sharp to enable libvips warnings
|
// Use NODE_DEBUG=sharp to enable libvips warnings
|
||||||
const debuglog = util.debuglog('sharp');
|
const debuglog = util.debuglog('sharp');
|
||||||
@@ -40,7 +13,7 @@ const debuglog = util.debuglog('sharp');
|
|||||||
/**
|
/**
|
||||||
* Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
* Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
||||||
*
|
*
|
||||||
* JPEG, PNG, WebP or TIFF format image data can be streamed out from this object.
|
* JPEG, PNG, WebP, AVIF or TIFF format image data can be streamed out from this object.
|
||||||
* When using Stream based output, derived attributes are available from the `info` event.
|
* When using Stream based output, derived attributes are available from the `info` event.
|
||||||
*
|
*
|
||||||
* Non-critical problems encountered during processing are emitted as `warning` events.
|
* Non-critical problems encountered during processing are emitted as `warning` events.
|
||||||
@@ -86,10 +59,44 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* .toBuffer()
|
* .toBuffer()
|
||||||
* .then( ... );
|
* .then( ... );
|
||||||
*
|
*
|
||||||
* @param {(Buffer|string)} [input] - if present, can be
|
* @example
|
||||||
* a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
* // Convert an animated GIF to an animated WebP
|
||||||
* a String containing the filesystem path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
* await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||||
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
*
|
||||||
|
* @example
|
||||||
|
* // Read a raw array of pixels and save it to a png
|
||||||
|
* const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
|
||||||
|
* const image = sharp(input, {
|
||||||
|
* // because the input does not contain its dimensions or how many channels it has
|
||||||
|
* // we need to specify it in the constructor options
|
||||||
|
* raw: {
|
||||||
|
* width: 2,
|
||||||
|
* height: 1,
|
||||||
|
* channels: 3
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
* await image.toFile('my-two-pixels.png');
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Generate RGB Gaussian noise
|
||||||
|
* await sharp({
|
||||||
|
* create: {
|
||||||
|
* width: 300,
|
||||||
|
* height: 200,
|
||||||
|
* channels: 3,
|
||||||
|
* noise: {
|
||||||
|
* type: 'gaussian',
|
||||||
|
* mean: 128,
|
||||||
|
* sigma: 30
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }).toFile('noise.png');
|
||||||
|
*
|
||||||
|
* @param {(Buffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string)} [input] - if present, can be
|
||||||
|
* a Buffer / 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.
|
||||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||||
* @param {boolean} [options.failOnError=true] - by default halt processing and raise an error when loading invalid images.
|
* @param {boolean} [options.failOnError=true] - by default halt processing and raise an error when loading invalid images.
|
||||||
* Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid.
|
* Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid.
|
||||||
@@ -98,19 +105,27 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* 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.sequentialRead=false] - Set this to `true` to use sequential rather than random access where possible.
|
* @param {boolean} [options.sequentialRead=false] - Set this to `true` to use sequential rather than random access where possible.
|
||||||
* This can reduce memory usage and might improve performance on some systems.
|
* This can reduce memory usage and might improve performance on some systems.
|
||||||
* @param {number} [options.density=72] - number representing the DPI for vector images.
|
* @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
|
||||||
* @param {number} [options.pages=1] - number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages.
|
* @param {number} [options.pages=1] - number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages.
|
||||||
* @param {number} [options.page=0] - page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based.
|
* @param {number} [options.page=0] - page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based.
|
||||||
|
* @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 {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (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]
|
* @param {number} [options.raw.width] - integral number of pixels wide.
|
||||||
* @param {number} [options.raw.height]
|
* @param {number} [options.raw.height] - integral number of pixels high.
|
||||||
* @param {number} [options.raw.channels] - 1-4
|
* @param {number} [options.raw.channels] - integral number of channels, between 1 and 4.
|
||||||
|
* @param {boolean} [options.raw.premultiplied] - specifies that the raw input has already been premultiplied, set to `true`
|
||||||
|
* to avoid sharp premultiplying the image. (optional, default `false`)
|
||||||
* @param {Object} [options.create] - describes a new image to be created.
|
* @param {Object} [options.create] - describes a new image to be created.
|
||||||
* @param {number} [options.create.width]
|
* @param {number} [options.create.width] - integral number of pixels wide.
|
||||||
* @param {number} [options.create.height]
|
* @param {number} [options.create.height] - integral number of pixels high.
|
||||||
* @param {number} [options.create.channels] - 3-4
|
* @param {number} [options.create.channels] - integral number of channels, either 3 (RGB) or 4 (RGBA).
|
||||||
* @param {string|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
* @param {string|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||||
|
* @param {Object} [options.create.noise] - describes a noise to be created.
|
||||||
|
* @param {string} [options.create.noise.type] - type of generated noise, currently only `gaussian` is supported.
|
||||||
|
* @param {number} [options.create.noise.mean] - mean of pixels in generated noise.
|
||||||
|
* @param {number} [options.create.noise.sigma] - standard deviation of pixels in generated noise.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -150,6 +165,13 @@ const Sharp = function (input, options) {
|
|||||||
extendRight: 0,
|
extendRight: 0,
|
||||||
extendBackground: [0, 0, 0, 255],
|
extendBackground: [0, 0, 0, 255],
|
||||||
withoutEnlargement: false,
|
withoutEnlargement: false,
|
||||||
|
affineMatrix: [],
|
||||||
|
affineBackground: [0, 0, 0, 255],
|
||||||
|
affineIdx: 0,
|
||||||
|
affineIdy: 0,
|
||||||
|
affineOdx: 0,
|
||||||
|
affineOdy: 0,
|
||||||
|
affineInterpolator: this.constructor.interpolators.bilinear,
|
||||||
kernel: 'lanczos3',
|
kernel: 'lanczos3',
|
||||||
fastShrinkOnLoad: true,
|
fastShrinkOnLoad: true,
|
||||||
// operations
|
// operations
|
||||||
@@ -158,6 +180,7 @@ const Sharp = function (input, options) {
|
|||||||
flatten: false,
|
flatten: false,
|
||||||
flattenBackground: [0, 0, 0],
|
flattenBackground: [0, 0, 0],
|
||||||
negate: false,
|
negate: false,
|
||||||
|
negateAlpha: true,
|
||||||
medianSize: 0,
|
medianSize: 0,
|
||||||
blurSigma: 0,
|
blurSigma: 0,
|
||||||
sharpenSigma: 0,
|
sharpenSigma: 0,
|
||||||
@@ -170,6 +193,9 @@ const Sharp = function (input, options) {
|
|||||||
gammaOut: 0,
|
gammaOut: 0,
|
||||||
greyscale: false,
|
greyscale: false,
|
||||||
normalise: false,
|
normalise: false,
|
||||||
|
claheWidth: 0,
|
||||||
|
claheHeight: 0,
|
||||||
|
claheMaxSlope: 3,
|
||||||
brightness: 1,
|
brightness: 1,
|
||||||
saturation: 1,
|
saturation: 1,
|
||||||
hue: 0,
|
hue: 0,
|
||||||
@@ -178,8 +204,9 @@ const Sharp = function (input, options) {
|
|||||||
joinChannelIn: [],
|
joinChannelIn: [],
|
||||||
extractChannel: -1,
|
extractChannel: -1,
|
||||||
removeAlpha: false,
|
removeAlpha: false,
|
||||||
ensureAlpha: false,
|
ensureAlpha: -1,
|
||||||
colourspace: 'srgb',
|
colourspace: 'srgb',
|
||||||
|
colourspaceInput: 'last',
|
||||||
composite: [],
|
composite: [],
|
||||||
// output
|
// output
|
||||||
fileOut: '',
|
fileOut: '',
|
||||||
@@ -187,6 +214,9 @@ const Sharp = function (input, options) {
|
|||||||
streamOut: false,
|
streamOut: false,
|
||||||
withMetadata: false,
|
withMetadata: false,
|
||||||
withMetadataOrientation: -1,
|
withMetadataOrientation: -1,
|
||||||
|
withMetadataDensity: 0,
|
||||||
|
withMetadataIcc: '',
|
||||||
|
withMetadataStrs: {},
|
||||||
resolveWithObject: false,
|
resolveWithObject: false,
|
||||||
// output format
|
// output format
|
||||||
jpegQuality: 80,
|
jpegQuality: 80,
|
||||||
@@ -198,7 +228,7 @@ const Sharp = function (input, options) {
|
|||||||
jpegOptimiseCoding: true,
|
jpegOptimiseCoding: true,
|
||||||
jpegQuantisationTable: 0,
|
jpegQuantisationTable: 0,
|
||||||
pngProgressive: false,
|
pngProgressive: false,
|
||||||
pngCompressionLevel: 9,
|
pngCompressionLevel: 6,
|
||||||
pngAdaptiveFiltering: false,
|
pngAdaptiveFiltering: false,
|
||||||
pngPalette: false,
|
pngPalette: false,
|
||||||
pngQuality: 100,
|
pngQuality: 100,
|
||||||
@@ -220,9 +250,12 @@ const Sharp = function (input, options) {
|
|||||||
tiffTileWidth: 256,
|
tiffTileWidth: 256,
|
||||||
tiffXres: 1.0,
|
tiffXres: 1.0,
|
||||||
tiffYres: 1.0,
|
tiffYres: 1.0,
|
||||||
heifQuality: 80,
|
heifQuality: 50,
|
||||||
heifLossless: false,
|
heifLossless: false,
|
||||||
heifCompression: 'hevc',
|
heifCompression: 'av1',
|
||||||
|
heifSpeed: 5,
|
||||||
|
heifChromaSubsampling: '4:4:4',
|
||||||
|
rawDepth: 'uchar',
|
||||||
tileSize: 256,
|
tileSize: 256,
|
||||||
tileOverlap: 0,
|
tileOverlap: 0,
|
||||||
tileContainer: 'fs',
|
tileContainer: 'fs',
|
||||||
@@ -232,6 +265,8 @@ const Sharp = function (input, options) {
|
|||||||
tileAngle: 0,
|
tileAngle: 0,
|
||||||
tileSkipBlanks: -1,
|
tileSkipBlanks: -1,
|
||||||
tileBackground: [255, 255, 255, 255],
|
tileBackground: [255, 255, 255, 255],
|
||||||
|
tileCentre: false,
|
||||||
|
tileId: 'https://example.com/iiif',
|
||||||
linearA: 1,
|
linearA: 1,
|
||||||
linearB: 0,
|
linearB: 0,
|
||||||
// Function to notify of libvips warnings
|
// Function to notify of libvips warnings
|
||||||
|
|||||||
128
lib/input.js
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
const color = require('color');
|
const color = require('color');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
const sharp = require('../build/Release/sharp.node');
|
const sharp = require('./sharp');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract input options, if any, from an object.
|
* Extract input options, if any, from an object.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _inputOptionsFromObject (obj) {
|
function _inputOptionsFromObject (obj) {
|
||||||
const { raw, density, limitInputPixels, sequentialRead, failOnError } = obj;
|
const { raw, density, limitInputPixels, sequentialRead, failOnError, animated, page, pages, subifd } = obj;
|
||||||
return [raw, density, limitInputPixels, sequentialRead, failOnError].some(is.defined)
|
return [raw, density, limitInputPixels, sequentialRead, failOnError, animated, page, pages, subifd].some(is.defined)
|
||||||
? { raw, density, limitInputPixels, sequentialRead, failOnError }
|
? { raw, density, limitInputPixels, sequentialRead, failOnError, animated, page, pages, subifd }
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +30,15 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
inputDescriptor.file = input;
|
inputDescriptor.file = input;
|
||||||
} else if (is.buffer(input)) {
|
} else if (is.buffer(input)) {
|
||||||
// Buffer
|
// Buffer
|
||||||
|
if (input.length === 0) {
|
||||||
|
throw Error('Input Buffer is empty');
|
||||||
|
}
|
||||||
inputDescriptor.buffer = input;
|
inputDescriptor.buffer = input;
|
||||||
|
} else if (is.typedArray(input)) {
|
||||||
|
if (input.length === 0) {
|
||||||
|
throw Error('Input Bit Array is empty');
|
||||||
|
}
|
||||||
|
inputDescriptor.buffer = Buffer.from(input.buffer);
|
||||||
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
||||||
// Plain Object descriptor, e.g. create
|
// Plain Object descriptor, e.g. create
|
||||||
inputOptions = input;
|
inputOptions = input;
|
||||||
@@ -57,10 +65,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
}
|
}
|
||||||
// Density
|
// Density
|
||||||
if (is.defined(inputOptions.density)) {
|
if (is.defined(inputOptions.density)) {
|
||||||
if (is.inRange(inputOptions.density, 1, 2400)) {
|
if (is.inRange(inputOptions.density, 1, 100000)) {
|
||||||
inputDescriptor.density = inputOptions.density;
|
inputDescriptor.density = inputOptions.density;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('density', 'number between 1 and 2400', inputOptions.density);
|
throw is.invalidParameterError('density', 'number between 1 and 100000', inputOptions.density);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// limitInputPixels
|
// limitInputPixels
|
||||||
@@ -94,11 +102,50 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
inputDescriptor.rawWidth = inputOptions.raw.width;
|
inputDescriptor.rawWidth = inputOptions.raw.width;
|
||||||
inputDescriptor.rawHeight = inputOptions.raw.height;
|
inputDescriptor.rawHeight = inputOptions.raw.height;
|
||||||
inputDescriptor.rawChannels = inputOptions.raw.channels;
|
inputDescriptor.rawChannels = inputOptions.raw.channels;
|
||||||
|
inputDescriptor.rawPremultiplied = !!inputOptions.raw.premultiplied;
|
||||||
|
|
||||||
|
switch (input.constructor) {
|
||||||
|
case Uint8Array:
|
||||||
|
case Uint8ClampedArray:
|
||||||
|
inputDescriptor.rawDepth = 'uchar';
|
||||||
|
break;
|
||||||
|
case Int8Array:
|
||||||
|
inputDescriptor.rawDepth = 'char';
|
||||||
|
break;
|
||||||
|
case Uint16Array:
|
||||||
|
inputDescriptor.rawDepth = 'ushort';
|
||||||
|
break;
|
||||||
|
case Int16Array:
|
||||||
|
inputDescriptor.rawDepth = 'short';
|
||||||
|
break;
|
||||||
|
case Uint32Array:
|
||||||
|
inputDescriptor.rawDepth = 'uint';
|
||||||
|
break;
|
||||||
|
case Int32Array:
|
||||||
|
inputDescriptor.rawDepth = 'int';
|
||||||
|
break;
|
||||||
|
case Float32Array:
|
||||||
|
inputDescriptor.rawDepth = 'float';
|
||||||
|
break;
|
||||||
|
case Float64Array:
|
||||||
|
inputDescriptor.rawDepth = 'double';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
inputDescriptor.rawDepth = 'uchar';
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Expected width, height and channels for raw pixel input');
|
throw new Error('Expected width, height and channels for raw pixel input');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Multi-page input (GIF, TIFF, PDF)
|
// Multi-page input (GIF, TIFF, PDF)
|
||||||
|
if (is.defined(inputOptions.animated)) {
|
||||||
|
if (is.bool(inputOptions.animated)) {
|
||||||
|
inputDescriptor.pages = inputOptions.animated ? -1 : 1;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('animated', 'boolean', inputOptions.animated);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is.defined(inputOptions.pages)) {
|
if (is.defined(inputOptions.pages)) {
|
||||||
if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {
|
if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {
|
||||||
inputDescriptor.pages = inputOptions.pages;
|
inputDescriptor.pages = inputOptions.pages;
|
||||||
@@ -121,28 +168,64 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);
|
throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Sub Image File Directory (TIFF)
|
||||||
|
if (is.defined(inputOptions.subifd)) {
|
||||||
|
if (is.integer(inputOptions.subifd) && is.inRange(inputOptions.subifd, -1, 100000)) {
|
||||||
|
inputDescriptor.subifd = inputOptions.subifd;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (is.defined(inputOptions.create)) {
|
if (is.defined(inputOptions.create)) {
|
||||||
if (
|
if (
|
||||||
is.object(inputOptions.create) &&
|
is.object(inputOptions.create) &&
|
||||||
is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
|
is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
|
||||||
is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
|
is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
|
||||||
is.integer(inputOptions.create.channels) && is.inRange(inputOptions.create.channels, 3, 4) &&
|
is.integer(inputOptions.create.channels)
|
||||||
is.defined(inputOptions.create.background)
|
|
||||||
) {
|
) {
|
||||||
inputDescriptor.createWidth = inputOptions.create.width;
|
inputDescriptor.createWidth = inputOptions.create.width;
|
||||||
inputDescriptor.createHeight = inputOptions.create.height;
|
inputDescriptor.createHeight = inputOptions.create.height;
|
||||||
inputDescriptor.createChannels = inputOptions.create.channels;
|
inputDescriptor.createChannels = inputOptions.create.channels;
|
||||||
const background = color(inputOptions.create.background);
|
// Noise
|
||||||
inputDescriptor.createBackground = [
|
if (is.defined(inputOptions.create.noise)) {
|
||||||
background.red(),
|
if (!is.object(inputOptions.create.noise)) {
|
||||||
background.green(),
|
throw new Error('Expected noise to be an object');
|
||||||
background.blue(),
|
}
|
||||||
Math.round(background.alpha() * 255)
|
if (!is.inArray(inputOptions.create.noise.type, ['gaussian'])) {
|
||||||
];
|
throw new Error('Only gaussian noise is supported at the moment');
|
||||||
|
}
|
||||||
|
if (!is.inRange(inputOptions.create.channels, 1, 4)) {
|
||||||
|
throw is.invalidParameterError('create.channels', 'number between 1 and 4', inputOptions.create.channels);
|
||||||
|
}
|
||||||
|
inputDescriptor.createNoiseType = inputOptions.create.noise.type;
|
||||||
|
if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {
|
||||||
|
inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);
|
||||||
|
}
|
||||||
|
if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {
|
||||||
|
inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);
|
||||||
|
}
|
||||||
|
} else if (is.defined(inputOptions.create.background)) {
|
||||||
|
if (!is.inRange(inputOptions.create.channels, 3, 4)) {
|
||||||
|
throw is.invalidParameterError('create.channels', 'number between 3 and 4', inputOptions.create.channels);
|
||||||
|
}
|
||||||
|
const background = color(inputOptions.create.background);
|
||||||
|
inputDescriptor.createBackground = [
|
||||||
|
background.red(),
|
||||||
|
background.green(),
|
||||||
|
background.blue(),
|
||||||
|
Math.round(background.alpha() * 255)
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
throw new Error('Expected valid noise or background to create a new input image');
|
||||||
|
}
|
||||||
delete inputDescriptor.buffer;
|
delete inputDescriptor.buffer;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Expected width, height, channels and background to create a new input image');
|
throw new Error('Expected valid width, height and channels to create a new input image');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (is.defined(inputOptions)) {
|
} else if (is.defined(inputOptions)) {
|
||||||
@@ -217,6 +300,9 @@ function _isStreamInput () {
|
|||||||
* - `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
|
||||||
|
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||||
|
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||||
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
* - `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
* - `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
||||||
* - `orientation`: Number value of the EXIF Orientation header, if present
|
* - `orientation`: Number value of the EXIF Orientation header, if present
|
||||||
@@ -302,6 +388,9 @@ function metadata (callback) {
|
|||||||
* - `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental)
|
* - `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental)
|
||||||
* - `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
* - `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
||||||
*
|
*
|
||||||
|
* **Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
||||||
|
* written to a buffer in order to run `stats` on the result (see third example).
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* const image = sharp(inputJpg);
|
* const image = sharp(inputJpg);
|
||||||
* image
|
* image
|
||||||
@@ -314,6 +403,13 @@ function metadata (callback) {
|
|||||||
* const { entropy, sharpness, dominant } = await sharp(input).stats();
|
* const { entropy, sharpness, dominant } = await sharp(input).stats();
|
||||||
* const { r, g, b } = dominant;
|
* const { r, g, b } = dominant;
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* const image = sharp(input);
|
||||||
|
* // store intermediate result
|
||||||
|
* const part = await image.extract(region).toBuffer();
|
||||||
|
* // create new instance to obtain statistics of extracted region
|
||||||
|
* const stats = await sharp(part).stats();
|
||||||
|
*
|
||||||
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
||||||
* @returns {Promise<Object>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
|
|||||||
24
lib/is.js
@@ -48,6 +48,29 @@ const buffer = function (val) {
|
|||||||
return val instanceof Buffer;
|
return val instanceof Buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this value a typed array object?. E.g. Uint8Array or Uint8ClampedArray?
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const typedArray = function (val) {
|
||||||
|
if (defined(val)) {
|
||||||
|
switch (val.constructor) {
|
||||||
|
case Uint8Array:
|
||||||
|
case Uint8ClampedArray:
|
||||||
|
case Int8Array:
|
||||||
|
case Uint16Array:
|
||||||
|
case Int16Array:
|
||||||
|
case Uint32Array:
|
||||||
|
case Int32Array:
|
||||||
|
case Float32Array:
|
||||||
|
case Float64Array:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this value a non-empty string?
|
* Is this value a non-empty string?
|
||||||
* @private
|
* @private
|
||||||
@@ -110,6 +133,7 @@ module.exports = {
|
|||||||
fn: fn,
|
fn: fn,
|
||||||
bool: bool,
|
bool: bool,
|
||||||
buffer: buffer,
|
buffer: buffer,
|
||||||
|
typedArray: typedArray,
|
||||||
string: string,
|
string: string,
|
||||||
number: number,
|
number: number,
|
||||||
integer: integer,
|
integer: integer,
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ const fs = require('fs');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const spawnSync = require('child_process').spawnSync;
|
const spawnSync = require('child_process').spawnSync;
|
||||||
const semver = require('semver');
|
const semverCoerce = require('semver/functions/coerce');
|
||||||
|
const semverGreaterThanOrEqualTo = require('semver/functions/gte');
|
||||||
|
|
||||||
const platform = require('./platform');
|
const platform = require('./platform');
|
||||||
|
|
||||||
const env = process.env;
|
const env = process.env;
|
||||||
const minimumLibvipsVersionLabelled = env.npm_package_config_libvips || /* istanbul ignore next */
|
const minimumLibvipsVersionLabelled = env.npm_package_config_libvips || /* istanbul ignore next */
|
||||||
require('../package.json').config.libvips;
|
require('../package.json').config.libvips;
|
||||||
const minimumLibvipsVersion = semver.coerce(minimumLibvipsVersionLabelled).version;
|
const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).version;
|
||||||
|
|
||||||
const spawnSyncOptions = {
|
const spawnSyncOptions = {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
@@ -19,9 +21,9 @@ const spawnSyncOptions = {
|
|||||||
|
|
||||||
const mkdirSync = function (dirPath) {
|
const mkdirSync = function (dirPath) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(dirPath);
|
fs.mkdirSync(dirPath, { recursive: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore next */
|
||||||
if (err.code !== 'EEXIST') {
|
if (err.code !== 'EEXIST') {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -37,33 +39,36 @@ const cachePath = function () {
|
|||||||
return libvipsCachePath;
|
return libvipsCachePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const log = function (item) {
|
||||||
|
if (item instanceof Error) {
|
||||||
|
console.error(`sharp: Installation error: ${item.message}`);
|
||||||
|
} else {
|
||||||
|
console.log(`sharp: ${item}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isRosetta = function () {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (process.platform === 'darwin' && process.arch === 'x64') {
|
||||||
|
const translated = spawnSync('sysctl sysctl.proc_translated', spawnSyncOptions).stdout;
|
||||||
|
return (translated || '').trim() === 'sysctl.proc_translated: 1';
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
const globalLibvipsVersion = function () {
|
const globalLibvipsVersion = function () {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout || '';
|
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout;
|
||||||
return globalLibvipsVersion.trim();
|
/* istanbul ignore next */
|
||||||
|
return (globalLibvipsVersion || '').trim();
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasVendoredLibvips = function () {
|
const hasVendoredLibvips = function () {
|
||||||
const currentPlatformId = platform();
|
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, platform());
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion);
|
return fs.existsSync(vendorPath);
|
||||||
let vendorPlatformId;
|
|
||||||
try {
|
|
||||||
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
|
||||||
} catch (err) {}
|
|
||||||
/* istanbul ignore else */
|
|
||||||
if (vendorPlatformId) {
|
|
||||||
/* istanbul ignore else */
|
|
||||||
if (currentPlatformId === vendorPlatformId) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the '${currentPlatformId}' platform.`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const pkgConfigPath = function () {
|
const pkgConfigPath = function () {
|
||||||
@@ -81,16 +86,20 @@ const useGlobalLibvips = function () {
|
|||||||
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (isRosetta()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const globalVipsVersion = globalLibvipsVersion();
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
return !!globalVipsVersion && /* istanbul ignore next */
|
return !!globalVipsVersion && /* istanbul ignore next */
|
||||||
semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
minimumLibvipsVersion,
|
minimumLibvipsVersion,
|
||||||
minimumLibvipsVersionLabelled,
|
minimumLibvipsVersionLabelled,
|
||||||
cachePath,
|
cachePath,
|
||||||
|
log,
|
||||||
globalLibvipsVersion,
|
globalLibvipsVersion,
|
||||||
hasVendoredLibvips,
|
hasVendoredLibvips,
|
||||||
pkgConfigPath,
|
pkgConfigPath,
|
||||||
|
|||||||
168
lib/operation.js
@@ -82,6 +82,103 @@ function flop (flop) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||||
|
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolator` Object e.g. `sharp.interpolator.nohalo`.
|
||||||
|
*
|
||||||
|
* In the case of a 2x2 matrix, the transform is:
|
||||||
|
* - X = `matrix[0, 0]` \* (x + `idx`) + `matrix[0, 1]` \* (y + `idy`) + `odx`
|
||||||
|
* - Y = `matrix[1, 0]` \* (x + `idx`) + `matrix[1, 1]` \* (y + `idy`) + `ody`
|
||||||
|
*
|
||||||
|
* where:
|
||||||
|
* - x and y are the coordinates in input image.
|
||||||
|
* - X and Y are the coordinates in output image.
|
||||||
|
* - (0,0) is the upper left corner.
|
||||||
|
*
|
||||||
|
* @since 0.27.0
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const pipeline = sharp()
|
||||||
|
* .affine([[1, 0.3], [0.1, 0.7]], {
|
||||||
|
* background: 'white',
|
||||||
|
* interpolate: sharp.interpolators.nohalo
|
||||||
|
* })
|
||||||
|
* .toBuffer((err, outputBuffer, info) => {
|
||||||
|
* // outputBuffer contains the transformed image
|
||||||
|
* // info.width and info.height contain the new dimensions
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* inputStream
|
||||||
|
* .pipe(pipeline);
|
||||||
|
*
|
||||||
|
* @param {Array<Array<number>>|Array<number>} matrix - affine transformation matrix
|
||||||
|
* @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.
|
||||||
|
* @param {Number} [options.idx=0] - input horizontal offset
|
||||||
|
* @param {Number} [options.idy=0] - input vertical offset
|
||||||
|
* @param {Number} [options.odx=0] - output horizontal offset
|
||||||
|
* @param {Number} [options.ody=0] - output vertical offset
|
||||||
|
* @param {String} [options.interpolator=sharp.interpolators.bicubic] - interpolator
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function affine (matrix, options) {
|
||||||
|
const flatMatrix = [].concat(...matrix);
|
||||||
|
if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
|
||||||
|
this.options.affineMatrix = flatMatrix;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('matrix', '1x4 or 2x2 array', matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is.defined(options)) {
|
||||||
|
if (is.object(options)) {
|
||||||
|
this._setBackgroundColourOption('affineBackground', options.background);
|
||||||
|
if (is.defined(options.idx)) {
|
||||||
|
if (is.number(options.idx)) {
|
||||||
|
this.options.affineIdx = options.idx;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('options.idx', 'number', options.idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.idy)) {
|
||||||
|
if (is.number(options.idy)) {
|
||||||
|
this.options.affineIdy = options.idy;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('options.idy', 'number', options.idy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.odx)) {
|
||||||
|
if (is.number(options.odx)) {
|
||||||
|
this.options.affineOdx = options.odx;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('options.odx', 'number', options.odx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.ody)) {
|
||||||
|
if (is.number(options.ody)) {
|
||||||
|
this.options.affineOdy = options.ody;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('options.ody', 'number', options.ody);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.interpolator)) {
|
||||||
|
if (is.inArray(options.interpolator, Object.values(this.constructor.interpolators))) {
|
||||||
|
this.options.affineInterpolator = options.interpolator;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('options.interpolator', 'valid interpolator name', options.interpolator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('options', 'object', options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sharpen the image.
|
* Sharpen the image.
|
||||||
* When used without parameters, performs a fast, mild sharpen of the output image.
|
* When used without parameters, performs a fast, mild sharpen of the output image.
|
||||||
@@ -171,7 +268,15 @@ function blur (sigma) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge alpha transparency channel, if any, with a background.
|
* Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
||||||
|
*
|
||||||
|
* See also {@link /api-channel#removealpha|removeAlpha}.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* await sharp(rgbaInput)
|
||||||
|
* .flatten({ background: '#F0A703' })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {string|Object} [options.background={r: 0, g: 0, b: 0}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black.
|
* @param {string|Object} [options.background={r: 0, g: 0, b: 0}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -220,11 +325,19 @@ function gamma (gamma, gammaOut) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce the "negative" of the image.
|
* Produce the "negative" of the image.
|
||||||
* @param {Boolean} [negate=true]
|
* @param {Object} [options]
|
||||||
|
* @param {Boolean} [options.alpha=true] Whether or not to negate any alpha channel
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
function negate (negate) {
|
function negate (options) {
|
||||||
this.options.negate = is.bool(negate) ? negate : true;
|
this.options.negate = is.bool(options) ? options : true;
|
||||||
|
if (is.plainObject(options) && 'alpha' in options) {
|
||||||
|
if (!is.bool(options.alpha)) {
|
||||||
|
throw is.invalidParameterError('alpha', 'should be boolean value', options.alpha);
|
||||||
|
} else {
|
||||||
|
this.options.negateAlpha = options.alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +360,47 @@ function normalize (normalize) {
|
|||||||
return this.normalise(normalize);
|
return this.normalise(normalize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform contrast limiting adaptive histogram equalization
|
||||||
|
* {@link https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE|CLAHE}.
|
||||||
|
*
|
||||||
|
* This will, in general, enhance the clarity of the image by bringing out darker details.
|
||||||
|
*
|
||||||
|
* @since 0.28.3
|
||||||
|
*
|
||||||
|
* @param {Object} options
|
||||||
|
* @param {number} options.width - integer width of the region in pixels.
|
||||||
|
* @param {number} options.height - integer height of the region in pixels.
|
||||||
|
* @param {number} [options.maxSlope=3] - maximum value for the slope of the
|
||||||
|
* cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
||||||
|
* are integers in the range 0-100 (inclusive)
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function clahe (options) {
|
||||||
|
if (!is.plainObject(options)) {
|
||||||
|
throw is.invalidParameterError('options', 'plain object', options);
|
||||||
|
}
|
||||||
|
if (!('width' in options) || !is.integer(options.width) || options.width <= 0) {
|
||||||
|
throw is.invalidParameterError('width', 'integer above zero', options.width);
|
||||||
|
} else {
|
||||||
|
this.options.claheWidth = options.width;
|
||||||
|
}
|
||||||
|
if (!('height' in options) || !is.integer(options.height) || options.height <= 0) {
|
||||||
|
throw is.invalidParameterError('height', 'integer above zero', options.height);
|
||||||
|
} else {
|
||||||
|
this.options.claheHeight = options.height;
|
||||||
|
}
|
||||||
|
if (!is.defined(options.maxSlope)) {
|
||||||
|
this.options.claheMaxSlope = 3;
|
||||||
|
} else if (!is.integer(options.maxSlope) || options.maxSlope < 0 || options.maxSlope > 100) {
|
||||||
|
throw is.invalidParameterError('maxSlope', 'integer 0-100', options.maxSlope);
|
||||||
|
} else {
|
||||||
|
this.options.claheMaxSlope = options.maxSlope;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convolve the image with the specified kernel.
|
* Convolve the image with the specified kernel.
|
||||||
*
|
*
|
||||||
@@ -265,7 +419,7 @@ function normalize (normalize) {
|
|||||||
*
|
*
|
||||||
* @param {Object} kernel
|
* @param {Object} kernel
|
||||||
* @param {number} kernel.width - width of the kernel in pixels.
|
* @param {number} kernel.width - width of the kernel in pixels.
|
||||||
* @param {number} kernel.height - width of the kernel in pixels.
|
* @param {number} kernel.height - height of the kernel in pixels.
|
||||||
* @param {Array<number>} kernel.kernel - Array of length `width*height` containing the kernel values.
|
* @param {Array<number>} kernel.kernel - Array of length `width*height` containing the kernel values.
|
||||||
* @param {number} [kernel.scale=sum] - the scale of the kernel in pixels.
|
* @param {number} [kernel.scale=sum] - the scale of the kernel in pixels.
|
||||||
* @param {number} [kernel.offset=0] - the offset of the kernel in pixels.
|
* @param {number} [kernel.offset=0] - the offset of the kernel in pixels.
|
||||||
@@ -299,7 +453,7 @@ function convolve (kernel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
* Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
||||||
* @param {number} [threshold=128] - a value in the range 0-255 representing the level at which the threshold will be applied.
|
* @param {number} [threshold=128] - a value in the range 0-255 representing the level at which the threshold will be applied.
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {Boolean} [options.greyscale=true] - convert to single channel greyscale.
|
* @param {Boolean} [options.greyscale=true] - convert to single channel greyscale.
|
||||||
@@ -482,6 +636,7 @@ module.exports = function (Sharp) {
|
|||||||
rotate,
|
rotate,
|
||||||
flip,
|
flip,
|
||||||
flop,
|
flop,
|
||||||
|
affine,
|
||||||
sharpen,
|
sharpen,
|
||||||
median,
|
median,
|
||||||
blur,
|
blur,
|
||||||
@@ -490,6 +645,7 @@ module.exports = function (Sharp) {
|
|||||||
negate,
|
negate,
|
||||||
normalise,
|
normalise,
|
||||||
normalize,
|
normalize,
|
||||||
|
clahe,
|
||||||
convolve,
|
convolve,
|
||||||
threshold,
|
threshold,
|
||||||
boolean,
|
boolean,
|
||||||
|
|||||||
295
lib/output.js
@@ -1,11 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
const sharp = require('../build/Release/sharp.node');
|
const sharp = require('./sharp');
|
||||||
|
|
||||||
const formats = new Map([
|
const formats = new Map([
|
||||||
['heic', 'heif'],
|
['heic', 'heif'],
|
||||||
['heif', 'heif'],
|
['heif', 'heif'],
|
||||||
|
['avif', 'avif'],
|
||||||
['jpeg', 'jpeg'],
|
['jpeg', 'jpeg'],
|
||||||
['jpg', 'jpeg'],
|
['jpg', 'jpeg'],
|
||||||
['png', 'png'],
|
['png', 'png'],
|
||||||
@@ -15,11 +16,13 @@ const formats = new Map([
|
|||||||
['gif', 'gif']
|
['gif', 'gif']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const errMagickSave = new Error('GIF output requires libvips with support for ImageMagick');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write output image data to a file.
|
* Write output image data to a file.
|
||||||
*
|
*
|
||||||
* If an explicit output format is not selected, it will be inferred from the extension,
|
* If an explicit output format is not selected, it will be inferred from the extension,
|
||||||
* with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
|
* with JPEG, PNG, WebP, AVIF, TIFF, DZI, and libvips' V format supported.
|
||||||
* Note that raw pixel data is only supported for buffer output.
|
* Note that raw pixel data is only supported for buffer output.
|
||||||
*
|
*
|
||||||
* By default all metadata will be removed, which includes EXIF-based orientation.
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
@@ -46,32 +49,30 @@ const formats = new Map([
|
|||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function toFile (fileOut, callback) {
|
function toFile (fileOut, callback) {
|
||||||
if (!fileOut || fileOut.length === 0) {
|
let err;
|
||||||
const errOutputInvalid = new Error('Missing output file path');
|
if (!is.string(fileOut)) {
|
||||||
|
err = new Error('Missing output file path');
|
||||||
|
} else if (this.options.input.file === fileOut) {
|
||||||
|
err = new Error('Cannot use same file for input and output');
|
||||||
|
} else if (this.options.formatOut === 'input' && fileOut.toLowerCase().endsWith('.gif') && !this.constructor.format.magick.output.file) {
|
||||||
|
err = errMagickSave;
|
||||||
|
}
|
||||||
|
if (err) {
|
||||||
if (is.fn(callback)) {
|
if (is.fn(callback)) {
|
||||||
callback(errOutputInvalid);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(errOutputInvalid);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.options.input.file === fileOut) {
|
this.options.fileOut = fileOut;
|
||||||
const errOutputIsInput = new Error('Cannot use same file for input and output');
|
return this._pipeline(callback);
|
||||||
if (is.fn(callback)) {
|
|
||||||
callback(errOutputIsInput);
|
|
||||||
} else {
|
|
||||||
return Promise.reject(errOutputIsInput);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.options.fileOut = fileOut;
|
|
||||||
return this._pipeline(callback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write output to a Buffer.
|
* Write output to a Buffer.
|
||||||
* JPEG, PNG, WebP, TIFF and RAW output are supported.
|
* JPEG, PNG, WebP, AVIF, TIFF and raw pixel data output are supported.
|
||||||
*
|
*
|
||||||
* If no explicit format is set, the output format will match the input image, except GIF and SVG input which become PNG output.
|
* If no explicit format is set, the output format will match the input image, except GIF and SVG input which become PNG output.
|
||||||
*
|
*
|
||||||
@@ -103,6 +104,22 @@ function toFile (fileOut, callback) {
|
|||||||
* .then(({ data, info }) => { ... })
|
* .then(({ data, info }) => { ... })
|
||||||
* .catch(err => { ... });
|
* .catch(err => { ... });
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* const { data, info } = await sharp('my-image.jpg')
|
||||||
|
* // output the raw pixels
|
||||||
|
* .raw()
|
||||||
|
* .toBuffer({ resolveWithObject: true });
|
||||||
|
*
|
||||||
|
* // create a more type safe way to work with the raw pixel data
|
||||||
|
* // this will not copy the data, instead it will change `data`s underlying ArrayBuffer
|
||||||
|
* // so `data` and `pixelArray` point to the same memory location
|
||||||
|
* const pixelArray = new Uint8ClampedArray(data.buffer);
|
||||||
|
*
|
||||||
|
* // When you are done changing the pixelArray, sharp takes the `pixelArray` as an input
|
||||||
|
* const { width, height, channels } = info;
|
||||||
|
* await sharp(pixelArray, { raw: { width, height, channels } })
|
||||||
|
* .toFile('my-changed-image.jpg');
|
||||||
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
* @param {boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
* @param {Function} [callback]
|
* @param {Function} [callback]
|
||||||
@@ -119,7 +136,8 @@ function toBuffer (options, callback) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
* This will also convert to and add a web-friendly sRGB ICC profile.
|
* This will also convert to and add a web-friendly sRGB ICC profile unless a custom
|
||||||
|
* output profile is provided.
|
||||||
*
|
*
|
||||||
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
|
* 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.
|
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
||||||
@@ -130,8 +148,29 @@ function toBuffer (options, callback) {
|
|||||||
* .toFile('output-with-metadata.jpg')
|
* .toFile('output-with-metadata.jpg')
|
||||||
* .then(info => { ... });
|
* .then(info => { ... });
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Set "IFD0-Copyright" in output EXIF metadata
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .withMetadata({
|
||||||
|
* exif: {
|
||||||
|
* IFD0: {
|
||||||
|
* Copyright: 'Wernham Hogg'
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
|
* * @example
|
||||||
|
* // Set output metadata to 96 DPI
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .withMetadata({ density: 96 })
|
||||||
|
* .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] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
|
* @param {string} [options.icc] filesystem path to output ICC profile, defaults to 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).
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -145,6 +184,39 @@ function withMetadata (options) {
|
|||||||
throw is.invalidParameterError('orientation', 'integer between 1 and 8', options.orientation);
|
throw is.invalidParameterError('orientation', 'integer between 1 and 8', options.orientation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is.defined(options.density)) {
|
||||||
|
if (is.number(options.density) && options.density > 0) {
|
||||||
|
this.options.withMetadataDensity = options.density;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('density', 'positive number', options.density);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.icc)) {
|
||||||
|
if (is.string(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.object(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;
|
||||||
}
|
}
|
||||||
@@ -164,7 +236,7 @@ function withMetadata (options) {
|
|||||||
* @throws {Error} unsupported format or options
|
* @throws {Error} unsupported format or options
|
||||||
*/
|
*/
|
||||||
function toFormat (format, options) {
|
function toFormat (format, options) {
|
||||||
const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
|
const actualFormat = formats.get((is.object(format) && is.string(format.id) ? format.id : format).toLowerCase());
|
||||||
if (!actualFormat) {
|
if (!actualFormat) {
|
||||||
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format);
|
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format);
|
||||||
}
|
}
|
||||||
@@ -174,8 +246,6 @@ function toFormat (format, options) {
|
|||||||
/**
|
/**
|
||||||
* Use these JPEG options for output image.
|
* Use these JPEG options for output image.
|
||||||
*
|
*
|
||||||
* Some of these options require the use of a globally-installed libvips compiled with support for mozjpeg.
|
|
||||||
*
|
|
||||||
* @example
|
* @example
|
||||||
* // Convert any input to very high quality JPEG output
|
* // Convert any input to very high quality JPEG output
|
||||||
* const data = await sharp(input)
|
* const data = await sharp(input)
|
||||||
@@ -185,18 +255,25 @@ function toFormat (format, options) {
|
|||||||
* })
|
* })
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Use mozjpeg to reduce output JPEG file size (slower)
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .jpeg({ mozjpeg: true })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {number} [options.quality=80] - quality, integer 1-100
|
* @param {number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
* @param {string} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling
|
* @param {string} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling
|
||||||
* @param {boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
* @param {boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
||||||
* @param {boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
* @param {boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
||||||
* @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.mozjpeg=false] - use mozjpeg defaults, equivalent to `{ trellisQuantisation: true, overshootDeringing: true, optimiseScans: true, quantisationTable: 3 }`
|
||||||
* @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation
|
||||||
* @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing
|
||||||
* @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive
|
||||||
* @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
||||||
* @param {number} [options.quantizationTable=0] - alternative spelling of quantisationTable, requires libvips compiled with support for mozjpeg
|
* @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8
|
||||||
|
* @param {number} [options.quantizationTable=0] - alternative spelling of quantisationTable
|
||||||
* @param {boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
* @param {boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@@ -220,6 +297,23 @@ function jpeg (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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
|
||||||
|
if (is.defined(optimiseCoding)) {
|
||||||
|
this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
|
||||||
|
}
|
||||||
|
if (is.defined(options.mozjpeg)) {
|
||||||
|
if (is.bool(options.mozjpeg)) {
|
||||||
|
if (options.mozjpeg) {
|
||||||
|
this.options.jpegTrellisQuantisation = true;
|
||||||
|
this.options.jpegOvershootDeringing = true;
|
||||||
|
this.options.jpegOptimiseScans = true;
|
||||||
|
this.options.jpegProgressive = true;
|
||||||
|
this.options.jpegQuantisationTable = 3;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('mozjpeg', 'boolean', options.mozjpeg);
|
||||||
|
}
|
||||||
|
}
|
||||||
const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
|
const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
|
||||||
if (is.defined(trellisQuantisation)) {
|
if (is.defined(trellisQuantisation)) {
|
||||||
this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
|
this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
|
||||||
@@ -234,10 +328,6 @@ function jpeg (options) {
|
|||||||
this.options.jpegProgressive = true;
|
this.options.jpegProgressive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
|
|
||||||
if (is.defined(optimiseCoding)) {
|
|
||||||
this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
|
|
||||||
}
|
|
||||||
const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
|
const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
|
||||||
if (is.defined(quantisationTable)) {
|
if (is.defined(quantisationTable)) {
|
||||||
if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
|
if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
|
||||||
@@ -253,26 +343,31 @@ function jpeg (options) {
|
|||||||
/**
|
/**
|
||||||
* Use these PNG options for output image.
|
* Use these PNG options for output image.
|
||||||
*
|
*
|
||||||
* PNG output is always full colour at 8 or 16 bits per pixel.
|
* By default, PNG output is full colour at 8 or 16 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.
|
||||||
* Some of these options require the use of a globally-installed libvips compiled with support for libimagequant (GPL).
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Convert any input to PNG output
|
* // Convert any input to full colour PNG output
|
||||||
* const data = await sharp(input)
|
* const data = await sharp(input)
|
||||||
* .png()
|
* .png()
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to indexed PNG output (slower)
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .png({ palette: true })
|
||||||
|
* .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=9] - zlib compression level, 0-9
|
* @param {number} [options.compressionLevel=6] - zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest)
|
||||||
* @param {boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
* @param {boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
||||||
* @param {boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
|
* @param {boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support
|
||||||
* @param {number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
* @param {number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, sets `palette` to `true`
|
||||||
* @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
* @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`
|
||||||
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`
|
||||||
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`
|
||||||
* @param {boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
* @param {boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@@ -334,6 +429,12 @@ function png (options) {
|
|||||||
* .webp({ lossless: true })
|
* .webp({ lossless: true })
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Optimise the file size of an animated WebP
|
||||||
|
* const outputWebp = await sharp(inputWebp, { animated: true })
|
||||||
|
* .webp({ reductionEffort: 6 })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {number} [options.quality=80] - quality, integer 1-100
|
* @param {number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
* @param {number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
||||||
@@ -399,9 +500,10 @@ function webp (options) {
|
|||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
|
/* istanbul ignore next */
|
||||||
function gif (options) {
|
function gif (options) {
|
||||||
if (!this.constructor.format.magick.output.buffer) {
|
if (!this.constructor.format.magick.output.buffer) {
|
||||||
throw new Error('The gif operation requires libvips to have been installed with support for ImageMagick');
|
throw errMagickSave;
|
||||||
}
|
}
|
||||||
trySetAnimationOptions(options, this.options);
|
trySetAnimationOptions(options, this.options);
|
||||||
return this._updateFormatOut('gif', options);
|
return this._updateFormatOut('gif', options);
|
||||||
@@ -461,15 +563,15 @@ function trySetAnimationOptions (source, target) {
|
|||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {number} [options.quality=80] - quality, integer 1-100
|
* @param {number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
* @param {boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
||||||
* @param {boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
* @param {string} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
||||||
* @param {boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
* @param {string} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
||||||
* @param {boolean} [options.pyramid=false] - write an image pyramid
|
* @param {boolean} [options.pyramid=false] - write an image pyramid
|
||||||
* @param {boolean} [options.tile=false] - write a tiled tiff
|
* @param {boolean} [options.tile=false] - write a tiled tiff
|
||||||
* @param {boolean} [options.tileWidth=256] - horizontal tile size
|
* @param {number} [options.tileWidth=256] - horizontal tile size
|
||||||
* @param {boolean} [options.tileHeight=256] - vertical tile size
|
* @param {number} [options.tileHeight=256] - vertical tile size
|
||||||
* @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
* @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
||||||
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
|
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
|
||||||
* @param {boolean} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
|
* @param {number} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
@@ -546,29 +648,44 @@ function tiff (options) {
|
|||||||
return this._updateFormatOut('tiff', options);
|
return this._updateFormatOut('tiff', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use these AVIF options for output image.
|
||||||
|
*
|
||||||
|
* Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
||||||
|
* most web browsers do not display these properly.
|
||||||
|
*
|
||||||
|
* @since 0.27.0
|
||||||
|
*
|
||||||
|
* @param {Object} [options] - output options
|
||||||
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
||||||
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
||||||
|
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 8 (fastest/largest)
|
||||||
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid options
|
||||||
|
*/
|
||||||
|
function avif (options) {
|
||||||
|
return this.heif({ ...options, compression: 'av1' });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these HEIF options for output image.
|
* Use these HEIF options for output image.
|
||||||
*
|
*
|
||||||
* Support for HEIF (HEIC/AVIF) is experimental.
|
* Support for patent-encumbered HEIC images requires the use of a
|
||||||
* Do not use this in production systems.
|
* globally-installed libvips compiled with support for libheif, libde265 and x265.
|
||||||
*
|
|
||||||
* Requires a custom, globally-installed libvips compiled with support for libheif.
|
|
||||||
*
|
|
||||||
* Most versions of libheif support only the patent-encumbered HEVC compression format.
|
|
||||||
*
|
*
|
||||||
* @since 0.23.0
|
* @since 0.23.0
|
||||||
*
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {number} [options.quality=80] - quality, integer 1-100
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
||||||
* @param {boolean} [options.compression='hevc'] - compression format: hevc, avc, jpeg, av1
|
* @param {string} [options.compression='av1'] - compression format: av1, hevc
|
||||||
* @param {boolean} [options.lossless=false] - use lossless compression
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
||||||
|
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 8 (fastest/largest)
|
||||||
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
function heif (options) {
|
function heif (options) {
|
||||||
if (!this.constructor.format.heif.output.buffer) {
|
|
||||||
throw new Error('The heif operation requires libvips to have been installed with support for libheif');
|
|
||||||
}
|
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
if (is.defined(options.quality)) {
|
if (is.defined(options.quality)) {
|
||||||
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
@@ -585,10 +702,24 @@ function heif (options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(options.compression)) {
|
if (is.defined(options.compression)) {
|
||||||
if (is.string(options.compression) && is.inArray(options.compression, ['hevc', 'avc', 'jpeg', 'av1'])) {
|
if (is.string(options.compression) && is.inArray(options.compression, ['av1', 'hevc'])) {
|
||||||
this.options.heifCompression = options.compression;
|
this.options.heifCompression = options.compression;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('compression', 'one of: hevc, avc, jpeg, av1', options.compression);
|
throw is.invalidParameterError('compression', 'one of: av1, hevc', options.compression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.speed)) {
|
||||||
|
if (is.integer(options.speed) && is.inRange(options.speed, 0, 8)) {
|
||||||
|
this.options.heifSpeed = options.speed;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('speed', 'integer between 0 and 8', options.speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.chromaSubsampling)) {
|
||||||
|
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
|
||||||
|
this.options.heifChromaSubsampling = options.chromaSubsampling;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,28 +727,41 @@ function heif (options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to be raw, uncompressed, 8-bit unsigned integer (unit8) pixel data.
|
* Force output to be raw, uncompressed pixel data.
|
||||||
* Pixel ordering is left-to-right, top-to-bottom, without padding.
|
* Pixel ordering is left-to-right, top-to-bottom, without padding.
|
||||||
* Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
* Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Extract raw RGB pixel data from JPEG input
|
* // Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
||||||
* const { data, info } = await sharp('input.jpg')
|
* const { data, info } = await sharp('input.jpg')
|
||||||
* .raw()
|
* .raw()
|
||||||
* .toBuffer({ resolveWithObject: true });
|
* .toBuffer({ resolveWithObject: true });
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Extract alpha channel as raw pixel data from PNG input
|
* // Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
||||||
* const data = await sharp('input.png')
|
* const data = await sharp('input.png')
|
||||||
* .ensureAlpha()
|
* .ensureAlpha()
|
||||||
* .extractChannel(3)
|
* .extractChannel(3)
|
||||||
* .toColourspace('b-w')
|
* .toColourspace('b-w')
|
||||||
* .raw()
|
* .raw({ depth: 'ushort' })
|
||||||
* .toBuffer();
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @returns {Sharp}
|
* @param {Object} [options] - output options
|
||||||
|
* @param {string} [options.depth='uchar'] - bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex
|
||||||
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
function raw () {
|
function raw (options) {
|
||||||
|
if (is.object(options)) {
|
||||||
|
if (is.defined(options.depth)) {
|
||||||
|
if (is.string(options.depth) && is.inArray(options.depth,
|
||||||
|
['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'float', 'complex', 'double', 'dpcomplex']
|
||||||
|
)) {
|
||||||
|
this.options.rawDepth = options.depth;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('depth', 'one of: char, uchar, short, ushort, int, uint, float, complex, double, dpcomplex', options.depth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return this._updateFormatOut('raw');
|
return this._updateFormatOut('raw');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,6 +792,9 @@ function raw () {
|
|||||||
* @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, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images
|
||||||
* @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`, `zoomify` or `google`.
|
* @param {string} [options.layout='dz'] filesystem layout, possible values are `dz`, `iiif`, `zoomify` or `google`.
|
||||||
|
* @param {boolean} [options.centre=false] centre image in tile.
|
||||||
|
* @param {boolean} [options.center=false] alternative spelling of centre.
|
||||||
|
* @param {string} [options.id='https://example.com/iiif'] when `layout` is `iiif`, sets the `@id` attribute of `info.json`
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -716,6 +863,19 @@ function tile (options) {
|
|||||||
} else if (is.defined(options.layout) && options.layout === 'google') {
|
} else if (is.defined(options.layout) && options.layout === 'google') {
|
||||||
this.options.tileSkipBlanks = 5;
|
this.options.tileSkipBlanks = 5;
|
||||||
}
|
}
|
||||||
|
// Center image in tile
|
||||||
|
const centre = is.bool(options.center) ? options.center : options.centre;
|
||||||
|
if (is.defined(centre)) {
|
||||||
|
this._setBooleanOption('tileCentre', centre);
|
||||||
|
}
|
||||||
|
// @id attribute for IIIF layout
|
||||||
|
if (is.defined(options.id)) {
|
||||||
|
if (is.string(options.id)) {
|
||||||
|
this.options.tileId = options.id;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('id', 'string', options.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Format
|
// Format
|
||||||
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
||||||
@@ -874,6 +1034,7 @@ module.exports = function (Sharp) {
|
|||||||
png,
|
png,
|
||||||
webp,
|
webp,
|
||||||
tiff,
|
tiff,
|
||||||
|
avif,
|
||||||
heif,
|
heif,
|
||||||
gif,
|
gif,
|
||||||
raw,
|
raw,
|
||||||
|
|||||||
@@ -302,11 +302,20 @@ function resize (width, height, options) {
|
|||||||
* })
|
* })
|
||||||
* ...
|
* ...
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* // Add a row of 10 red pixels to the bottom
|
||||||
|
* sharp(input)
|
||||||
|
* .extend({
|
||||||
|
* bottom: 10,
|
||||||
|
* background: 'red'
|
||||||
|
* })
|
||||||
|
* ...
|
||||||
|
*
|
||||||
* @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
|
* @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
|
||||||
* @param {number} [extend.top]
|
* @param {number} [extend.top=0]
|
||||||
* @param {number} [extend.left]
|
* @param {number} [extend.left=0]
|
||||||
* @param {number} [extend.bottom]
|
* @param {number} [extend.bottom=0]
|
||||||
* @param {number} [extend.right]
|
* @param {number} [extend.right=0]
|
||||||
* @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
* @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
@@ -317,17 +326,35 @@ function extend (extend) {
|
|||||||
this.options.extendBottom = extend;
|
this.options.extendBottom = extend;
|
||||||
this.options.extendLeft = extend;
|
this.options.extendLeft = extend;
|
||||||
this.options.extendRight = extend;
|
this.options.extendRight = extend;
|
||||||
} else if (
|
} else if (is.object(extend)) {
|
||||||
is.object(extend) &&
|
if (is.defined(extend.top)) {
|
||||||
is.integer(extend.top) && extend.top >= 0 &&
|
if (is.integer(extend.top) && extend.top >= 0) {
|
||||||
is.integer(extend.bottom) && extend.bottom >= 0 &&
|
this.options.extendTop = extend.top;
|
||||||
is.integer(extend.left) && extend.left >= 0 &&
|
} else {
|
||||||
is.integer(extend.right) && extend.right >= 0
|
throw is.invalidParameterError('top', 'positive integer', extend.top);
|
||||||
) {
|
}
|
||||||
this.options.extendTop = extend.top;
|
}
|
||||||
this.options.extendBottom = extend.bottom;
|
if (is.defined(extend.bottom)) {
|
||||||
this.options.extendLeft = extend.left;
|
if (is.integer(extend.bottom) && extend.bottom >= 0) {
|
||||||
this.options.extendRight = extend.right;
|
this.options.extendBottom = extend.bottom;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('bottom', 'positive integer', extend.bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(extend.left)) {
|
||||||
|
if (is.integer(extend.left) && extend.left >= 0) {
|
||||||
|
this.options.extendLeft = extend.left;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('left', 'positive integer', extend.left);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(extend.right)) {
|
||||||
|
if (is.integer(extend.right) && extend.right >= 0) {
|
||||||
|
this.options.extendRight = extend.right;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('right', 'positive integer', extend.right);
|
||||||
|
}
|
||||||
|
}
|
||||||
this._setBackgroundColourOption('extendBackground', extend.background);
|
this._setBackgroundColourOption('extendBackground', extend.background);
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('extend', 'integer or object', extend);
|
throw is.invalidParameterError('extend', 'integer or object', extend);
|
||||||
@@ -386,7 +413,8 @@ function extract (options) {
|
|||||||
* Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
* Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
||||||
* Images consisting entirely of a single colour will calculate "boring" using the alpha channel, if any.
|
* Images consisting entirely of a single colour will calculate "boring" using the alpha channel, if any.
|
||||||
*
|
*
|
||||||
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
* The `info` response Object, obtained from callback of `.toFile()` or `.toBuffer()`,
|
||||||
|
* will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
*
|
*
|
||||||
* @param {number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
|
* @param {number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
|
|||||||
24
lib/sharp.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const platformAndArch = require('./platform')();
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
try {
|
||||||
|
module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
|
||||||
|
} catch (err) {
|
||||||
|
// Bail early if bindings aren't available
|
||||||
|
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, '', 'Possible solutions:'];
|
||||||
|
if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
|
||||||
|
help.push('- Update Homebrew: "brew update && brew upgrade vips"');
|
||||||
|
} else {
|
||||||
|
help.push(
|
||||||
|
'- Install with the --verbose flag and look for errors: "npm install --ignore-scripts=false --verbose sharp"',
|
||||||
|
`- Install for the current runtime: "npm install --platform=${process.platform} --arch=${process.arch} sharp"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
help.push(
|
||||||
|
'- Consult the installation documentation: https://sharp.pixelplumbing.com/install'
|
||||||
|
);
|
||||||
|
console.error(help.join('\n'));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const events = require('events');
|
const events = require('events');
|
||||||
|
const detectLibc = require('detect-libc');
|
||||||
|
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
const sharp = require('../build/Release/sharp.node');
|
const sharp = require('./sharp');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@@ -13,6 +15,26 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
*/
|
*/
|
||||||
const format = sharp.format();
|
const format = sharp.format();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Object containing the available interpolators and their proper values
|
||||||
|
* @readonly
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
const interpolators = {
|
||||||
|
/** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
|
||||||
|
nearest: 'nearest',
|
||||||
|
/** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
|
||||||
|
bilinear: 'bilinear',
|
||||||
|
/** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
|
||||||
|
bicubic: 'bicubic',
|
||||||
|
/** [LBB interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. */
|
||||||
|
locallyBoundedBicubic: 'lbb',
|
||||||
|
/** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
|
||||||
|
nohalo: 'nohalo',
|
||||||
|
/** [VSQBS interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
|
||||||
|
vertexSplitQuadraticBasisSpline: 'vsqbs'
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Object containing the version numbers of libvips and its dependencies.
|
* An Object containing the version numbers of libvips and its dependencies.
|
||||||
* @member
|
* @member
|
||||||
@@ -64,8 +86,12 @@ cache(true);
|
|||||||
/**
|
/**
|
||||||
* Gets or, when a concurrency is provided, sets
|
* Gets or, when a concurrency is provided, sets
|
||||||
* the number of threads _libvips'_ should create to process each image.
|
* the number of threads _libvips'_ should create to process each image.
|
||||||
* The default value is the number of CPU cores.
|
*
|
||||||
* A value of `0` will reset to this default.
|
* The default value is the number of CPU cores,
|
||||||
|
* except when using glibc-based Linux without jemalloc,
|
||||||
|
* where the default is `1` to help reduce memory fragmentation.
|
||||||
|
*
|
||||||
|
* A value of `0` will reset this to the number of CPU cores.
|
||||||
*
|
*
|
||||||
* The maximum number of images that can be processed in parallel
|
* The maximum number of images that can be processed in parallel
|
||||||
* is limited by libuv's `UV_THREADPOOL_SIZE` environment variable.
|
* is limited by libuv's `UV_THREADPOOL_SIZE` environment variable.
|
||||||
@@ -83,6 +109,11 @@ cache(true);
|
|||||||
function concurrency (concurrency) {
|
function concurrency (concurrency) {
|
||||||
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
||||||
}
|
}
|
||||||
|
/* istanbul ignore next */
|
||||||
|
if (detectLibc.family === detectLibc.GLIBC && !sharp._isUsingJemalloc()) {
|
||||||
|
// Reduce default concurrency to 1 when using glibc memory allocator
|
||||||
|
sharp.concurrency(1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An EventEmitter that emits a `change` event when a task is either:
|
* An EventEmitter that emits a `change` event when a task is either:
|
||||||
@@ -137,15 +168,12 @@ simd(true);
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
[
|
Sharp.cache = cache;
|
||||||
cache,
|
Sharp.concurrency = concurrency;
|
||||||
concurrency,
|
Sharp.counters = counters;
|
||||||
counters,
|
Sharp.simd = simd;
|
||||||
simd
|
|
||||||
].forEach(function (f) {
|
|
||||||
Sharp[f.name] = f;
|
|
||||||
});
|
|
||||||
Sharp.format = format;
|
Sharp.format = format;
|
||||||
|
Sharp.interpolators = interpolators;
|
||||||
Sharp.versions = versions;
|
Sharp.versions = versions;
|
||||||
Sharp.queue = queue;
|
Sharp.queue = queue;
|
||||||
};
|
};
|
||||||
|
|||||||
64
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images",
|
||||||
"version": "0.26.0-alpha1",
|
"version": "0.29.0",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -68,17 +68,28 @@
|
|||||||
"Brychan Bennett-Odlum <git@brychan.io>",
|
"Brychan Bennett-Odlum <git@brychan.io>",
|
||||||
"Edward Silverton <e.silverton@gmail.com>",
|
"Edward Silverton <e.silverton@gmail.com>",
|
||||||
"Roman Malieiev <aromaleev@gmail.com>",
|
"Roman Malieiev <aromaleev@gmail.com>",
|
||||||
"Tomas Szabo <tomas.szabo@deftomat.com>"
|
"Tomas Szabo <tomas.szabo@deftomat.com>",
|
||||||
|
"Robert O'Rourke <robert@o-rourke.org>",
|
||||||
|
"Guillermo Alfonso Varela Chouciño <guillevch@gmail.com>",
|
||||||
|
"Christian Flintrup <chr@gigahost.dk>",
|
||||||
|
"Manan Jadhav <manan@motionden.com>",
|
||||||
|
"Leon Radley <leon@radley.se>",
|
||||||
|
"alza54 <alza54@thiocod.in>",
|
||||||
|
"Jacob Smith <jacob@frende.me>",
|
||||||
|
"Michael Nutt <michael@nutt.im>",
|
||||||
|
"Brad Parham <baparham@gmail.com>",
|
||||||
|
"Taneli Vatanen <taneli.vatanen@gmail.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)",
|
||||||
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
||||||
"test": "semistandard && cpplint && npm run test-unit && npm run test-licensing && node install/prebuild-ci",
|
"test": "npm run test-lint && npm run test-unit && npm run test-licensing",
|
||||||
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
"test-lint": "semistandard && cpplint",
|
||||||
|
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=1000 --timeout=60000 ./test/unit/*.js",
|
||||||
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
||||||
"test-coverage": "./test/coverage/report.sh",
|
"test-coverage": "./test/coverage/report.sh",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"docs-build": "documentation lint lib && for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done && node docs/search-index/build",
|
"docs-build": "documentation lint lib && node docs/build && node docs/search-index/build",
|
||||||
"docs-serve": "cd docs && npx serve",
|
"docs-serve": "cd docs && npx serve",
|
||||||
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
||||||
},
|
},
|
||||||
@@ -86,7 +97,6 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"binding.gyp",
|
"binding.gyp",
|
||||||
"install/**",
|
"install/**",
|
||||||
"!install/prebuild-ci.js",
|
|
||||||
"lib/**",
|
"lib/**",
|
||||||
"src/**"
|
"src/**"
|
||||||
],
|
],
|
||||||
@@ -98,6 +108,7 @@
|
|||||||
"jpeg",
|
"jpeg",
|
||||||
"png",
|
"png",
|
||||||
"webp",
|
"webp",
|
||||||
|
"avif",
|
||||||
"tiff",
|
"tiff",
|
||||||
"gif",
|
"gif",
|
||||||
"svg",
|
"svg",
|
||||||
@@ -111,46 +122,45 @@
|
|||||||
"vips"
|
"vips"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^3.1.2",
|
"color": "^4.0.1",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"node-addon-api": "^3.0.0",
|
"node-addon-api": "^4.0.0",
|
||||||
"npmlog": "^4.1.2",
|
"prebuild-install": "^6.1.4",
|
||||||
"prebuild-install": "^5.3.5",
|
"semver": "^7.3.5",
|
||||||
"semver": "^7.3.2",
|
"simple-get": "^3.1.0",
|
||||||
"simple-get": "^4.0.0",
|
"tar-fs": "^2.1.1",
|
||||||
"tar-fs": "^2.1.0",
|
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^3.2.0",
|
"async": "^3.2.1",
|
||||||
"cc": "^2.0.1",
|
"cc": "^3.0.1",
|
||||||
"decompress-zip": "^0.3.2",
|
"decompress-zip": "^0.3.3",
|
||||||
"documentation": "^13.0.2",
|
"documentation": "^13.2.5",
|
||||||
"exif-reader": "^1.0.3",
|
"exif-reader": "^1.0.3",
|
||||||
"icc": "^2.0.0",
|
"icc": "^2.0.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^8.1.1",
|
"mocha": "^9.0.3",
|
||||||
"mock-fs": "^4.12.0",
|
"mock-fs": "^5.0.0",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"prebuild": "^10.0.0",
|
"prebuild": "^10.0.1",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"semistandard": "^14.2.3"
|
"semistandard": "^16.0.1"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"config": {
|
"config": {
|
||||||
"libvips": "8.10.0-rc4",
|
"libvips": "8.11.3",
|
||||||
"runtime": "napi",
|
"runtime": "napi",
|
||||||
"target": 3
|
"target": 5
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.16.0"
|
"node": ">=12.13.0"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
},
|
},
|
||||||
"binary": {
|
"binary": {
|
||||||
"napi_versions": [
|
"napi_versions": [
|
||||||
3
|
5
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"semistandard": {
|
"semistandard": {
|
||||||
|
|||||||
172
src/common.cc
@@ -36,6 +36,9 @@ namespace sharp {
|
|||||||
std::string AttrAsStr(Napi::Object obj, std::string attr) {
|
std::string AttrAsStr(Napi::Object obj, std::string attr) {
|
||||||
return obj.Get(attr).As<Napi::String>();
|
return obj.Get(attr).As<Napi::String>();
|
||||||
}
|
}
|
||||||
|
std::string AttrAsStr(Napi::Object obj, unsigned int const attr) {
|
||||||
|
return obj.Get(attr).As<Napi::String>();
|
||||||
|
}
|
||||||
uint32_t AttrAsUint32(Napi::Object obj, std::string attr) {
|
uint32_t AttrAsUint32(Napi::Object obj, std::string attr) {
|
||||||
return obj.Get(attr).As<Napi::Number>().Uint32Value();
|
return obj.Get(attr).As<Napi::Number>().Uint32Value();
|
||||||
}
|
}
|
||||||
@@ -54,13 +57,13 @@ namespace sharp {
|
|||||||
bool AttrAsBool(Napi::Object obj, std::string attr) {
|
bool AttrAsBool(Napi::Object obj, std::string attr) {
|
||||||
return obj.Get(attr).As<Napi::Boolean>().Value();
|
return obj.Get(attr).As<Napi::Boolean>().Value();
|
||||||
}
|
}
|
||||||
std::vector<double> AttrAsRgba(Napi::Object obj, std::string attr) {
|
std::vector<double> AttrAsVectorOfDouble(Napi::Object obj, std::string attr) {
|
||||||
Napi::Array background = obj.Get(attr).As<Napi::Array>();
|
Napi::Array napiArray = obj.Get(attr).As<Napi::Array>();
|
||||||
std::vector<double> rgba(background.Length());
|
std::vector<double> vectorOfDouble(napiArray.Length());
|
||||||
for (unsigned int i = 0; i < background.Length(); i++) {
|
for (unsigned int i = 0; i < napiArray.Length(); i++) {
|
||||||
rgba[i] = AttrAsDouble(background, i);
|
vectorOfDouble[i] = AttrAsDouble(napiArray, i);
|
||||||
}
|
}
|
||||||
return rgba;
|
return vectorOfDouble;
|
||||||
}
|
}
|
||||||
std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr) {
|
std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr) {
|
||||||
Napi::Array array = obj.Get(attr).As<Napi::Array>();
|
Napi::Array array = obj.Get(attr).As<Napi::Array>();
|
||||||
@@ -89,9 +92,13 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
// Raw pixel input
|
// Raw pixel input
|
||||||
if (HasAttr(input, "rawChannels")) {
|
if (HasAttr(input, "rawChannels")) {
|
||||||
|
descriptor->rawDepth = static_cast<VipsBandFormat>(
|
||||||
|
vips_enum_from_nick(nullptr, VIPS_TYPE_BAND_FORMAT,
|
||||||
|
AttrAsStr(input, "rawDepth").data()));
|
||||||
descriptor->rawChannels = AttrAsUint32(input, "rawChannels");
|
descriptor->rawChannels = AttrAsUint32(input, "rawChannels");
|
||||||
descriptor->rawWidth = AttrAsUint32(input, "rawWidth");
|
descriptor->rawWidth = AttrAsUint32(input, "rawWidth");
|
||||||
descriptor->rawHeight = AttrAsUint32(input, "rawHeight");
|
descriptor->rawHeight = AttrAsUint32(input, "rawHeight");
|
||||||
|
descriptor->rawPremultiplied = AttrAsBool(input, "rawPremultiplied");
|
||||||
}
|
}
|
||||||
// Multi-page input (GIF, TIFF, PDF)
|
// Multi-page input (GIF, TIFF, PDF)
|
||||||
if (HasAttr(input, "pages")) {
|
if (HasAttr(input, "pages")) {
|
||||||
@@ -104,12 +111,22 @@ namespace sharp {
|
|||||||
if (HasAttr(input, "level")) {
|
if (HasAttr(input, "level")) {
|
||||||
descriptor->level = AttrAsUint32(input, "level");
|
descriptor->level = AttrAsUint32(input, "level");
|
||||||
}
|
}
|
||||||
|
// subIFD (OME-TIFF)
|
||||||
|
if (HasAttr(input, "subifd")) {
|
||||||
|
descriptor->subifd = AttrAsInt32(input, "subifd");
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (HasAttr(input, "createChannels")) {
|
if (HasAttr(input, "createChannels")) {
|
||||||
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
||||||
descriptor->createWidth = AttrAsUint32(input, "createWidth");
|
descriptor->createWidth = AttrAsUint32(input, "createWidth");
|
||||||
descriptor->createHeight = AttrAsUint32(input, "createHeight");
|
descriptor->createHeight = AttrAsUint32(input, "createHeight");
|
||||||
descriptor->createBackground = AttrAsRgba(input, "createBackground");
|
if (HasAttr(input, "createNoiseType")) {
|
||||||
|
descriptor->createNoiseType = AttrAsStr(input, "createNoiseType");
|
||||||
|
descriptor->createNoiseMean = AttrAsDouble(input, "createNoiseMean");
|
||||||
|
descriptor->createNoiseSigma = AttrAsDouble(input, "createNoiseSigma");
|
||||||
|
} else {
|
||||||
|
descriptor->createBackground = AttrAsVectorOfDouble(input, "createBackground");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 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 = AttrAsUint32(input, "limitInputPixels");
|
descriptor->limitInputPixels = AttrAsUint32(input, "limitInputPixels");
|
||||||
@@ -180,6 +197,7 @@ namespace sharp {
|
|||||||
case ImageType::OPENSLIDE: id = "openslide"; break;
|
case ImageType::OPENSLIDE: id = "openslide"; break;
|
||||||
case ImageType::PPM: id = "ppm"; break;
|
case ImageType::PPM: id = "ppm"; break;
|
||||||
case ImageType::FITS: id = "fits"; break;
|
case ImageType::FITS: id = "fits"; break;
|
||||||
|
case ImageType::EXR: id = "exr"; 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;
|
||||||
@@ -188,30 +206,41 @@ namespace sharp {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regenerate this table with something like:
|
||||||
|
*
|
||||||
|
* $ vips -l foreign | grep -i load | awk '{ print $2, $1; }'
|
||||||
|
*
|
||||||
|
* Plus a bit of editing.
|
||||||
|
*/
|
||||||
std::map<std::string, ImageType> loaderToType = {
|
std::map<std::string, ImageType> loaderToType = {
|
||||||
{ "jpegload", ImageType::JPEG },
|
{ "VipsForeignLoadJpegFile", ImageType::JPEG },
|
||||||
{ "jpegload_buffer", ImageType::JPEG },
|
{ "VipsForeignLoadJpegBuffer", ImageType::JPEG },
|
||||||
{ "pngload", ImageType::PNG },
|
{ "VipsForeignLoadPngFile", ImageType::PNG },
|
||||||
{ "pngload_buffer", ImageType::PNG },
|
{ "VipsForeignLoadPngBuffer", ImageType::PNG },
|
||||||
{ "webpload", ImageType::WEBP },
|
{ "VipsForeignLoadWebpFile", ImageType::WEBP },
|
||||||
{ "webpload_buffer", ImageType::WEBP },
|
{ "VipsForeignLoadWebpBuffer", ImageType::WEBP },
|
||||||
{ "tiffload", ImageType::TIFF },
|
{ "VipsForeignLoadTiffFile", ImageType::TIFF },
|
||||||
{ "tiffload_buffer", ImageType::TIFF },
|
{ "VipsForeignLoadTiffBuffer", ImageType::TIFF },
|
||||||
{ "gifload", ImageType::GIF },
|
{ "VipsForeignLoadGifFile", ImageType::GIF },
|
||||||
{ "gifload_buffer", ImageType::GIF },
|
{ "VipsForeignLoadGifBuffer", ImageType::GIF },
|
||||||
{ "svgload", ImageType::SVG },
|
{ "VipsForeignLoadNsgifFile", ImageType::GIF },
|
||||||
{ "svgload_buffer", ImageType::SVG },
|
{ "VipsForeignLoadNsgifBuffer", ImageType::GIF },
|
||||||
{ "heifload", ImageType::HEIF },
|
{ "VipsForeignLoadSvgFile", ImageType::SVG },
|
||||||
{ "heifload_buffer", ImageType::HEIF },
|
{ "VipsForeignLoadSvgBuffer", ImageType::SVG },
|
||||||
{ "pdfload", ImageType::PDF },
|
{ "VipsForeignLoadHeifFile", ImageType::HEIF },
|
||||||
{ "pdfload_buffer", ImageType::PDF },
|
{ "VipsForeignLoadHeifBuffer", ImageType::HEIF },
|
||||||
{ "magickload", ImageType::MAGICK },
|
{ "VipsForeignLoadPdfFile", ImageType::PDF },
|
||||||
{ "magickload_buffer", ImageType::MAGICK },
|
{ "VipsForeignLoadPdfBuffer", ImageType::PDF },
|
||||||
{ "openslideload", ImageType::OPENSLIDE },
|
{ "VipsForeignLoadMagickFile", ImageType::MAGICK },
|
||||||
{ "ppmload", ImageType::PPM },
|
{ "VipsForeignLoadMagickBuffer", ImageType::MAGICK },
|
||||||
{ "fitsload", ImageType::FITS },
|
{ "VipsForeignLoadOpenslide", ImageType::OPENSLIDE },
|
||||||
{ "vipsload", ImageType::VIPS },
|
{ "VipsForeignLoadPpmFile", ImageType::PPM },
|
||||||
{ "rawload", ImageType::RAW }
|
{ "VipsForeignLoadFits", ImageType::FITS },
|
||||||
|
{ "VipsForeignLoadOpenexr", ImageType::EXR },
|
||||||
|
{ "VipsForeignLoadVips", ImageType::VIPS },
|
||||||
|
{ "VipsForeignLoadVipsFile", ImageType::VIPS },
|
||||||
|
{ "VipsForeignLoadRaw", ImageType::RAW }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -221,7 +250,7 @@ namespace sharp {
|
|||||||
ImageType imageType = ImageType::UNKNOWN;
|
ImageType imageType = ImageType::UNKNOWN;
|
||||||
char const *load = vips_foreign_find_load_buffer(buffer, length);
|
char const *load = vips_foreign_find_load_buffer(buffer, length);
|
||||||
if (load != nullptr) {
|
if (load != nullptr) {
|
||||||
auto it = loaderToType.find(vips_nickname_find(g_type_from_name(load)));
|
auto it = loaderToType.find(load);
|
||||||
if (it != loaderToType.end()) {
|
if (it != loaderToType.end()) {
|
||||||
imageType = it->second;
|
imageType = it->second;
|
||||||
}
|
}
|
||||||
@@ -236,7 +265,7 @@ namespace sharp {
|
|||||||
ImageType imageType = ImageType::UNKNOWN;
|
ImageType imageType = ImageType::UNKNOWN;
|
||||||
char const *load = vips_foreign_find_load(file);
|
char const *load = vips_foreign_find_load(file);
|
||||||
if (load != nullptr) {
|
if (load != nullptr) {
|
||||||
auto it = loaderToType.find(vips_nickname_find(g_type_from_name(load)));
|
auto it = loaderToType.find(load);
|
||||||
if (it != loaderToType.end()) {
|
if (it != loaderToType.end()) {
|
||||||
imageType = it->second;
|
imageType = it->second;
|
||||||
}
|
}
|
||||||
@@ -271,12 +300,15 @@ namespace sharp {
|
|||||||
if (descriptor->rawChannels > 0) {
|
if (descriptor->rawChannels > 0) {
|
||||||
// Raw, uncompressed pixel data
|
// Raw, uncompressed pixel data
|
||||||
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
|
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,
|
||||||
descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, VIPS_FORMAT_UCHAR);
|
descriptor->rawWidth, descriptor->rawHeight, descriptor->rawChannels, descriptor->rawDepth);
|
||||||
if (descriptor->rawChannels < 3) {
|
if (descriptor->rawChannels < 3) {
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_B_W;
|
image.get_image()->Type = VIPS_INTERPRETATION_B_W;
|
||||||
} else {
|
} else {
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
|
image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
|
||||||
}
|
}
|
||||||
|
if (descriptor->rawPremultiplied) {
|
||||||
|
image = image.unpremultiply();
|
||||||
|
}
|
||||||
imageType = ImageType::RAW;
|
imageType = ImageType::RAW;
|
||||||
} else {
|
} else {
|
||||||
// Compressed data
|
// Compressed data
|
||||||
@@ -302,6 +334,9 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::OPENSLIDE) {
|
if (imageType == ImageType::OPENSLIDE) {
|
||||||
option->set("level", descriptor->level);
|
option->set("level", descriptor->level);
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::TIFF) {
|
||||||
|
option->set("subifd", descriptor->subifd);
|
||||||
|
}
|
||||||
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);
|
||||||
@@ -316,15 +351,35 @@ namespace sharp {
|
|||||||
} else {
|
} else {
|
||||||
if (descriptor->createChannels > 0) {
|
if (descriptor->createChannels > 0) {
|
||||||
// Create new image
|
// Create new image
|
||||||
std::vector<double> background = {
|
if (descriptor->createNoiseType == "gaussian") {
|
||||||
descriptor->createBackground[0],
|
int const channels = descriptor->createChannels;
|
||||||
descriptor->createBackground[1],
|
image = VImage::new_matrix(descriptor->createWidth, descriptor->createHeight);
|
||||||
descriptor->createBackground[2]
|
std::vector<VImage> bands = {};
|
||||||
};
|
bands.reserve(channels);
|
||||||
if (descriptor->createChannels == 4) {
|
for (int _band = 0; _band < channels; _band++) {
|
||||||
background.push_back(descriptor->createBackground[3]);
|
bands.push_back(image.gaussnoise(
|
||||||
|
descriptor->createWidth,
|
||||||
|
descriptor->createHeight,
|
||||||
|
VImage::option()->set("mean", descriptor->createNoiseMean)->set("sigma", descriptor->createNoiseSigma)));
|
||||||
|
}
|
||||||
|
image = image.bandjoin(bands);
|
||||||
|
image = image.cast(VipsBandFormat::VIPS_FORMAT_UCHAR);
|
||||||
|
if (channels < 3) {
|
||||||
|
image = image.colourspace(VIPS_INTERPRETATION_B_W);
|
||||||
|
} else {
|
||||||
|
image = image.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::vector<double> background = {
|
||||||
|
descriptor->createBackground[0],
|
||||||
|
descriptor->createBackground[1],
|
||||||
|
descriptor->createBackground[2]
|
||||||
|
};
|
||||||
|
if (descriptor->createChannels == 4) {
|
||||||
|
background.push_back(descriptor->createBackground[3]);
|
||||||
|
}
|
||||||
|
image = VImage::new_matrix(descriptor->createWidth, descriptor->createHeight).new_from_image(background);
|
||||||
}
|
}
|
||||||
image = VImage::new_matrix(descriptor->createWidth, descriptor->createHeight).new_from_image(background);
|
|
||||||
image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
|
image.get_image()->Type = VIPS_INTERPRETATION_sRGB;
|
||||||
imageType = ImageType::RAW;
|
imageType = ImageType::RAW;
|
||||||
} else {
|
} else {
|
||||||
@@ -354,6 +409,9 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::OPENSLIDE) {
|
if (imageType == ImageType::OPENSLIDE) {
|
||||||
option->set("level", descriptor->level);
|
option->set("level", descriptor->level);
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::TIFF) {
|
||||||
|
option->set("subifd", descriptor->subifd);
|
||||||
|
}
|
||||||
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);
|
||||||
@@ -386,12 +444,7 @@ namespace sharp {
|
|||||||
Uses colour space interpretation with number of channels to guess this.
|
Uses colour space interpretation with number of channels to guess this.
|
||||||
*/
|
*/
|
||||||
bool HasAlpha(VImage image) {
|
bool HasAlpha(VImage image) {
|
||||||
int const bands = image.bands();
|
return image.has_alpha();
|
||||||
VipsInterpretation const interpretation = image.interpretation();
|
|
||||||
return (
|
|
||||||
(bands == 2 && interpretation == VIPS_INTERPRETATION_B_W) ||
|
|
||||||
(bands == 4 && interpretation != VIPS_INTERPRETATION_CMYK) ||
|
|
||||||
(bands == 5 && interpretation == VIPS_INTERPRETATION_CMYK));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -475,9 +528,8 @@ namespace sharp {
|
|||||||
VImage SetDensity(VImage image, const double density) {
|
VImage SetDensity(VImage image, const double density) {
|
||||||
const double pixelsPerMm = density / 25.4;
|
const double pixelsPerMm = density / 25.4;
|
||||||
VImage copy = image.copy();
|
VImage copy = image.copy();
|
||||||
copy.set("Xres", pixelsPerMm);
|
copy.get_image()->Xres = pixelsPerMm;
|
||||||
copy.set("Yres", pixelsPerMm);
|
copy.get_image()->Yres = pixelsPerMm;
|
||||||
copy.set(VIPS_META_RESOLUTION_UNIT, "in");
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,8 +537,8 @@ namespace sharp {
|
|||||||
Check the proposed format supports the current dimensions.
|
Check the proposed format supports the current dimensions.
|
||||||
*/
|
*/
|
||||||
void AssertImageTypeDimensions(VImage image, ImageType const imageType) {
|
void AssertImageTypeDimensions(VImage image, ImageType const imageType) {
|
||||||
const int height = image.get_typeof("pageHeight") == G_TYPE_INT
|
const int height = image.get_typeof(VIPS_META_PAGE_HEIGHT) == G_TYPE_INT
|
||||||
? image.get_int("pageHeight")
|
? image.get_int(VIPS_META_PAGE_HEIGHT)
|
||||||
: image.height();
|
: image.height();
|
||||||
if (imageType == ImageType::JPEG) {
|
if (imageType == ImageType::JPEG) {
|
||||||
if (image.width() > 65535 || height > 65535) {
|
if (image.width() > 65535 || height > 65535) {
|
||||||
@@ -656,26 +708,18 @@ namespace sharp {
|
|||||||
int top = 0;
|
int top = 0;
|
||||||
|
|
||||||
// assign only if valid
|
// assign only if valid
|
||||||
if (x >= 0 && x < (inWidth - outWidth)) {
|
if (x < (inWidth - outWidth)) {
|
||||||
left = x;
|
left = x;
|
||||||
} else if (x >= (inWidth - outWidth)) {
|
} else if (x >= (inWidth - outWidth)) {
|
||||||
left = inWidth - outWidth;
|
left = inWidth - outWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y >= 0 && y < (inHeight - outHeight)) {
|
if (y < (inHeight - outHeight)) {
|
||||||
top = y;
|
top = y;
|
||||||
} else if (y >= (inHeight - outHeight)) {
|
} else if (y >= (inHeight - outHeight)) {
|
||||||
top = inHeight - outHeight;
|
top = inHeight - outHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the resulting left and top could have been outside the image after calculation from bottom/right edges
|
|
||||||
if (left < 0) {
|
|
||||||
left = 0;
|
|
||||||
}
|
|
||||||
if (top < 0) {
|
|
||||||
top = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_tuple(left, top);
|
return std::make_tuple(left, top);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,10 +819,10 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
Ensures alpha channel, if missing.
|
Ensures alpha channel, if missing.
|
||||||
*/
|
*/
|
||||||
VImage EnsureAlpha(VImage image) {
|
VImage EnsureAlpha(VImage image, double const value) {
|
||||||
if (!HasAlpha(image)) {
|
if (!HasAlpha(image)) {
|
||||||
std::vector<double> alpha;
|
std::vector<double> alpha;
|
||||||
alpha.push_back(sharp::MaximumImageAlpha(image.interpretation()));
|
alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));
|
||||||
image = image.bandjoin_const(alpha);
|
image = image.bandjoin_const(alpha);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
|
|||||||
25
src/common.h
@@ -24,8 +24,10 @@
|
|||||||
|
|
||||||
// Verify platform and compiler compatibility
|
// Verify platform and compiler compatibility
|
||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 9))
|
#if (VIPS_MAJOR_VERSION < 8) || \
|
||||||
#error "libvips version 8.9.2+ is required - please see https://sharp.pixelplumbing.com/install"
|
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 11) || \
|
||||||
|
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 11 && VIPS_MICRO_VERSION < 3)
|
||||||
|
#error "libvips version 8.11.3+ is required - please see https://sharp.pixelplumbing.com/install"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
|
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
|
||||||
@@ -52,16 +54,22 @@ namespace sharp {
|
|||||||
size_t bufferLength;
|
size_t bufferLength;
|
||||||
bool isBuffer;
|
bool isBuffer;
|
||||||
double density;
|
double density;
|
||||||
|
VipsBandFormat rawDepth;
|
||||||
int rawChannels;
|
int rawChannels;
|
||||||
int rawWidth;
|
int rawWidth;
|
||||||
int rawHeight;
|
int rawHeight;
|
||||||
|
bool rawPremultiplied;
|
||||||
int pages;
|
int pages;
|
||||||
int page;
|
int page;
|
||||||
int level;
|
int level;
|
||||||
|
int subifd;
|
||||||
int createChannels;
|
int createChannels;
|
||||||
int createWidth;
|
int createWidth;
|
||||||
int createHeight;
|
int createHeight;
|
||||||
std::vector<double> createBackground;
|
std::vector<double> createBackground;
|
||||||
|
std::string createNoiseType;
|
||||||
|
double createNoiseMean;
|
||||||
|
double createNoiseSigma;
|
||||||
|
|
||||||
InputDescriptor():
|
InputDescriptor():
|
||||||
buffer(nullptr),
|
buffer(nullptr),
|
||||||
@@ -71,28 +79,34 @@ namespace sharp {
|
|||||||
bufferLength(0),
|
bufferLength(0),
|
||||||
isBuffer(FALSE),
|
isBuffer(FALSE),
|
||||||
density(72.0),
|
density(72.0),
|
||||||
|
rawDepth(VIPS_FORMAT_UCHAR),
|
||||||
rawChannels(0),
|
rawChannels(0),
|
||||||
rawWidth(0),
|
rawWidth(0),
|
||||||
rawHeight(0),
|
rawHeight(0),
|
||||||
|
rawPremultiplied(false),
|
||||||
pages(1),
|
pages(1),
|
||||||
page(0),
|
page(0),
|
||||||
level(0),
|
level(0),
|
||||||
|
subifd(-1),
|
||||||
createChannels(0),
|
createChannels(0),
|
||||||
createWidth(0),
|
createWidth(0),
|
||||||
createHeight(0),
|
createHeight(0),
|
||||||
createBackground{ 0.0, 0.0, 0.0, 255.0 } {}
|
createBackground{ 0.0, 0.0, 0.0, 255.0 },
|
||||||
|
createNoiseMean(0.0),
|
||||||
|
createNoiseSigma(0.0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convenience methods to access the attributes of a Napi::Object
|
// Convenience methods to access the attributes of a Napi::Object
|
||||||
bool HasAttr(Napi::Object obj, std::string attr);
|
bool HasAttr(Napi::Object obj, std::string attr);
|
||||||
std::string AttrAsStr(Napi::Object obj, std::string attr);
|
std::string AttrAsStr(Napi::Object obj, std::string attr);
|
||||||
|
std::string AttrAsStr(Napi::Object obj, unsigned int const attr);
|
||||||
uint32_t AttrAsUint32(Napi::Object obj, std::string attr);
|
uint32_t AttrAsUint32(Napi::Object obj, std::string attr);
|
||||||
int32_t AttrAsInt32(Napi::Object obj, std::string attr);
|
int32_t AttrAsInt32(Napi::Object obj, std::string attr);
|
||||||
int32_t AttrAsInt32(Napi::Object obj, unsigned int const attr);
|
int32_t AttrAsInt32(Napi::Object obj, unsigned int const attr);
|
||||||
double AttrAsDouble(Napi::Object obj, std::string attr);
|
double AttrAsDouble(Napi::Object obj, std::string attr);
|
||||||
double AttrAsDouble(Napi::Object obj, unsigned int const attr);
|
double AttrAsDouble(Napi::Object obj, unsigned int const attr);
|
||||||
bool AttrAsBool(Napi::Object obj, std::string attr);
|
bool AttrAsBool(Napi::Object obj, std::string attr);
|
||||||
std::vector<double> AttrAsRgba(Napi::Object obj, std::string attr);
|
std::vector<double> AttrAsVectorOfDouble(Napi::Object obj, std::string attr);
|
||||||
std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr);
|
std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr);
|
||||||
|
|
||||||
// Create an InputDescriptor instance from a Napi::Object describing an input image
|
// Create an InputDescriptor instance from a Napi::Object describing an input image
|
||||||
@@ -111,6 +125,7 @@ namespace sharp {
|
|||||||
OPENSLIDE,
|
OPENSLIDE,
|
||||||
PPM,
|
PPM,
|
||||||
FITS,
|
FITS,
|
||||||
|
EXR,
|
||||||
VIPS,
|
VIPS,
|
||||||
RAW,
|
RAW,
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
@@ -288,7 +303,7 @@ namespace sharp {
|
|||||||
/*
|
/*
|
||||||
Ensures alpha channel, if missing.
|
Ensures alpha channel, if missing.
|
||||||
*/
|
*/
|
||||||
VImage EnsureAlpha(VImage image);
|
VImage EnsureAlpha(VImage image, double const value);
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
|
|||||||
@@ -110,19 +110,6 @@ VSource::new_from_options( const char *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
VOption *
|
|
||||||
VOption::set( const char *name, const VSource value )
|
|
||||||
{
|
|
||||||
Pair *pair = new Pair( name );
|
|
||||||
|
|
||||||
pair->input = true;
|
|
||||||
g_value_init( &pair->value, VIPS_TYPE_SOURCE );
|
|
||||||
g_value_set_object( &pair->value, value.get_source() );
|
|
||||||
options.push_back( pair );
|
|
||||||
|
|
||||||
return( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
VTarget
|
VTarget
|
||||||
VTarget::new_to_descriptor( int descriptor )
|
VTarget::new_to_descriptor( int descriptor )
|
||||||
{
|
{
|
||||||
@@ -162,17 +149,4 @@ VTarget::new_to_memory()
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
VOption *
|
|
||||||
VOption::set( const char *name, const VTarget value )
|
|
||||||
{
|
|
||||||
Pair *pair = new Pair( name );
|
|
||||||
|
|
||||||
pair->input = true;
|
|
||||||
g_value_init( &pair->value, VIPS_TYPE_TARGET );
|
|
||||||
g_value_set_object( &pair->value, value.get_target() );
|
|
||||||
options.push_back( pair );
|
|
||||||
|
|
||||||
return( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
VIPS_NAMESPACE_END
|
VIPS_NAMESPACE_END
|
||||||
|
|||||||
@@ -51,6 +51,12 @@
|
|||||||
|
|
||||||
VIPS_NAMESPACE_START
|
VIPS_NAMESPACE_START
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \namespace vips
|
||||||
|
*
|
||||||
|
* General docs for the vips namespace.
|
||||||
|
*/
|
||||||
|
|
||||||
std::vector<double>
|
std::vector<double>
|
||||||
to_vectorv( int n, ... )
|
to_vectorv( int n, ... )
|
||||||
{
|
{
|
||||||
@@ -140,6 +146,20 @@ VOption::set( const char *name, int value )
|
|||||||
return( this );
|
return( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// input guint64
|
||||||
|
VOption *
|
||||||
|
VOption::set( const char *name, guint64 value )
|
||||||
|
{
|
||||||
|
Pair *pair = new Pair( name );
|
||||||
|
|
||||||
|
pair->input = true;
|
||||||
|
g_value_init( &pair->value, G_TYPE_UINT64 );
|
||||||
|
g_value_set_uint64( &pair->value, value );
|
||||||
|
options.push_back( pair );
|
||||||
|
|
||||||
|
return( this );
|
||||||
|
}
|
||||||
|
|
||||||
// input double
|
// input double
|
||||||
VOption *
|
VOption *
|
||||||
VOption::set( const char *name, double value )
|
VOption::set( const char *name, double value )
|
||||||
@@ -167,39 +187,17 @@ VOption::set( const char *name, const char *value )
|
|||||||
return( this );
|
return( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
// input image
|
// input vips object (image, source, target, etc. etc.)
|
||||||
VOption *
|
VOption *
|
||||||
VOption::set( const char *name, const VImage value )
|
VOption::set( const char *name, const VObject value )
|
||||||
{
|
{
|
||||||
Pair *pair = new Pair( name );
|
Pair *pair = new Pair( name );
|
||||||
|
VipsObject *object = value.get_object();
|
||||||
|
GType type = G_OBJECT_TYPE( object );
|
||||||
|
|
||||||
pair->input = true;
|
pair->input = true;
|
||||||
g_value_init( &pair->value, VIPS_TYPE_IMAGE );
|
g_value_init( &pair->value, type );
|
||||||
g_value_set_object( &pair->value, value.get_image() );
|
g_value_set_object( &pair->value, object );
|
||||||
options.push_back( pair );
|
|
||||||
|
|
||||||
return( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
// input double array
|
|
||||||
VOption *
|
|
||||||
VOption::set( const char *name, std::vector<double> value )
|
|
||||||
{
|
|
||||||
Pair *pair = new Pair( name );
|
|
||||||
|
|
||||||
double *array;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
pair->input = true;
|
|
||||||
|
|
||||||
g_value_init( &pair->value, VIPS_TYPE_ARRAY_DOUBLE );
|
|
||||||
vips_value_set_array_double( &pair->value, NULL,
|
|
||||||
static_cast< int >( value.size() ) );
|
|
||||||
array = vips_value_get_array_double( &pair->value, NULL );
|
|
||||||
|
|
||||||
for( i = 0; i < value.size(); i++ )
|
|
||||||
array[i] = value[i];
|
|
||||||
|
|
||||||
options.push_back( pair );
|
options.push_back( pair );
|
||||||
|
|
||||||
return( this );
|
return( this );
|
||||||
@@ -229,6 +227,30 @@ VOption::set( const char *name, std::vector<int> value )
|
|||||||
return( this );
|
return( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// input double array
|
||||||
|
VOption *
|
||||||
|
VOption::set( const char *name, std::vector<double> value )
|
||||||
|
{
|
||||||
|
Pair *pair = new Pair( name );
|
||||||
|
|
||||||
|
double *array;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
pair->input = true;
|
||||||
|
|
||||||
|
g_value_init( &pair->value, VIPS_TYPE_ARRAY_DOUBLE );
|
||||||
|
vips_value_set_array_double( &pair->value, NULL,
|
||||||
|
static_cast< int >( value.size() ) );
|
||||||
|
array = vips_value_get_array_double( &pair->value, NULL );
|
||||||
|
|
||||||
|
for( i = 0; i < value.size(); i++ )
|
||||||
|
array[i] = value[i];
|
||||||
|
|
||||||
|
options.push_back( pair );
|
||||||
|
|
||||||
|
return( this );
|
||||||
|
}
|
||||||
|
|
||||||
// input image array
|
// input image array
|
||||||
VOption *
|
VOption *
|
||||||
VOption::set( const char *name, std::vector<VImage> value )
|
VOption::set( const char *name, std::vector<VImage> value )
|
||||||
@@ -619,6 +641,22 @@ VImage::new_from_source( VSource source, const char *option_string,
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage
|
||||||
|
VImage::new_from_memory_steal( void *data, size_t size,
|
||||||
|
int width, int height, int bands, VipsBandFormat format )
|
||||||
|
{
|
||||||
|
VipsImage *image;
|
||||||
|
|
||||||
|
if( !(image = vips_image_new_from_memory( data, size,
|
||||||
|
width, height, bands, format )) )
|
||||||
|
throw( VError() );
|
||||||
|
|
||||||
|
g_signal_connect( image, "postclose",
|
||||||
|
G_CALLBACK( vips_image_free_buffer ), data);
|
||||||
|
|
||||||
|
return( VImage( image ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage
|
VImage
|
||||||
VImage::new_matrix( int width, int height )
|
VImage::new_matrix( int width, int height )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,17 +60,4 @@ VInterpolate::new_from_name( const char *name, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
VOption *
|
|
||||||
VOption::set( const char *name, const VInterpolate value )
|
|
||||||
{
|
|
||||||
Pair *pair = new Pair( name );
|
|
||||||
|
|
||||||
pair->input = true;
|
|
||||||
g_value_init( &pair->value, VIPS_TYPE_INTERPOLATE );
|
|
||||||
g_value_set_object( &pair->value, value.get_interpolate() );
|
|
||||||
options.push_back( pair );
|
|
||||||
|
|
||||||
return( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
VIPS_NAMESPACE_END
|
VIPS_NAMESPACE_END
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// bodies for vips operations
|
// bodies for vips operations
|
||||||
// Sun 5 Jul 22:36:37 BST 2020
|
// Wed May 12 11:30:00 AM CEST 2021
|
||||||
// this file is generated automatically, do not edit!
|
// this file is generated automatically, do not edit!
|
||||||
|
|
||||||
VImage VImage::CMC2LCh( VOption *options ) const
|
VImage VImage::CMC2LCh( VOption *options ) const
|
||||||
@@ -1065,6 +1065,18 @@ VImage VImage::fitsload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::fitsload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "fitsload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::fitssave( const char *filename, VOption *options ) const
|
void VImage::fitssave( const char *filename, VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "fitssave",
|
call( "fitssave",
|
||||||
@@ -1656,6 +1668,70 @@ VImage VImage::join( VImage in2, VipsDirection direction, VOption *options ) con
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::jp2kload( const char *filename, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "jp2kload",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "filename", filename ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
VImage VImage::jp2kload_buffer( VipsBlob *buffer, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "jp2kload_buffer",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "buffer", buffer ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
VImage VImage::jp2kload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "jp2kload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
void VImage::jp2ksave( const char *filename, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "jp2ksave",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "filename", filename ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
VipsBlob *VImage::jp2ksave_buffer( VOption *options ) const
|
||||||
|
{
|
||||||
|
VipsBlob *buffer;
|
||||||
|
|
||||||
|
call( "jp2ksave_buffer",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "buffer", &buffer ) );
|
||||||
|
|
||||||
|
return( buffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
void VImage::jp2ksave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "jp2ksave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::jpegload( const char *filename, VOption *options )
|
VImage VImage::jpegload( const char *filename, VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -1727,6 +1803,70 @@ void VImage::jpegsave_target( VTarget target, VOption *options ) const
|
|||||||
set( "target", target ) );
|
set( "target", target ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::jxlload( const char *filename, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "jxlload",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "filename", filename ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
VImage VImage::jxlload_buffer( VipsBlob *buffer, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "jxlload_buffer",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "buffer", buffer ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
VImage VImage::jxlload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "jxlload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
|
void VImage::jxlsave( const char *filename, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "jxlsave",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "filename", filename ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
VipsBlob *VImage::jxlsave_buffer( VOption *options ) const
|
||||||
|
{
|
||||||
|
VipsBlob *buffer;
|
||||||
|
|
||||||
|
call( "jxlsave_buffer",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "buffer", &buffer ) );
|
||||||
|
|
||||||
|
return( buffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
void VImage::jxlsave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "jxlsave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::labelregions( VOption *options ) const
|
VImage VImage::labelregions( VOption *options ) const
|
||||||
{
|
{
|
||||||
VImage mask;
|
VImage mask;
|
||||||
@@ -2284,6 +2424,18 @@ VImage VImage::niftiload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::niftiload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "niftiload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::niftisave( const char *filename, VOption *options ) const
|
void VImage::niftisave( const char *filename, VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "niftisave",
|
call( "niftisave",
|
||||||
@@ -2316,6 +2468,18 @@ VImage VImage::openslideload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::openslideload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "openslideload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::pdfload( const char *filename, VOption *options )
|
VImage VImage::pdfload( const char *filename, VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -3388,6 +3552,18 @@ VImage VImage::vipsload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::vipsload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "vipsload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::vipssave( const char *filename, VOption *options ) const
|
void VImage::vipssave( const char *filename, VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "vipssave",
|
call( "vipssave",
|
||||||
@@ -3396,6 +3572,14 @@ void VImage::vipssave( const char *filename, VOption *options ) const
|
|||||||
set( "filename", filename ) );
|
set( "filename", filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VImage::vipssave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "vipssave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::webpload( const char *filename, VOption *options )
|
VImage VImage::webpload( const char *filename, VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
if (image.get_typeof("heif-primary") == G_TYPE_INT) {
|
if (image.get_typeof("heif-primary") == G_TYPE_INT) {
|
||||||
baton->pagePrimary = image.get_int("heif-primary");
|
baton->pagePrimary = image.get_int("heif-primary");
|
||||||
}
|
}
|
||||||
|
if (image.get_typeof("heif-compression") == VIPS_TYPE_REF_STRING) {
|
||||||
|
baton->compression = image.get_string("heif-compression");
|
||||||
|
}
|
||||||
if (image.get_typeof("openslide.level-count") == VIPS_TYPE_REF_STRING) {
|
if (image.get_typeof("openslide.level-count") == VIPS_TYPE_REF_STRING) {
|
||||||
int const levels = std::stoi(image.get_string("openslide.level-count"));
|
int const levels = std::stoi(image.get_string("openslide.level-count"));
|
||||||
for (int l = 0; l < levels; l++) {
|
for (int l = 0; l < levels; l++) {
|
||||||
@@ -83,7 +86,13 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
baton->levels.push_back(std::pair<int, int>(width, height));
|
baton->levels.push_back(std::pair<int, int>(width, height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_N_SUBIFDS) == G_TYPE_INT) {
|
||||||
|
baton->subifds = image.get_int(VIPS_META_N_SUBIFDS);
|
||||||
|
}
|
||||||
baton->hasProfile = sharp::HasProfile(image);
|
baton->hasProfile = sharp::HasProfile(image);
|
||||||
|
if (image.get_typeof("background") == VIPS_TYPE_ARRAY_DOUBLE) {
|
||||||
|
baton->background = image.get_array_double("background");
|
||||||
|
}
|
||||||
// Derived attributes
|
// Derived attributes
|
||||||
baton->hasAlpha = sharp::HasAlpha(image);
|
baton->hasAlpha = sharp::HasAlpha(image);
|
||||||
baton->orientation = sharp::ExifOrientation(image);
|
baton->orientation = sharp::ExifOrientation(image);
|
||||||
@@ -186,6 +195,9 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
if (baton->pagePrimary > -1) {
|
if (baton->pagePrimary > -1) {
|
||||||
info.Set("pagePrimary", baton->pagePrimary);
|
info.Set("pagePrimary", baton->pagePrimary);
|
||||||
}
|
}
|
||||||
|
if (!baton->compression.empty()) {
|
||||||
|
info.Set("compression", baton->compression);
|
||||||
|
}
|
||||||
if (!baton->levels.empty()) {
|
if (!baton->levels.empty()) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
|
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
|
||||||
@@ -197,6 +209,20 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
info.Set("levels", levels);
|
info.Set("levels", levels);
|
||||||
}
|
}
|
||||||
|
if (baton->subifds > 0) {
|
||||||
|
info.Set("subifds", baton->subifds);
|
||||||
|
}
|
||||||
|
if (!baton->background.empty()) {
|
||||||
|
if (baton->background.size() == 3) {
|
||||||
|
Napi::Object background = Napi::Object::New(env);
|
||||||
|
background.Set("r", baton->background[0]);
|
||||||
|
background.Set("g", baton->background[1]);
|
||||||
|
background.Set("b", baton->background[2]);
|
||||||
|
info.Set("background", background);
|
||||||
|
} else {
|
||||||
|
info.Set("background", baton->background[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
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) {
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ struct MetadataBaton {
|
|||||||
int loop;
|
int loop;
|
||||||
std::vector<int> delay;
|
std::vector<int> delay;
|
||||||
int pagePrimary;
|
int pagePrimary;
|
||||||
|
std::string compression;
|
||||||
std::vector<std::pair<int, int>> levels;
|
std::vector<std::pair<int, int>> levels;
|
||||||
|
int subifds;
|
||||||
|
std::vector<double> background;
|
||||||
bool hasProfile;
|
bool hasProfile;
|
||||||
bool hasAlpha;
|
bool hasAlpha;
|
||||||
int orientation;
|
int orientation;
|
||||||
@@ -67,6 +70,7 @@ struct MetadataBaton {
|
|||||||
pageHeight(0),
|
pageHeight(0),
|
||||||
loop(-1),
|
loop(-1),
|
||||||
pagePrimary(-1),
|
pagePrimary(-1),
|
||||||
|
subifds(0),
|
||||||
hasProfile(false),
|
hasProfile(false),
|
||||||
hasAlpha(false),
|
hasAlpha(false),
|
||||||
orientation(0),
|
orientation(0),
|
||||||
|
|||||||
@@ -92,6 +92,13 @@ namespace sharp {
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contrast limiting adapative histogram equalization (CLAHE)
|
||||||
|
*/
|
||||||
|
VImage Clahe(VImage image, int const width, int const height, int const maxSlope) {
|
||||||
|
return image.hist_local(width, height, VImage::option()->set("max_slope", maxSlope));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gamma encoding/decoding
|
* Gamma encoding/decoding
|
||||||
*/
|
*/
|
||||||
@@ -105,6 +112,19 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce the "negative" of the image.
|
||||||
|
*/
|
||||||
|
VImage Negate(VImage image, bool const negateAlpha) {
|
||||||
|
if (HasAlpha(image) && !negateAlpha) {
|
||||||
|
// Separate alpha channel
|
||||||
|
VImage alpha = image[image.bands() - 1];
|
||||||
|
return RemoveAlpha(image).invert().bandjoin(alpha);
|
||||||
|
} else {
|
||||||
|
return image.invert();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
||||||
*/
|
*/
|
||||||
@@ -149,8 +169,8 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
||||||
double *m = matrix.get();
|
double *m = matrix.get();
|
||||||
|
image = image.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
return image
|
return image
|
||||||
.colourspace(VIPS_INTERPRETATION_sRGB)
|
|
||||||
.recomb(image.bands() == 3
|
.recomb(image.bands() == 3
|
||||||
? VImage::new_from_memory(
|
? VImage::new_from_memory(
|
||||||
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
||||||
@@ -275,4 +295,16 @@ namespace sharp {
|
|||||||
return image.linear(a, b);
|
return image.linear(a, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure the image is in a given colourspace
|
||||||
|
*/
|
||||||
|
VImage EnsureColourspace(VImage image, VipsInterpretation colourspace) {
|
||||||
|
if (colourspace != VIPS_INTERPRETATION_LAST && image.interpretation() != colourspace) {
|
||||||
|
image = image.colourspace(colourspace,
|
||||||
|
VImage::option()->set("source_space", image.interpretation()));
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|||||||
@@ -35,11 +35,21 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Normalise(VImage image);
|
VImage Normalise(VImage image);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contrast limiting adapative histogram equalization (CLAHE)
|
||||||
|
*/
|
||||||
|
VImage Clahe(VImage image, int const width, int const height, int const maxSlope);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gamma encoding/decoding
|
* Gamma encoding/decoding
|
||||||
*/
|
*/
|
||||||
VImage Gamma(VImage image, double const exponent);
|
VImage Gamma(VImage image, double const exponent);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Produce the "negative" of the image.
|
||||||
|
*/
|
||||||
|
VImage Negate(VImage image, bool const negateAlpha);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
||||||
*/
|
*/
|
||||||
@@ -92,6 +102,11 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Modulate(VImage image, double const brightness, double const saturation, int const hue);
|
VImage Modulate(VImage image, double const brightness, double const saturation, int const hue);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure the image is in a given colourspace
|
||||||
|
*/
|
||||||
|
VImage EnsureColourspace(VImage image, VipsInterpretation colourspace);
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
#endif // SRC_OPERATIONS_H_
|
#endif // SRC_OPERATIONS_H_
|
||||||
|
|||||||
177
src/pipeline.cc
@@ -67,6 +67,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
vips::VImage image;
|
vips::VImage image;
|
||||||
sharp::ImageType inputImageType;
|
sharp::ImageType inputImageType;
|
||||||
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
||||||
|
image = sharp::EnsureColourspace(image, baton->colourspaceInput);
|
||||||
|
|
||||||
// Calculate angle of rotation
|
// Calculate angle of rotation
|
||||||
VipsAngle rotation;
|
VipsAngle rotation;
|
||||||
@@ -214,7 +215,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
double yresidual = static_cast<double>(yshrink) / yfactor;
|
double yresidual = static_cast<double>(yshrink) / yfactor;
|
||||||
|
|
||||||
// If integral x and y shrink are equal, try to use shrink-on-load for JPEG and WebP,
|
// If integral x and y shrink are equal, try to use shrink-on-load for JPEG and WebP,
|
||||||
// but not when applying gamma correction, pre-resize extract or trim
|
// but not when applying gamma correction, pre-resize extract, trim or input colourspace
|
||||||
int shrink_on_load = 1;
|
int shrink_on_load = 1;
|
||||||
|
|
||||||
int shrink_on_load_factor = 1;
|
int shrink_on_load_factor = 1;
|
||||||
@@ -226,7 +227,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (
|
if (
|
||||||
xshrink == yshrink && xshrink >= 2 * shrink_on_load_factor &&
|
xshrink == yshrink && xshrink >= 2 * shrink_on_load_factor &&
|
||||||
(inputImageType == sharp::ImageType::JPEG || inputImageType == sharp::ImageType::WEBP) &&
|
(inputImageType == sharp::ImageType::JPEG || inputImageType == sharp::ImageType::WEBP) &&
|
||||||
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 &&
|
||||||
|
image.width() > 3 && image.height() > 3 && baton->input->pages == 1
|
||||||
) {
|
) {
|
||||||
if (xshrink >= 8 * shrink_on_load_factor) {
|
if (xshrink >= 8 * shrink_on_load_factor) {
|
||||||
xfactor = xfactor / 8;
|
xfactor = xfactor / 8;
|
||||||
@@ -324,7 +327,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
// Negate the colours in the image
|
// Negate the colours in the image
|
||||||
if (baton->negate) {
|
if (baton->negate) {
|
||||||
image = image.invert();
|
image = sharp::Negate(image, baton->negateAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gamma encoding (darken)
|
// Gamma encoding (darken)
|
||||||
@@ -344,9 +347,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
bool const shouldApplyMedian = baton->medianSize > 0;
|
bool const shouldApplyMedian = baton->medianSize > 0;
|
||||||
bool const shouldComposite = !baton->composite.empty();
|
bool const shouldComposite = !baton->composite.empty();
|
||||||
bool const shouldModulate = baton->brightness != 1.0 || baton->saturation != 1.0 || baton->hue != 0.0;
|
bool const shouldModulate = baton->brightness != 1.0 || baton->saturation != 1.0 || baton->hue != 0.0;
|
||||||
|
bool const shouldApplyClahe = baton->claheWidth != 0 && baton->claheHeight != 0;
|
||||||
|
|
||||||
if (shouldComposite && !sharp::HasAlpha(image)) {
|
if (shouldComposite && !sharp::HasAlpha(image)) {
|
||||||
image = sharp::EnsureAlpha(image);
|
image = sharp::EnsureAlpha(image, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) &&
|
bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) &&
|
||||||
@@ -409,6 +413,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++) {
|
||||||
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i]);
|
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i]);
|
||||||
|
joinImage = sharp::EnsureColourspace(joinImage, baton->colourspaceInput);
|
||||||
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));
|
||||||
@@ -485,6 +490,18 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
baton->leftOffsetPost, baton->topOffsetPost, baton->widthPost, baton->heightPost);
|
baton->leftOffsetPost, baton->topOffsetPost, baton->widthPost, baton->heightPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Affine transform
|
||||||
|
if (baton->affineMatrix.size() > 0) {
|
||||||
|
std::vector<double> background;
|
||||||
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->affineBackground);
|
||||||
|
image = image.affine(baton->affineMatrix, VImage::option()->set("background", background)
|
||||||
|
->set("idx", baton->affineIdx)
|
||||||
|
->set("idy", baton->affineIdy)
|
||||||
|
->set("odx", baton->affineOdx)
|
||||||
|
->set("ody", baton->affineOdy)
|
||||||
|
->set("interpolate", baton->affineInterpolator));
|
||||||
|
}
|
||||||
|
|
||||||
// Extend edges
|
// Extend edges
|
||||||
if (baton->extendTop > 0 || baton->extendBottom > 0 || baton->extendLeft > 0 || baton->extendRight > 0) {
|
if (baton->extendTop > 0 || baton->extendBottom > 0 || baton->extendLeft > 0 || baton->extendRight > 0) {
|
||||||
std::vector<double> background;
|
std::vector<double> background;
|
||||||
@@ -538,7 +555,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
for (Composite *composite : baton->composite) {
|
for (Composite *composite : baton->composite) {
|
||||||
VImage compositeImage;
|
VImage compositeImage;
|
||||||
sharp::ImageType compositeImageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType compositeImageType = sharp::ImageType::UNKNOWN;
|
||||||
std::tie(compositeImage, compositeImageType) = OpenInput(composite->input);
|
std::tie(compositeImage, compositeImageType) = sharp::OpenInput(composite->input);
|
||||||
|
compositeImage = sharp::EnsureColourspace(compositeImage, baton->colourspaceInput);
|
||||||
// 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");
|
||||||
@@ -550,15 +568,23 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Use gravity in overlay
|
// Use gravity in overlay
|
||||||
if (compositeImage.width() <= baton->width) {
|
if (compositeImage.width() <= baton->width) {
|
||||||
across = static_cast<int>(ceil(static_cast<double>(image.width()) / compositeImage.width()));
|
across = static_cast<int>(ceil(static_cast<double>(image.width()) / compositeImage.width()));
|
||||||
|
// Ensure odd number of tiles across when gravity is centre, north or south
|
||||||
|
if (composite->gravity == 0 || composite->gravity == 1 || composite->gravity == 3) {
|
||||||
|
across |= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (compositeImage.height() <= baton->height) {
|
if (compositeImage.height() <= baton->height) {
|
||||||
down = static_cast<int>(ceil(static_cast<double>(image.height()) / compositeImage.height()));
|
down = static_cast<int>(ceil(static_cast<double>(image.height()) / compositeImage.height()));
|
||||||
|
// Ensure odd number of tiles down when gravity is centre, east or west
|
||||||
|
if (composite->gravity == 0 || composite->gravity == 2 || composite->gravity == 4) {
|
||||||
|
down |= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (across != 0 || down != 0) {
|
if (across != 0 || down != 0) {
|
||||||
int left;
|
int left;
|
||||||
int top;
|
int top;
|
||||||
compositeImage = compositeImage.replicate(across, down);
|
compositeImage = compositeImage.replicate(across, down);
|
||||||
if (composite->left >= 0 && composite->top >= 0) {
|
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(),
|
||||||
composite->left, composite->top);
|
composite->left, composite->top);
|
||||||
@@ -574,16 +600,21 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Ensure image to composite is sRGB with premultiplied alpha
|
// Ensure image to composite is sRGB with premultiplied alpha
|
||||||
compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
|
compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
if (!sharp::HasAlpha(compositeImage)) {
|
if (!sharp::HasAlpha(compositeImage)) {
|
||||||
compositeImage = sharp::EnsureAlpha(compositeImage);
|
compositeImage = sharp::EnsureAlpha(compositeImage, 1);
|
||||||
}
|
}
|
||||||
if (!composite->premultiplied) compositeImage = compositeImage.premultiply();
|
if (!composite->premultiplied) compositeImage = compositeImage.premultiply();
|
||||||
// Calculate position
|
// Calculate position
|
||||||
int left;
|
int left;
|
||||||
int top;
|
int top;
|
||||||
if (composite->left >= 0 && composite->top >= 0) {
|
if (composite->hasOffset) {
|
||||||
// Composite image at given offsets
|
// Composite image at given offsets
|
||||||
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
if (composite->tile) {
|
||||||
compositeImage.width(), compositeImage.height(), composite->left, composite->top);
|
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
||||||
|
compositeImage.width(), compositeImage.height(), composite->left, composite->top);
|
||||||
|
} else {
|
||||||
|
left = composite->left;
|
||||||
|
top = composite->top;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Composite image with given gravity
|
// Composite image with given gravity
|
||||||
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
||||||
@@ -624,11 +655,17 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = sharp::Normalise(image);
|
image = sharp::Normalise(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply contrast limiting adaptive histogram equalization (CLAHE)
|
||||||
|
if (shouldApplyClahe) {
|
||||||
|
image = sharp::Clahe(image, baton->claheWidth, baton->claheHeight, baton->claheMaxSlope);
|
||||||
|
}
|
||||||
|
|
||||||
// Apply bitwise boolean operation between images
|
// Apply bitwise boolean operation between images
|
||||||
if (baton->boolean != nullptr) {
|
if (baton->boolean != nullptr) {
|
||||||
VImage booleanImage;
|
VImage booleanImage;
|
||||||
sharp::ImageType booleanImageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType booleanImageType = sharp::ImageType::UNKNOWN;
|
||||||
std::tie(booleanImage, booleanImageType) = sharp::OpenInput(baton->boolean);
|
std::tie(booleanImage, booleanImageType) = sharp::OpenInput(baton->boolean);
|
||||||
|
booleanImage = sharp::EnsureColourspace(booleanImage, baton->colourspaceInput);
|
||||||
image = sharp::Boolean(image, booleanImage, baton->booleanOp);
|
image = sharp::Boolean(image, booleanImage, baton->booleanOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,8 +703,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure alpha channel, if missing
|
// Ensure alpha channel, if missing
|
||||||
if (baton->ensureAlpha) {
|
if (baton->ensureAlpha != -1) {
|
||||||
image = sharp::EnsureAlpha(image);
|
image = sharp::EnsureAlpha(image, baton->ensureAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert image to sRGB, if not already
|
// Convert image to sRGB, if not already
|
||||||
@@ -684,10 +721,29 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply output ICC profile
|
||||||
|
if (!baton->withMetadataIcc.empty()) {
|
||||||
|
image = image.icc_transform(
|
||||||
|
const_cast<char*>(baton->withMetadataIcc.data()),
|
||||||
|
VImage::option()
|
||||||
|
->set("input_profile", "srgb")
|
||||||
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
|
}
|
||||||
// Override EXIF Orientation tag
|
// Override EXIF Orientation tag
|
||||||
if (baton->withMetadata && baton->withMetadataOrientation != -1) {
|
if (baton->withMetadata && baton->withMetadataOrientation != -1) {
|
||||||
image = sharp::SetExifOrientation(image, baton->withMetadataOrientation);
|
image = sharp::SetExifOrientation(image, baton->withMetadataOrientation);
|
||||||
}
|
}
|
||||||
|
// Override pixel density
|
||||||
|
if (baton->withMetadataDensity > 0) {
|
||||||
|
image = sharp::SetDensity(image, baton->withMetadataDensity);
|
||||||
|
}
|
||||||
|
// Metadata key/value pairs, e.g. EXIF
|
||||||
|
if (!baton->withMetadataStrs.empty()) {
|
||||||
|
image = image.copy();
|
||||||
|
for (const auto& s : baton->withMetadataStrs) {
|
||||||
|
image.set(s.first.data(), s.second.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Number of channels used in output image
|
// Number of channels used in output image
|
||||||
baton->channels = image.bands();
|
baton->channels = image.bands();
|
||||||
@@ -709,13 +765,13 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (baton->formatOut == "jpeg" || (baton->formatOut == "input" && inputImageType == sharp::ImageType::JPEG)) {
|
if (baton->formatOut == "jpeg" || (baton->formatOut == "input" && inputImageType == sharp::ImageType::JPEG)) {
|
||||||
// Write JPEG to buffer
|
// Write JPEG to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
||||||
VipsArea *area = VIPS_AREA(image.jpegsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.jpegsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->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"
|
||||||
? VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF
|
? VIPS_FOREIGN_SUBSAMPLE_OFF
|
||||||
: VIPS_FOREIGN_JPEG_SUBSAMPLE_ON)
|
: VIPS_FOREIGN_SUBSAMPLE_ON)
|
||||||
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
||||||
->set("quant_table", baton->jpegQuantisationTable)
|
->set("quant_table", baton->jpegQuantisationTable)
|
||||||
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
||||||
@@ -736,7 +792,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
inputImageType == sharp::ImageType::SVG))) {
|
inputImageType == sharp::ImageType::SVG))) {
|
||||||
// Write PNG to buffer
|
// Write PNG to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
||||||
VipsArea *area = VIPS_AREA(image.pngsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.pngsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
@@ -754,7 +810,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
(baton->formatOut == "input" && inputImageType == sharp::ImageType::WEBP)) {
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::WEBP)) {
|
||||||
// Write WEBP to buffer
|
// Write WEBP to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::WEBP);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::WEBP);
|
||||||
VipsArea *area = VIPS_AREA(image.webpsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.webpsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
@@ -771,8 +827,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
(baton->formatOut == "input" && inputImageType == sharp::ImageType::GIF && supportsGifOutput)) {
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::GIF && supportsGifOutput)) {
|
||||||
// Write GIF to buffer
|
// Write GIF to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
||||||
VipsArea *area = VIPS_AREA(image.magicksave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.magicksave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
|
->set("optimize_gif_frames", TRUE)
|
||||||
|
->set("optimize_gif_transparency", TRUE)
|
||||||
->set("format", "gif")));
|
->set("format", "gif")));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
@@ -790,7 +848,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
|
if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
|
||||||
image = image.cast(VIPS_FORMAT_FLOAT);
|
image = image.cast(VIPS_FORMAT_FLOAT);
|
||||||
}
|
}
|
||||||
VipsArea *area = VIPS_AREA(image.tiffsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.tiffsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->tiffQuality)
|
->set("Q", baton->tiffQuality)
|
||||||
->set("bitdepth", baton->tiffBitdepth)
|
->set("bitdepth", baton->tiffBitdepth)
|
||||||
@@ -810,10 +868,13 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
} else if (baton->formatOut == "heif" ||
|
} else if (baton->formatOut == "heif" ||
|
||||||
(baton->formatOut == "input" && inputImageType == sharp::ImageType::HEIF)) {
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::HEIF)) {
|
||||||
// Write HEIF to buffer
|
// Write HEIF to buffer
|
||||||
VipsArea *area = VIPS_AREA(image.heifsave_buffer(VImage::option()
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.heifsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("compression", baton->heifCompression)
|
|
||||||
->set("Q", baton->heifQuality)
|
->set("Q", baton->heifQuality)
|
||||||
|
->set("compression", baton->heifCompression)
|
||||||
|
->set("speed", baton->heifSpeed)
|
||||||
|
->set("subsample_mode", baton->heifChromaSubsampling == "4:4:4"
|
||||||
|
? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON)
|
||||||
->set("lossless", baton->heifLossless)));
|
->set("lossless", baton->heifLossless)));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
@@ -828,9 +889,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = image[0];
|
image = image[0];
|
||||||
baton->channels = 1;
|
baton->channels = 1;
|
||||||
}
|
}
|
||||||
if (image.format() != VIPS_FORMAT_UCHAR) {
|
if (image.format() != baton->rawDepth) {
|
||||||
// Cast pixels to uint8 (unsigned char)
|
// Cast pixels to requested format
|
||||||
image = image.cast(VIPS_FORMAT_UCHAR);
|
image = image.cast(baton->rawDepth);
|
||||||
}
|
}
|
||||||
// Get raw image data
|
// Get raw image data
|
||||||
baton->bufferOut = static_cast<char*>(image.write_to_memory(&baton->bufferOutLength));
|
baton->bufferOut = static_cast<char*>(image.write_to_memory(&baton->bufferOutLength));
|
||||||
@@ -862,7 +923,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
bool const isV = sharp::IsV(baton->fileOut);
|
bool const isV = sharp::IsV(baton->fileOut);
|
||||||
bool const mightMatchInput = baton->formatOut == "input";
|
bool const mightMatchInput = baton->formatOut == "input";
|
||||||
bool const willMatchInput = mightMatchInput &&
|
bool const willMatchInput = mightMatchInput &&
|
||||||
!(isJpeg || isPng || isWebp || isGif || isTiff || isDz || isDzZip || isV);
|
!(isJpeg || isPng || isWebp || isGif || isTiff || isHeif || isDz || isDzZip || isV);
|
||||||
|
|
||||||
if (baton->formatOut == "jpeg" || (mightMatchInput && isJpeg) ||
|
if (baton->formatOut == "jpeg" || (mightMatchInput && isJpeg) ||
|
||||||
(willMatchInput && inputImageType == sharp::ImageType::JPEG)) {
|
(willMatchInput && inputImageType == sharp::ImageType::JPEG)) {
|
||||||
@@ -873,8 +934,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
->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"
|
||||||
? VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF
|
? VIPS_FOREIGN_SUBSAMPLE_OFF
|
||||||
: VIPS_FOREIGN_JPEG_SUBSAMPLE_ON)
|
: VIPS_FOREIGN_SUBSAMPLE_ON)
|
||||||
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
||||||
->set("quant_table", baton->jpegQuantisationTable)
|
->set("quant_table", baton->jpegQuantisationTable)
|
||||||
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
||||||
@@ -916,6 +977,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
||||||
image.magicksave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.magicksave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
|
->set("optimize_gif_frames", TRUE)
|
||||||
|
->set("optimize_gif_transparency", TRUE)
|
||||||
->set("format", "gif"));
|
->set("format", "gif"));
|
||||||
baton->formatOut = "gif";
|
baton->formatOut = "gif";
|
||||||
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
||||||
@@ -925,6 +988,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
}
|
}
|
||||||
|
// Cast pixel values to float, if required
|
||||||
|
if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_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("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->tiffQuality)
|
->set("Q", baton->tiffQuality)
|
||||||
@@ -941,13 +1008,13 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
} else if (baton->formatOut == "heif" || (mightMatchInput && isHeif) ||
|
} else if (baton->formatOut == "heif" || (mightMatchInput && isHeif) ||
|
||||||
(willMatchInput && inputImageType == sharp::ImageType::HEIF)) {
|
(willMatchInput && inputImageType == sharp::ImageType::HEIF)) {
|
||||||
// Write HEIF to file
|
// Write HEIF to file
|
||||||
if (sharp::IsAvif(baton->fileOut)) {
|
|
||||||
baton->heifCompression = VIPS_FOREIGN_HEIF_COMPRESSION_AV1;
|
|
||||||
}
|
|
||||||
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("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->heifQuality)
|
->set("Q", baton->heifQuality)
|
||||||
->set("compression", baton->heifCompression)
|
->set("compression", baton->heifCompression)
|
||||||
|
->set("speed", baton->heifSpeed)
|
||||||
|
->set("subsample_mode", baton->heifChromaSubsampling == "4:4:4"
|
||||||
|
? VIPS_FOREIGN_SUBSAMPLE_OFF : VIPS_FOREIGN_SUBSAMPLE_ON)
|
||||||
->set("lossless", baton->heifLossless));
|
->set("lossless", baton->heifLossless));
|
||||||
baton->formatOut = "heif";
|
baton->formatOut = "heif";
|
||||||
} else if (baton->formatOut == "dz" || isDz || isDzZip) {
|
} else if (baton->formatOut == "dz" || isDz || isDzZip) {
|
||||||
@@ -1001,6 +1068,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
->set("suffix", const_cast<char*>(suffix.data()))
|
->set("suffix", const_cast<char*>(suffix.data()))
|
||||||
->set("angle", CalculateAngleRotation(baton->tileAngle))
|
->set("angle", CalculateAngleRotation(baton->tileAngle))
|
||||||
->set("background", baton->tileBackground)
|
->set("background", baton->tileBackground)
|
||||||
|
->set("centre", baton->tileCentre)
|
||||||
|
->set("id", const_cast<char*>(baton->tileId.data()))
|
||||||
->set("skip_blanks", baton->tileSkipBlanks);
|
->set("skip_blanks", baton->tileSkipBlanks);
|
||||||
// libvips chooses a default depth based on layout. Instead of replicating that logic here by
|
// libvips chooses a default depth based on layout. Instead of replicating that logic here by
|
||||||
// not passing anything - libvips will handle choice
|
// not passing anything - libvips will handle choice
|
||||||
@@ -1062,6 +1131,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("width", static_cast<uint32_t>(width));
|
info.Set("width", static_cast<uint32_t>(width));
|
||||||
info.Set("height", static_cast<uint32_t>(height));
|
info.Set("height", static_cast<uint32_t>(height));
|
||||||
info.Set("channels", static_cast<uint32_t>(baton->channels));
|
info.Set("channels", static_cast<uint32_t>(baton->channels));
|
||||||
|
if (baton->formatOut == "raw") {
|
||||||
|
info.Set("depth", vips_enum_nick(VIPS_TYPE_BAND_FORMAT, baton->rawDepth));
|
||||||
|
}
|
||||||
info.Set("premultiplied", baton->premultiplied);
|
info.Set("premultiplied", baton->premultiplied);
|
||||||
if (baton->hasCropOffset) {
|
if (baton->hasCropOffset) {
|
||||||
info.Set("cropOffsetLeft", static_cast<int32_t>(baton->cropOffsetLeft));
|
info.Set("cropOffsetLeft", static_cast<int32_t>(baton->cropOffsetLeft));
|
||||||
@@ -1228,6 +1300,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
composite->gravity = sharp::AttrAsUint32(compositeObject, "gravity");
|
composite->gravity = sharp::AttrAsUint32(compositeObject, "gravity");
|
||||||
composite->left = sharp::AttrAsInt32(compositeObject, "left");
|
composite->left = sharp::AttrAsInt32(compositeObject, "left");
|
||||||
composite->top = sharp::AttrAsInt32(compositeObject, "top");
|
composite->top = sharp::AttrAsInt32(compositeObject, "top");
|
||||||
|
composite->hasOffset = sharp::AttrAsBool(compositeObject, "hasOffset");
|
||||||
composite->tile = sharp::AttrAsBool(compositeObject, "tile");
|
composite->tile = sharp::AttrAsBool(compositeObject, "tile");
|
||||||
composite->premultiplied = sharp::AttrAsBool(compositeObject, "premultiplied");
|
composite->premultiplied = sharp::AttrAsBool(compositeObject, "premultiplied");
|
||||||
baton->composite.push_back(composite);
|
baton->composite.push_back(composite);
|
||||||
@@ -1235,7 +1308,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
// Resize options
|
// Resize options
|
||||||
baton->withoutEnlargement = sharp::AttrAsBool(options, "withoutEnlargement");
|
baton->withoutEnlargement = sharp::AttrAsBool(options, "withoutEnlargement");
|
||||||
baton->position = sharp::AttrAsInt32(options, "position");
|
baton->position = sharp::AttrAsInt32(options, "position");
|
||||||
baton->resizeBackground = sharp::AttrAsRgba(options, "resizeBackground");
|
baton->resizeBackground = sharp::AttrAsVectorOfDouble(options, "resizeBackground");
|
||||||
baton->kernel = sharp::AttrAsStr(options, "kernel");
|
baton->kernel = sharp::AttrAsStr(options, "kernel");
|
||||||
baton->fastShrinkOnLoad = sharp::AttrAsBool(options, "fastShrinkOnLoad");
|
baton->fastShrinkOnLoad = sharp::AttrAsBool(options, "fastShrinkOnLoad");
|
||||||
// Join Channel Options
|
// Join Channel Options
|
||||||
@@ -1248,8 +1321,9 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
}
|
}
|
||||||
// Operators
|
// Operators
|
||||||
baton->flatten = sharp::AttrAsBool(options, "flatten");
|
baton->flatten = sharp::AttrAsBool(options, "flatten");
|
||||||
baton->flattenBackground = sharp::AttrAsRgba(options, "flattenBackground");
|
baton->flattenBackground = sharp::AttrAsVectorOfDouble(options, "flattenBackground");
|
||||||
baton->negate = sharp::AttrAsBool(options, "negate");
|
baton->negate = sharp::AttrAsBool(options, "negate");
|
||||||
|
baton->negateAlpha = sharp::AttrAsBool(options, "negateAlpha");
|
||||||
baton->blurSigma = sharp::AttrAsDouble(options, "blurSigma");
|
baton->blurSigma = sharp::AttrAsDouble(options, "blurSigma");
|
||||||
baton->brightness = sharp::AttrAsDouble(options, "brightness");
|
baton->brightness = sharp::AttrAsDouble(options, "brightness");
|
||||||
baton->saturation = sharp::AttrAsDouble(options, "saturation");
|
baton->saturation = sharp::AttrAsDouble(options, "saturation");
|
||||||
@@ -1267,10 +1341,13 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->linearB = sharp::AttrAsDouble(options, "linearB");
|
baton->linearB = sharp::AttrAsDouble(options, "linearB");
|
||||||
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->claheWidth = sharp::AttrAsUint32(options, "claheWidth");
|
||||||
|
baton->claheHeight = sharp::AttrAsUint32(options, "claheHeight");
|
||||||
|
baton->claheMaxSlope = sharp::AttrAsUint32(options, "claheMaxSlope");
|
||||||
baton->useExifOrientation = sharp::AttrAsBool(options, "useExifOrientation");
|
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::AttrAsRgba(options, "rotationBackground");
|
baton->rotationBackground = sharp::AttrAsVectorOfDouble(options, "rotationBackground");
|
||||||
baton->rotateBeforePreExtract = sharp::AttrAsBool(options, "rotateBeforePreExtract");
|
baton->rotateBeforePreExtract = sharp::AttrAsBool(options, "rotateBeforePreExtract");
|
||||||
baton->flip = sharp::AttrAsBool(options, "flip");
|
baton->flip = sharp::AttrAsBool(options, "flip");
|
||||||
baton->flop = sharp::AttrAsBool(options, "flop");
|
baton->flop = sharp::AttrAsBool(options, "flop");
|
||||||
@@ -1278,11 +1355,18 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->extendBottom = sharp::AttrAsInt32(options, "extendBottom");
|
baton->extendBottom = sharp::AttrAsInt32(options, "extendBottom");
|
||||||
baton->extendLeft = sharp::AttrAsInt32(options, "extendLeft");
|
baton->extendLeft = sharp::AttrAsInt32(options, "extendLeft");
|
||||||
baton->extendRight = sharp::AttrAsInt32(options, "extendRight");
|
baton->extendRight = sharp::AttrAsInt32(options, "extendRight");
|
||||||
baton->extendBackground = sharp::AttrAsRgba(options, "extendBackground");
|
baton->extendBackground = sharp::AttrAsVectorOfDouble(options, "extendBackground");
|
||||||
baton->extractChannel = sharp::AttrAsInt32(options, "extractChannel");
|
baton->extractChannel = sharp::AttrAsInt32(options, "extractChannel");
|
||||||
|
baton->affineMatrix = sharp::AttrAsVectorOfDouble(options, "affineMatrix");
|
||||||
|
baton->affineBackground = sharp::AttrAsVectorOfDouble(options, "affineBackground");
|
||||||
|
baton->affineIdx = sharp::AttrAsDouble(options, "affineIdx");
|
||||||
|
baton->affineIdy = sharp::AttrAsDouble(options, "affineIdy");
|
||||||
|
baton->affineOdx = sharp::AttrAsDouble(options, "affineOdx");
|
||||||
|
baton->affineOdy = sharp::AttrAsDouble(options, "affineOdy");
|
||||||
|
baton->affineInterpolator = vips::VInterpolate::new_from_name(sharp::AttrAsStr(options, "affineInterpolator").data());
|
||||||
|
|
||||||
baton->removeAlpha = sharp::AttrAsBool(options, "removeAlpha");
|
baton->removeAlpha = sharp::AttrAsBool(options, "removeAlpha");
|
||||||
baton->ensureAlpha = sharp::AttrAsBool(options, "ensureAlpha");
|
baton->ensureAlpha = sharp::AttrAsDouble(options, "ensureAlpha");
|
||||||
if (options.Has("boolean")) {
|
if (options.Has("boolean")) {
|
||||||
baton->boolean = sharp::CreateInputDescriptor(options.Get("boolean").As<Napi::Object>());
|
baton->boolean = sharp::CreateInputDescriptor(options.Get("boolean").As<Napi::Object>());
|
||||||
baton->booleanOp = sharp::GetBooleanOperation(sharp::AttrAsStr(options, "booleanOp"));
|
baton->booleanOp = sharp::GetBooleanOperation(sharp::AttrAsStr(options, "booleanOp"));
|
||||||
@@ -1310,6 +1394,10 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
|
baton->recombMatrix[i] = sharp::AttrAsDouble(recombMatrix, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
baton->colourspaceInput = sharp::GetInterpretation(sharp::AttrAsStr(options, "colourspaceInput"));
|
||||||
|
if (baton->colourspaceInput == VIPS_INTERPRETATION_ERROR) {
|
||||||
|
baton->colourspaceInput = VIPS_INTERPRETATION_LAST;
|
||||||
|
}
|
||||||
baton->colourspace = sharp::GetInterpretation(sharp::AttrAsStr(options, "colourspace"));
|
baton->colourspace = sharp::GetInterpretation(sharp::AttrAsStr(options, "colourspace"));
|
||||||
if (baton->colourspace == VIPS_INTERPRETATION_ERROR) {
|
if (baton->colourspace == VIPS_INTERPRETATION_ERROR) {
|
||||||
baton->colourspace = VIPS_INTERPRETATION_sRGB;
|
baton->colourspace = VIPS_INTERPRETATION_sRGB;
|
||||||
@@ -1319,6 +1407,14 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->fileOut = sharp::AttrAsStr(options, "fileOut");
|
baton->fileOut = sharp::AttrAsStr(options, "fileOut");
|
||||||
baton->withMetadata = sharp::AttrAsBool(options, "withMetadata");
|
baton->withMetadata = sharp::AttrAsBool(options, "withMetadata");
|
||||||
baton->withMetadataOrientation = sharp::AttrAsUint32(options, "withMetadataOrientation");
|
baton->withMetadataOrientation = sharp::AttrAsUint32(options, "withMetadataOrientation");
|
||||||
|
baton->withMetadataDensity = sharp::AttrAsDouble(options, "withMetadataDensity");
|
||||||
|
baton->withMetadataIcc = sharp::AttrAsStr(options, "withMetadataIcc");
|
||||||
|
Napi::Object mdStrs = options.Get("withMetadataStrs").As<Napi::Object>();
|
||||||
|
Napi::Array mdStrKeys = mdStrs.GetPropertyNames();
|
||||||
|
for (unsigned int i = 0; i < mdStrKeys.Length(); i++) {
|
||||||
|
std::string k = sharp::AttrAsStr(mdStrKeys, i);
|
||||||
|
baton->withMetadataStrs.insert(std::make_pair(k, sharp::AttrAsStr(mdStrs, k)));
|
||||||
|
}
|
||||||
// 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");
|
||||||
@@ -1361,6 +1457,13 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->heifCompression = static_cast<VipsForeignHeifCompression>(
|
baton->heifCompression = static_cast<VipsForeignHeifCompression>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_HEIF_COMPRESSION,
|
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_HEIF_COMPRESSION,
|
||||||
sharp::AttrAsStr(options, "heifCompression").data()));
|
sharp::AttrAsStr(options, "heifCompression").data()));
|
||||||
|
baton->heifSpeed = sharp::AttrAsUint32(options, "heifSpeed");
|
||||||
|
baton->heifChromaSubsampling = sharp::AttrAsStr(options, "heifChromaSubsampling");
|
||||||
|
|
||||||
|
// Raw output
|
||||||
|
baton->rawDepth = static_cast<VipsBandFormat>(
|
||||||
|
vips_enum_from_nick(nullptr, VIPS_TYPE_BAND_FORMAT,
|
||||||
|
sharp::AttrAsStr(options, "rawDepth").data()));
|
||||||
|
|
||||||
// Animated output
|
// Animated output
|
||||||
if (sharp::HasAttr(options, "pageHeight")) {
|
if (sharp::HasAttr(options, "pageHeight")) {
|
||||||
@@ -1377,7 +1480,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
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");
|
||||||
baton->tileBackground = sharp::AttrAsRgba(options, "tileBackground");
|
baton->tileBackground = sharp::AttrAsVectorOfDouble(options, "tileBackground");
|
||||||
baton->tileSkipBlanks = sharp::AttrAsInt32(options, "tileSkipBlanks");
|
baton->tileSkipBlanks = sharp::AttrAsInt32(options, "tileSkipBlanks");
|
||||||
baton->tileContainer = static_cast<VipsForeignDzContainer>(
|
baton->tileContainer = static_cast<VipsForeignDzContainer>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_DZ_CONTAINER,
|
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_DZ_CONTAINER,
|
||||||
@@ -1389,6 +1492,8 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->tileDepth = static_cast<VipsForeignDzDepth>(
|
baton->tileDepth = static_cast<VipsForeignDzDepth>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_DZ_DEPTH,
|
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_DZ_DEPTH,
|
||||||
sharp::AttrAsStr(options, "tileDepth").data()));
|
sharp::AttrAsStr(options, "tileDepth").data()));
|
||||||
|
baton->tileCentre = sharp::AttrAsBool(options, "tileCentre");
|
||||||
|
baton->tileId = sharp::AttrAsStr(options, "tileId");
|
||||||
|
|
||||||
// Force random access for certain operations
|
// Force random access for certain operations
|
||||||
if (baton->input->access == VIPS_ACCESS_SEQUENTIAL) {
|
if (baton->input->access == VIPS_ACCESS_SEQUENTIAL) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
@@ -40,6 +41,7 @@ struct Composite {
|
|||||||
int gravity;
|
int gravity;
|
||||||
int left;
|
int left;
|
||||||
int top;
|
int top;
|
||||||
|
bool hasOffset;
|
||||||
bool tile;
|
bool tile;
|
||||||
bool premultiplied;
|
bool premultiplied;
|
||||||
|
|
||||||
@@ -47,8 +49,9 @@ struct Composite {
|
|||||||
input(nullptr),
|
input(nullptr),
|
||||||
mode(VIPS_BLEND_MODE_OVER),
|
mode(VIPS_BLEND_MODE_OVER),
|
||||||
gravity(0),
|
gravity(0),
|
||||||
left(-1),
|
left(0),
|
||||||
top(-1),
|
top(0),
|
||||||
|
hasOffset(false),
|
||||||
tile(false),
|
tile(false),
|
||||||
premultiplied(false) {}
|
premultiplied(false) {}
|
||||||
};
|
};
|
||||||
@@ -79,6 +82,7 @@ struct PipelineBaton {
|
|||||||
int cropOffsetLeft;
|
int cropOffsetLeft;
|
||||||
int cropOffsetTop;
|
int cropOffsetTop;
|
||||||
bool premultiplied;
|
bool premultiplied;
|
||||||
|
bool tileCentre;
|
||||||
std::string kernel;
|
std::string kernel;
|
||||||
bool fastShrinkOnLoad;
|
bool fastShrinkOnLoad;
|
||||||
double tintA;
|
double tintA;
|
||||||
@@ -86,6 +90,7 @@ struct PipelineBaton {
|
|||||||
bool flatten;
|
bool flatten;
|
||||||
std::vector<double> flattenBackground;
|
std::vector<double> flattenBackground;
|
||||||
bool negate;
|
bool negate;
|
||||||
|
bool negateAlpha;
|
||||||
double blurSigma;
|
double blurSigma;
|
||||||
double brightness;
|
double brightness;
|
||||||
double saturation;
|
double saturation;
|
||||||
@@ -105,6 +110,9 @@ struct PipelineBaton {
|
|||||||
double gammaOut;
|
double gammaOut;
|
||||||
bool greyscale;
|
bool greyscale;
|
||||||
bool normalise;
|
bool normalise;
|
||||||
|
int claheWidth;
|
||||||
|
int claheHeight;
|
||||||
|
int claheMaxSlope;
|
||||||
bool useExifOrientation;
|
bool useExifOrientation;
|
||||||
int angle;
|
int angle;
|
||||||
double rotationAngle;
|
double rotationAngle;
|
||||||
@@ -118,6 +126,13 @@ struct PipelineBaton {
|
|||||||
int extendRight;
|
int extendRight;
|
||||||
std::vector<double> extendBackground;
|
std::vector<double> extendBackground;
|
||||||
bool withoutEnlargement;
|
bool withoutEnlargement;
|
||||||
|
std::vector<double> affineMatrix;
|
||||||
|
std::vector<double> affineBackground;
|
||||||
|
double affineIdx;
|
||||||
|
double affineIdy;
|
||||||
|
double affineOdx;
|
||||||
|
double affineOdy;
|
||||||
|
vips::VInterpolate affineInterpolator;
|
||||||
int jpegQuality;
|
int jpegQuality;
|
||||||
bool jpegProgressive;
|
bool jpegProgressive;
|
||||||
std::string jpegChromaSubsampling;
|
std::string jpegChromaSubsampling;
|
||||||
@@ -151,10 +166,16 @@ struct PipelineBaton {
|
|||||||
double tiffYres;
|
double tiffYres;
|
||||||
int heifQuality;
|
int heifQuality;
|
||||||
VipsForeignHeifCompression heifCompression;
|
VipsForeignHeifCompression heifCompression;
|
||||||
|
int heifSpeed;
|
||||||
|
std::string heifChromaSubsampling;
|
||||||
bool heifLossless;
|
bool heifLossless;
|
||||||
|
VipsBandFormat rawDepth;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool withMetadata;
|
bool withMetadata;
|
||||||
int withMetadataOrientation;
|
int withMetadataOrientation;
|
||||||
|
double withMetadataDensity;
|
||||||
|
std::string withMetadataIcc;
|
||||||
|
std::unordered_map<std::string, std::string> withMetadataStrs;
|
||||||
std::unique_ptr<double[]> convKernel;
|
std::unique_ptr<double[]> convKernel;
|
||||||
int convKernelWidth;
|
int convKernelWidth;
|
||||||
int convKernelHeight;
|
int convKernelHeight;
|
||||||
@@ -165,7 +186,8 @@ struct PipelineBaton {
|
|||||||
VipsOperationBoolean bandBoolOp;
|
VipsOperationBoolean bandBoolOp;
|
||||||
int extractChannel;
|
int extractChannel;
|
||||||
bool removeAlpha;
|
bool removeAlpha;
|
||||||
bool ensureAlpha;
|
double ensureAlpha;
|
||||||
|
VipsInterpretation colourspaceInput;
|
||||||
VipsInterpretation colourspace;
|
VipsInterpretation colourspace;
|
||||||
int pageHeight;
|
int pageHeight;
|
||||||
std::vector<int> delay;
|
std::vector<int> delay;
|
||||||
@@ -179,6 +201,7 @@ struct PipelineBaton {
|
|||||||
std::vector<double> tileBackground;
|
std::vector<double> tileBackground;
|
||||||
int tileSkipBlanks;
|
int tileSkipBlanks;
|
||||||
VipsForeignDzDepth tileDepth;
|
VipsForeignDzDepth tileDepth;
|
||||||
|
std::string tileId;
|
||||||
std::unique_ptr<double[]> recombMatrix;
|
std::unique_ptr<double[]> recombMatrix;
|
||||||
|
|
||||||
PipelineBaton():
|
PipelineBaton():
|
||||||
@@ -199,6 +222,7 @@ struct PipelineBaton {
|
|||||||
flatten(false),
|
flatten(false),
|
||||||
flattenBackground{ 0.0, 0.0, 0.0 },
|
flattenBackground{ 0.0, 0.0, 0.0 },
|
||||||
negate(false),
|
negate(false),
|
||||||
|
negateAlpha(true),
|
||||||
blurSigma(0.0),
|
blurSigma(0.0),
|
||||||
brightness(1.0),
|
brightness(1.0),
|
||||||
saturation(1.0),
|
saturation(1.0),
|
||||||
@@ -217,6 +241,9 @@ struct PipelineBaton {
|
|||||||
gamma(0.0),
|
gamma(0.0),
|
||||||
greyscale(false),
|
greyscale(false),
|
||||||
normalise(false),
|
normalise(false),
|
||||||
|
claheWidth(0),
|
||||||
|
claheHeight(0),
|
||||||
|
claheMaxSlope(3),
|
||||||
useExifOrientation(false),
|
useExifOrientation(false),
|
||||||
angle(0),
|
angle(0),
|
||||||
rotationAngle(0.0),
|
rotationAngle(0.0),
|
||||||
@@ -229,6 +256,13 @@ struct PipelineBaton {
|
|||||||
extendRight(0),
|
extendRight(0),
|
||||||
extendBackground{ 0.0, 0.0, 0.0, 255.0 },
|
extendBackground{ 0.0, 0.0, 0.0, 255.0 },
|
||||||
withoutEnlargement(false),
|
withoutEnlargement(false),
|
||||||
|
affineMatrix{ 1.0, 0.0, 0.0, 1.0 },
|
||||||
|
affineBackground{ 0.0, 0.0, 0.0, 255.0 },
|
||||||
|
affineIdx(0),
|
||||||
|
affineIdy(0),
|
||||||
|
affineOdx(0),
|
||||||
|
affineOdy(0),
|
||||||
|
affineInterpolator(vips::VInterpolate::new_from_name("bicubic")),
|
||||||
jpegQuality(80),
|
jpegQuality(80),
|
||||||
jpegProgressive(false),
|
jpegProgressive(false),
|
||||||
jpegChromaSubsampling("4:2:0"),
|
jpegChromaSubsampling("4:2:0"),
|
||||||
@@ -238,7 +272,7 @@ struct PipelineBaton {
|
|||||||
jpegOptimiseScans(false),
|
jpegOptimiseScans(false),
|
||||||
jpegOptimiseCoding(true),
|
jpegOptimiseCoding(true),
|
||||||
pngProgressive(false),
|
pngProgressive(false),
|
||||||
pngCompressionLevel(9),
|
pngCompressionLevel(6),
|
||||||
pngAdaptiveFiltering(false),
|
pngAdaptiveFiltering(false),
|
||||||
pngPalette(false),
|
pngPalette(false),
|
||||||
pngQuality(100),
|
pngQuality(100),
|
||||||
@@ -260,11 +294,15 @@ struct PipelineBaton {
|
|||||||
tiffTileWidth(256),
|
tiffTileWidth(256),
|
||||||
tiffXres(1.0),
|
tiffXres(1.0),
|
||||||
tiffYres(1.0),
|
tiffYres(1.0),
|
||||||
heifQuality(80),
|
heifQuality(50),
|
||||||
heifCompression(VIPS_FOREIGN_HEIF_COMPRESSION_HEVC),
|
heifCompression(VIPS_FOREIGN_HEIF_COMPRESSION_AV1),
|
||||||
|
heifSpeed(5),
|
||||||
|
heifChromaSubsampling("4:4:4"),
|
||||||
heifLossless(false),
|
heifLossless(false),
|
||||||
|
rawDepth(VIPS_FORMAT_UCHAR),
|
||||||
withMetadata(false),
|
withMetadata(false),
|
||||||
withMetadataOrientation(-1),
|
withMetadataOrientation(-1),
|
||||||
|
withMetadataDensity(0.0),
|
||||||
convKernelWidth(0),
|
convKernelWidth(0),
|
||||||
convKernelHeight(0),
|
convKernelHeight(0),
|
||||||
convKernelScale(0.0),
|
convKernelScale(0.0),
|
||||||
@@ -274,7 +312,8 @@ struct PipelineBaton {
|
|||||||
bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
|
bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
|
||||||
extractChannel(-1),
|
extractChannel(-1),
|
||||||
removeAlpha(false),
|
removeAlpha(false),
|
||||||
ensureAlpha(false),
|
ensureAlpha(-1.0),
|
||||||
|
colourspaceInput(VIPS_INTERPRETATION_LAST),
|
||||||
colourspace(VIPS_INTERPRETATION_LAST),
|
colourspace(VIPS_INTERPRETATION_LAST),
|
||||||
pageHeight(0),
|
pageHeight(0),
|
||||||
delay{-1},
|
delay{-1},
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
|
|
||||||
static void* sharp_vips_init(void*) {
|
static void* sharp_vips_init(void*) {
|
||||||
|
g_setenv("VIPS_MIN_STACK_SIZE", "2m", FALSE);
|
||||||
vips_init("sharp");
|
vips_init("sharp");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -43,6 +44,7 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
|
|||||||
exports.Set("libvipsVersion", Napi::Function::New(env, libvipsVersion));
|
exports.Set("libvipsVersion", Napi::Function::New(env, libvipsVersion));
|
||||||
exports.Set("format", Napi::Function::New(env, format));
|
exports.Set("format", Napi::Function::New(env, format));
|
||||||
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("stats", Napi::Function::New(env, stats));
|
exports.Set("stats", Napi::Function::New(env, stats));
|
||||||
return exports;
|
return exports;
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/stats.cc
@@ -80,12 +80,14 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
// Estimate entropy via histogram of greyscale value frequency
|
// Estimate entropy via histogram of greyscale value frequency
|
||||||
baton->entropy = std::abs(greyscale.hist_find().hist_entropy());
|
baton->entropy = std::abs(greyscale.hist_find().hist_entropy());
|
||||||
// Estimate sharpness via standard deviation of greyscale laplacian
|
// Estimate sharpness via standard deviation of greyscale laplacian
|
||||||
VImage laplacian = VImage::new_matrixv(3, 3,
|
if (image.width() > 1 || image.height() > 1) {
|
||||||
0.0, 1.0, 0.0,
|
VImage laplacian = VImage::new_matrixv(3, 3,
|
||||||
1.0, -4.0, 1.0,
|
0.0, 1.0, 0.0,
|
||||||
0.0, 1.0, 0.0);
|
1.0, -4.0, 1.0,
|
||||||
laplacian.set("scale", 9.0);
|
0.0, 1.0, 0.0);
|
||||||
baton->sharpness = greyscale.conv(laplacian).deviate();
|
laplacian.set("scale", 9.0);
|
||||||
|
baton->sharpness = greyscale.conv(laplacian).deviate();
|
||||||
|
}
|
||||||
// Most dominant sRGB colour via 4096-bin 3D histogram
|
// Most dominant sRGB colour via 4096-bin 3D histogram
|
||||||
vips::VImage hist = sharp::RemoveAlpha(image)
|
vips::VImage hist = sharp::RemoveAlpha(image)
|
||||||
.colourspace(VIPS_INTERPRETATION_sRGB)
|
.colourspace(VIPS_INTERPRETATION_sRGB)
|
||||||
|
|||||||
@@ -225,3 +225,19 @@ Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {
|
|||||||
|
|
||||||
return Napi::Number::New(env, maxColourDistance);
|
return Napi::Number::New(env, maxColourDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
// mallctl will be resolved by the runtime linker when jemalloc is being used
|
||||||
|
extern "C" {
|
||||||
|
int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) __attribute__((weak));
|
||||||
|
}
|
||||||
|
Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {
|
||||||
|
Napi::Env env = info.Env();
|
||||||
|
return Napi::Boolean::New(env, mallctl != nullptr);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Napi::Value _isUsingJemalloc(const Napi::CallbackInfo& info) {
|
||||||
|
Napi::Env env = info.Env();
|
||||||
|
return Napi::Boolean::New(env, false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -24,5 +24,6 @@ Napi::Value simd(const Napi::CallbackInfo& info);
|
|||||||
Napi::Value libvipsVersion(const Napi::CallbackInfo& info);
|
Napi::Value libvipsVersion(const Napi::CallbackInfo& info);
|
||||||
Napi::Value format(const Napi::CallbackInfo& info);
|
Napi::Value format(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);
|
||||||
|
|
||||||
#endif // SRC_UTILITIES_H_
|
#endif // SRC_UTILITIES_H_
|
||||||
|
|||||||
@@ -8,16 +8,18 @@
|
|||||||
"test": "node perf && node random && node parallel"
|
"test": "node perf && node random && node parallel"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^3.1.0",
|
"@squoosh/cli": "0.7.2",
|
||||||
"benchmark": "^2.1.4",
|
"@squoosh/lib": "0.4.0",
|
||||||
"gm": "^1.23.1",
|
"async": "3.2.1",
|
||||||
"imagemagick": "^0.1.3",
|
"benchmark": "2.1.4",
|
||||||
"jimp": "^0.9.3",
|
"gm": "1.23.1",
|
||||||
"mapnik": "^4.3.1",
|
"imagemagick": "0.1.3",
|
||||||
"semver": "^7.1.1"
|
"jimp": "0.16.1",
|
||||||
|
"mapnik": "4.5.8",
|
||||||
|
"semver": "7.3.5"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.5.0"
|
"node": "16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const os = require('os');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
@@ -12,15 +14,23 @@ const gm = require('gm');
|
|||||||
const imagemagick = require('imagemagick');
|
const imagemagick = require('imagemagick');
|
||||||
const mapnik = require('mapnik');
|
const mapnik = require('mapnik');
|
||||||
const jimp = require('jimp');
|
const jimp = require('jimp');
|
||||||
|
const squoosh = require('@squoosh/lib');
|
||||||
|
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
const outputJpg = fixtures.path('output.jpg');
|
||||||
|
const outputPng = fixtures.path('output.png');
|
||||||
|
const outputWebP = fixtures.path('output.webp');
|
||||||
|
|
||||||
const width = 720;
|
const width = 720;
|
||||||
const height = 588;
|
const height = 588;
|
||||||
|
|
||||||
// Disable libvips cache to ensure tests are as fair as they can be
|
// Disable libvips cache to ensure tests are as fair as they can be
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
|
|
||||||
|
// Spawn one thread per CPU
|
||||||
|
sharp.concurrency(os.cpus().length);
|
||||||
|
|
||||||
async.series({
|
async.series({
|
||||||
jpeg: function (callback) {
|
jpeg: function (callback) {
|
||||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
@@ -56,7 +66,7 @@ async.series({
|
|||||||
image
|
image
|
||||||
.resize(width, height, jimp.RESIZE_BICUBIC)
|
.resize(width, height, jimp.RESIZE_BICUBIC)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -67,6 +77,65 @@ async.series({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 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();
|
||||||
|
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
|
||||||
jpegSuite.add('mapnik-file-file', {
|
jpegSuite.add('mapnik-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
@@ -77,7 +146,7 @@ async.series({
|
|||||||
.resize(width, height, {
|
.resize(width, height, {
|
||||||
scaling_method: mapnik.imageScaling.lanczos
|
scaling_method: mapnik.imageScaling.lanczos
|
||||||
})
|
})
|
||||||
.save(fixtures.outputJpg, 'jpeg:quality=80', function (err) {
|
.save(outputJpg, 'jpeg:quality=80', function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
@@ -105,7 +174,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputJpg,
|
srcPath: fixtures.inputJpg,
|
||||||
dstPath: fixtures.outputJpg,
|
dstPath: outputJpg,
|
||||||
quality: 0.8,
|
quality: 0.8,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
@@ -128,7 +197,7 @@ async.series({
|
|||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -159,7 +228,7 @@ async.series({
|
|||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -190,7 +259,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputJpg, function (err) {
|
.toFile(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -217,7 +286,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputJpg, function (err) {
|
.toFile(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -229,7 +298,7 @@ async.series({
|
|||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('finish', function () {
|
writable.on('finish', function () {
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
@@ -564,8 +633,9 @@ async.series({
|
|||||||
},
|
},
|
||||||
// PNG
|
// PNG
|
||||||
png: function (callback) {
|
png: function (callback) {
|
||||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
const inputPngBuffer = fs.readFileSync(fixtures.inputPngAlphaPremultiplicationLarge);
|
||||||
const pngSuite = new Benchmark.Suite('png');
|
const pngSuite = new Benchmark.Suite('png');
|
||||||
|
const minSamples = 64;
|
||||||
// jimp
|
// jimp
|
||||||
pngSuite.add('jimp-buffer-buffer', {
|
pngSuite.add('jimp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
@@ -576,6 +646,8 @@ async.series({
|
|||||||
} else {
|
} else {
|
||||||
image
|
image
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
|
.deflateLevel(6)
|
||||||
|
.filterType(0)
|
||||||
.getBuffer(jimp.MIME_PNG, function (err) {
|
.getBuffer(jimp.MIME_PNG, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -589,13 +661,15 @@ async.series({
|
|||||||
}).add('jimp-file-file', {
|
}).add('jimp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
jimp.read(fixtures.inputPng, function (err, image) {
|
jimp.read(fixtures.inputPngAlphaPremultiplicationLarge, function (err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
image
|
image
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.write(fixtures.outputPng, function (err) {
|
.deflateLevel(6)
|
||||||
|
.filterType(0)
|
||||||
|
.write(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -610,7 +684,7 @@ async.series({
|
|||||||
pngSuite.add('mapnik-file-file', {
|
pngSuite.add('mapnik-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
mapnik.Image.open(fixtures.inputPng, function (err, img) {
|
mapnik.Image.open(fixtures.inputPngAlphaPremultiplicationLarge, function (err, img) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
img.premultiply(function (err, img) {
|
img.premultiply(function (err, img) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -620,7 +694,7 @@ async.series({
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
img.demultiply(function (err, img) {
|
img.demultiply(function (err, img) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
img.save(fixtures.outputPng, 'png', function (err) {
|
img.save(outputPng, 'png', function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
@@ -657,11 +731,15 @@ async.series({
|
|||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputPng,
|
srcPath: fixtures.inputPngAlphaPremultiplicationLarge,
|
||||||
dstPath: fixtures.outputPng,
|
dstPath: outputPng,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
filter: 'Lanczos'
|
filter: 'Lanczos',
|
||||||
|
customArgs: [
|
||||||
|
'-define', 'PNG:compression-level=6',
|
||||||
|
'-define', 'PNG:compression-filter=0'
|
||||||
|
]
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -675,10 +753,12 @@ async.series({
|
|||||||
pngSuite.add('gm-file-file', {
|
pngSuite.add('gm-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputPng)
|
gm(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.write(fixtures.outputPng, function (err) {
|
.define('PNG:compression-level=6')
|
||||||
|
.define('PNG:compression-filter=0')
|
||||||
|
.write(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -689,9 +769,11 @@ async.series({
|
|||||||
}).add('gm-file-buffer', {
|
}).add('gm-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
gm(fixtures.inputPng)
|
gm(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
|
.define('PNG:compression-level=6')
|
||||||
|
.define('PNG:compression-filter=0')
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -705,10 +787,12 @@ async.series({
|
|||||||
// sharp
|
// sharp
|
||||||
pngSuite.add('sharp-buffer-file', {
|
pngSuite.add('sharp-buffer-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
minSamples,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputPng, function (err) {
|
.png({ compressionLevel: 6 })
|
||||||
|
.toFile(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -718,9 +802,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-buffer-buffer', {
|
}).add('sharp-buffer-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
minSamples,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -732,10 +818,12 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-file', {
|
}).add('sharp-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
minSamples,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputPng, function (err) {
|
.png({ compressionLevel: 6 })
|
||||||
|
.toFile(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -745,9 +833,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-file-buffer', {
|
}).add('sharp-file-buffer', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
minSamples,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -759,10 +849,11 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-progressive', {
|
}).add('sharp-progressive', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
minSamples,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.png({ progressive: true })
|
.png({ compressionLevel: 6, progressive: true })
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -774,10 +865,27 @@ async.series({
|
|||||||
}
|
}
|
||||||
}).add('sharp-adaptiveFiltering', {
|
}).add('sharp-adaptiveFiltering', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
minSamples,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.png({ adaptiveFiltering: true })
|
.png({ adaptiveFiltering: true, compressionLevel: 6 })
|
||||||
|
.toBuffer(function (err, buffer) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
} else {
|
||||||
|
assert.notStrictEqual(null, buffer);
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).add('sharp-compressionLevel=9', {
|
||||||
|
defer: true,
|
||||||
|
minSamples,
|
||||||
|
fn: function (deferred) {
|
||||||
|
sharp(inputPngBuffer)
|
||||||
|
.resize(width, height)
|
||||||
|
.png({ compressionLevel: 9 })
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -802,7 +910,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputWebPBuffer)
|
sharp(inputWebPBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputWebP, function (err) {
|
.toFile(outputWebP, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@@ -829,7 +937,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputWebP, function (err) {
|
.toFile(outputWebP, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ new Benchmark.Suite('random').add('imagemagick', {
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputJpg,
|
srcPath: fixtures.inputJpg,
|
||||||
dstPath: fixtures.outputJpg,
|
dstPath: fixtures.path('output.jpg'),
|
||||||
quality: 0.8,
|
quality: 0.8,
|
||||||
width: randomDimension(),
|
width: randomDimension(),
|
||||||
height: randomDimension(),
|
height: randomDimension(),
|
||||||
|
|||||||
BIN
test/fixtures/big-height.webp
vendored
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
3
test/fixtures/circle.svg
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8">
|
||||||
|
<circle r="3.75" cx="4" cy="4" fill="deeppink" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 122 B |
BIN
test/fixtures/concert.jpg
vendored
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
test/fixtures/expected/affine-background-all-offsets-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
test/fixtures/expected/affine-background-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
test/fixtures/expected/affine-background-output-offsets-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/affine-bicubic-2x-upscale-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
test/fixtures/expected/affine-bilinear-2x-upscale-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
test/fixtures/expected/affine-extract-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
test/fixtures/expected/affine-extract-rotate-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
test/fixtures/expected/affine-lbb-2x-upscale-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
test/fixtures/expected/affine-nearest-2x-upscale-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 64 KiB |
BIN
test/fixtures/expected/affine-nohalo-2x-upscale-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
test/fixtures/expected/affine-resize-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
test/fixtures/expected/affine-rotate-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
test/fixtures/expected/affine-vsqbs-2x-upscale-expected.jpg
vendored
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
test/fixtures/expected/circle.png
vendored
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
test/fixtures/expected/clahe-100-100-0.jpg
vendored
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
test/fixtures/expected/clahe-100-50-3.jpg
vendored
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/clahe-11-25-14.jpg
vendored
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
test/fixtures/expected/clahe-5-5-0.jpg
vendored
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
test/fixtures/expected/clahe-5-5-5.jpg
vendored
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
test/fixtures/expected/clahe-50-50-0.jpg
vendored
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
test/fixtures/expected/clahe-50-50-14.jpg
vendored
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
test/fixtures/expected/colourspace-gradients-gamma-resize.png
vendored
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
test/fixtures/expected/extract-alpha-16bit.jpg
vendored
|
Before Width: | Height: | Size: 685 B |
BIN
test/fixtures/expected/extract-alpha-16bit.png
vendored
Normal file
|
After Width: | Height: | Size: 262 B |
BIN
test/fixtures/expected/hilutite.jpg
vendored
Normal file
|
After Width: | Height: | Size: 424 KiB |