Compare commits
81 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
e896d5e920 | ||
|
|
42d4228595 | ||
|
|
341ea3e4ea | ||
|
|
cb1baede87 | ||
|
|
45653ca2e7 | ||
|
|
77c861b74b | ||
|
|
b586c2146f | ||
|
|
4d42bed4f8 | ||
|
|
ea54c119ab | ||
|
|
d95b124771 | ||
|
|
61ccf09e6f | ||
|
|
8da30f0b41 | ||
|
|
90a57e7664 | ||
|
|
c42de19d2a | ||
|
|
dcc42f8514 | ||
|
|
3150fad909 | ||
|
|
ba17db3ab3 | ||
|
|
7c1c48327e | ||
|
|
85459e0ec6 | ||
|
|
13bdb68366 | ||
|
|
c91373fba3 | ||
|
|
e8149f5295 | ||
|
|
ab015ef90f | ||
|
|
fdfc89e577 | ||
|
|
e647e1f7bd | ||
|
|
a05d735e31 | ||
|
|
4470048ba4 | ||
|
|
0f58f956a7 | ||
|
|
20284757a6 | ||
|
|
df6efa0285 | ||
|
|
3c10e118e3 | ||
|
|
19980190f7 | ||
|
|
8f5495a446 | ||
|
|
9431029917 | ||
|
|
17ea70a102 | ||
|
|
7f142bddb3 | ||
|
|
98e0516ac1 | ||
|
|
7717516d1d | ||
|
|
760550ca0d | ||
|
|
f8144dd89c | ||
|
|
ac4070cb49 | ||
|
|
25b964e3df | ||
|
|
17ec6c72df | ||
|
|
a7b1185602 | ||
|
|
c76ae06fd1 | ||
|
|
b3dd54d550 | ||
|
|
d248eadb06 | ||
|
|
507eef3053 | ||
|
|
fc2f672337 | ||
|
|
6f49be8f26 |
@@ -2,6 +2,7 @@ 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
|
||||||
prerequisites_script:
|
prerequisites_script:
|
||||||
|
|||||||
4
.github/CONTRIBUTING.md
vendored
@@ -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
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/installation.md
vendored
@@ -7,7 +7,7 @@ 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`?
|
||||||
|
|
||||||
|
|||||||
71
.travis.yml
@@ -5,7 +5,7 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
- sudo docker run -dit --name sharp --env CI --env TRAVIS_TAG --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 bash -c "curl -sL https://rpm.nodesource.com/setup_10.x | bash -"
|
||||||
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
||||||
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
||||||
@@ -16,29 +16,18 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
- 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 bash -c "curl -sL https://rpm.nodesource.com/setup_12.x | bash -"
|
||||||
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
||||||
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp bash -c "npm test"
|
script: sudo docker exec sharp bash -c "npm test"
|
||||||
|
|
||||||
- name: "Linux x64 (CentOS 7, glibc 2.17) - Node.js 13"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
|
||||||
- sudo docker exec sharp bash -c "curl -sL https://rpm.nodesource.com/setup_13.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"
|
- name: "Linux x64 (CentOS 7, glibc 2.17) - Node.js 14"
|
||||||
os: linux
|
os: linux
|
||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp centos:7
|
- 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 bash -c "curl -sL https://rpm.nodesource.com/setup_14.x | bash -"
|
||||||
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
- sudo docker exec sharp yum install -y gcc-c++ make git nodejs
|
||||||
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp bash -c "npm install --unsafe-perm"
|
||||||
@@ -49,7 +38,7 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:10.17.0-alpine3.9 # https://github.com/nodejs/docker-node/issues/1158
|
- sudo docker run -dit --name sharp --env CI --env TRAVIS_TAG --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
|
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -59,17 +48,7 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:12.0-alpine
|
- 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 13"
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:13.0-alpine
|
|
||||||
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -79,7 +58,7 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:14.0-alpine
|
- 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
|
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -90,11 +69,11 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
- sudo docker run -dit --name sharp --env CI --env TRAVIS_TAG --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 "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 "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 "echo 'deb https://deb.nodesource.com/node_10.x sid main' >/etc/apt/sources.list.d/nodesource.list"
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
- 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"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
|
|
||||||
@@ -104,24 +83,10 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
- 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 "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 "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 "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"
|
|
||||||
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 13"
|
|
||||||
arch: arm64
|
|
||||||
os: linux
|
|
||||||
dist: bionic
|
|
||||||
language: shell
|
|
||||||
before_install:
|
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --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_13.x buster main' >/etc/apt/sources.list.d/nodesource.list"
|
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
- 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"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -132,10 +97,10 @@ jobs:
|
|||||||
dist: bionic
|
dist: bionic
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
- 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 "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 "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 "echo 'deb https://deb.nodesource.com/node_14.x sid main' >/etc/apt/sources.list.d/nodesource.list"
|
||||||
- sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
- 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"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
@@ -151,25 +116,21 @@ jobs:
|
|||||||
osx_image: xcode10.1
|
osx_image: xcode10.1
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: "12"
|
node_js: "12"
|
||||||
|
before_install: unset prebuild_upload
|
||||||
- name: "macOS (10.13) - Node.js 13"
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode10.1
|
|
||||||
language: node_js
|
|
||||||
node_js: "13"
|
|
||||||
|
|
||||||
- name: "macOS (10.13) - Node.js 14"
|
- name: "macOS (10.13) - Node.js 14"
|
||||||
os: osx
|
os: osx
|
||||||
osx_image: xcode10.1
|
osx_image: xcode10.1
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: "14"
|
node_js: "14"
|
||||||
|
before_install: unset prebuild_upload
|
||||||
|
|
||||||
- name: "Unit test coverage report"
|
- name: "Unit test coverage report"
|
||||||
os: linux
|
os: linux
|
||||||
dist: bionic
|
dist: bionic
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: "13"
|
node_js: "13"
|
||||||
before_install: unset PREBUILD_TOKEN
|
before_install: unset prebuild_upload
|
||||||
after_success:
|
after_success:
|
||||||
- npm install coveralls
|
- npm install coveralls
|
||||||
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
|
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|||||||
As well as image resizing, operations such as
|
As well as image resizing, operations such as
|
||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern macOS, Windows and Linux systems running Node.js v10+
|
Most modern macOS, Windows and Linux systems running Node.js v10.16.0+
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|||||||
10
appveyor.yml
@@ -9,16 +9,16 @@ environment:
|
|||||||
platform: x64
|
platform: x64
|
||||||
- nodejs_version: "12"
|
- nodejs_version: "12"
|
||||||
platform: x86
|
platform: x86
|
||||||
|
prebuild_upload: ""
|
||||||
- nodejs_version: "12"
|
- nodejs_version: "12"
|
||||||
platform: x64
|
platform: x64
|
||||||
- nodejs_version: "13"
|
prebuild_upload: ""
|
||||||
platform: x86
|
- nodejs_version: "14.2.0"
|
||||||
- nodejs_version: "13"
|
|
||||||
platform: x64
|
|
||||||
- nodejs_version: "14"
|
|
||||||
platform: x86
|
platform: x86
|
||||||
|
prebuild_upload: ""
|
||||||
- nodejs_version: "14"
|
- nodejs_version: "14"
|
||||||
platform: x64
|
platform: x64
|
||||||
|
prebuild_upload: ""
|
||||||
install:
|
install:
|
||||||
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform
|
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform
|
||||||
- npm install
|
- npm install
|
||||||
|
|||||||
153
binding.gyp
@@ -1,4 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
'variables': {
|
||||||
|
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
|
||||||
|
'sharp_vendor_dir': '<(module_root_dir)/vendor/<(vips_version)'
|
||||||
|
},
|
||||||
'targets': [{
|
'targets': [{
|
||||||
'target_name': 'libvips-cpp',
|
'target_name': 'libvips-cpp',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
@@ -16,23 +20,38 @@
|
|||||||
'src/libvips/cplusplus/VImage.cpp'
|
'src/libvips/cplusplus/VImage.cpp'
|
||||||
],
|
],
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'vendor/include',
|
'<(sharp_vendor_dir)/include',
|
||||||
'vendor/include/glib-2.0',
|
'<(sharp_vendor_dir)/include/glib-2.0',
|
||||||
'vendor/lib/glib-2.0/include'
|
'<(sharp_vendor_dir)/lib/glib-2.0/include'
|
||||||
],
|
|
||||||
'libraries': [
|
|
||||||
'../vendor/lib/libvips.lib',
|
|
||||||
'../vendor/lib/libglib-2.0.lib',
|
|
||||||
'../vendor/lib/libgobject-2.0.lib'
|
|
||||||
],
|
],
|
||||||
|
'link_settings': {
|
||||||
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
|
'libraries': [
|
||||||
|
'libvips.lib',
|
||||||
|
'libglib-2.0.lib',
|
||||||
|
'libgobject-2.0.lib'
|
||||||
|
],
|
||||||
|
},
|
||||||
'configurations': {
|
'configurations': {
|
||||||
'Release': {
|
'Release': {
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
'ExceptionHandling': 1
|
'ExceptionHandling': 1,
|
||||||
|
'WholeProgramOptimization': 'true'
|
||||||
|
},
|
||||||
|
'VCLibrarianTool': {
|
||||||
|
'AdditionalOptions': [
|
||||||
|
'/LTCG:INCREMENTAL'
|
||||||
|
]
|
||||||
},
|
},
|
||||||
'VCLinkerTool': {
|
'VCLinkerTool': {
|
||||||
'ImageHasSafeExceptionHandlers': 'false'
|
'ImageHasSafeExceptionHandlers': 'false',
|
||||||
|
'OptimizeReferences': 2,
|
||||||
|
'EnableCOMDATFolding': 2,
|
||||||
|
'LinkIncremental': 1,
|
||||||
|
'AdditionalOptions': [
|
||||||
|
'/LTCG:INCREMENTAL'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'msvs_disabled_warnings': [
|
'msvs_disabled_warnings': [
|
||||||
@@ -58,8 +77,8 @@
|
|||||||
'runtime_link%': 'shared',
|
'runtime_link%': 'shared',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS != "win"', {
|
['OS != "win"', {
|
||||||
'pkg_config_path': '<!(node -e "console.log(require(\'./lib/libvips\').pkgConfigPath())")',
|
'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
|
||||||
'use_global_libvips': '<!(node -e "console.log(Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString())")'
|
'use_global_libvips': '<!(node -p "Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString()")'
|
||||||
}, {
|
}, {
|
||||||
'pkg_config_path': '',
|
'pkg_config_path': '',
|
||||||
'use_global_libvips': ''
|
'use_global_libvips': ''
|
||||||
@@ -76,7 +95,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"', {
|
||||||
@@ -98,9 +117,9 @@
|
|||||||
}, {
|
}, {
|
||||||
# Use pre-built libvips stored locally within node_modules
|
# Use pre-built libvips stored locally within node_modules
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'vendor/include',
|
'<(sharp_vendor_dir)/include',
|
||||||
'vendor/include/glib-2.0',
|
'<(sharp_vendor_dir)/include/glib-2.0',
|
||||||
'vendor/lib/glib-2.0/include'
|
'<(sharp_vendor_dir)/lib/glib-2.0/include'
|
||||||
],
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
@@ -108,64 +127,45 @@
|
|||||||
'_ALLOW_KEYWORD_MACROS',
|
'_ALLOW_KEYWORD_MACROS',
|
||||||
'_FILE_OFFSET_BITS=64'
|
'_FILE_OFFSET_BITS=64'
|
||||||
],
|
],
|
||||||
'libraries': [
|
'link_settings': {
|
||||||
'../vendor/lib/libvips.lib',
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'../vendor/lib/libglib-2.0.lib',
|
'libraries': [
|
||||||
'../vendor/lib/libgobject-2.0.lib'
|
'libvips.lib',
|
||||||
]
|
'libglib-2.0.lib',
|
||||||
|
'libgobject-2.0.lib'
|
||||||
|
]
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
['OS == "mac"', {
|
['OS == "mac"', {
|
||||||
'libraries': [
|
'link_settings': {
|
||||||
'../vendor/lib/libvips-cpp.42.dylib',
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'../vendor/lib/libvips.42.dylib',
|
'libraries': [
|
||||||
'../vendor/lib/libglib-2.0.0.dylib',
|
'libvips-cpp.42.dylib',
|
||||||
'../vendor/lib/libgobject-2.0.0.dylib',
|
'libvips.42.dylib'
|
||||||
# Ensure runtime linking is relative to sharp.node
|
]
|
||||||
'-rpath \'@loader_path/../../vendor/lib\''
|
},
|
||||||
]
|
'xcode_settings': {
|
||||||
|
'OTHER_LDFLAGS': [
|
||||||
|
# Ensure runtime linking is relative to sharp.node
|
||||||
|
'-Wl,-rpath,\'@loader_path/../../vendor/<(vips_version)/lib\''
|
||||||
|
]
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
['OS == "linux"', {
|
['OS == "linux"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
'_GLIBCXX_USE_CXX11_ABI=0'
|
'_GLIBCXX_USE_CXX11_ABI=0'
|
||||||
],
|
],
|
||||||
'libraries': [
|
'link_settings': {
|
||||||
'../vendor/lib/libvips-cpp.so',
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'../vendor/lib/libvips.so',
|
'libraries': [
|
||||||
'../vendor/lib/libglib-2.0.so',
|
'-l:libvips-cpp.so.42',
|
||||||
'../vendor/lib/libgobject-2.0.so',
|
'-l:libvips.so.42'
|
||||||
# Dependencies of dependencies, included for openSUSE support
|
],
|
||||||
'../vendor/lib/libcairo.so',
|
'ldflags': [
|
||||||
'../vendor/lib/libexif.so',
|
# Ensure runtime linking is relative to sharp.node
|
||||||
'../vendor/lib/libexpat.so',
|
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../vendor/<(vips_version)/lib\''
|
||||||
'../vendor/lib/libffi.so',
|
]
|
||||||
'../vendor/lib/libfontconfig.so',
|
}
|
||||||
'../vendor/lib/libfreetype.so',
|
|
||||||
'../vendor/lib/libfribidi.so',
|
|
||||||
'../vendor/lib/libgdk_pixbuf-2.0.so',
|
|
||||||
'../vendor/lib/libgif.so',
|
|
||||||
'../vendor/lib/libgio-2.0.so',
|
|
||||||
'../vendor/lib/libgmodule-2.0.so',
|
|
||||||
'../vendor/lib/libgsf-1.so',
|
|
||||||
'../vendor/lib/libgthread-2.0.so',
|
|
||||||
'../vendor/lib/libharfbuzz.so',
|
|
||||||
'../vendor/lib/libjpeg.so',
|
|
||||||
'../vendor/lib/liblcms2.so',
|
|
||||||
'../vendor/lib/liborc-0.4.so',
|
|
||||||
'../vendor/lib/libpango-1.0.so',
|
|
||||||
'../vendor/lib/libpangocairo-1.0.so',
|
|
||||||
'../vendor/lib/libpangoft2-1.0.so',
|
|
||||||
'../vendor/lib/libpixman-1.so',
|
|
||||||
'../vendor/lib/libpng.so',
|
|
||||||
'../vendor/lib/librsvg-2.so',
|
|
||||||
'../vendor/lib/libtiff.so',
|
|
||||||
'../vendor/lib/libwebp.so',
|
|
||||||
'../vendor/lib/libwebpdemux.so',
|
|
||||||
'../vendor/lib/libwebpmux.so',
|
|
||||||
'../vendor/lib/libxml2.so',
|
|
||||||
'../vendor/lib/libz.so',
|
|
||||||
# Ensure runtime linking is relative to sharp.node
|
|
||||||
'-Wl,--disable-new-dtags -Wl,-rpath=\'$${ORIGIN}/../../vendor/lib\''
|
|
||||||
]
|
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
@@ -178,8 +178,7 @@
|
|||||||
],
|
],
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
||||||
'CLANG_CXX_LIBRARY': 'libc++',
|
'MACOSX_DEPLOYMENT_TARGET': '10.9',
|
||||||
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
|
||||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
||||||
'GCC_ENABLE_CPP_RTTI': 'YES',
|
'GCC_ENABLE_CPP_RTTI': 'YES',
|
||||||
'OTHER_CPLUSPLUSFLAGS': [
|
'OTHER_CPLUSPLUSFLAGS': [
|
||||||
@@ -204,10 +203,22 @@
|
|||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
'ExceptionHandling': 1
|
'ExceptionHandling': 1,
|
||||||
|
'WholeProgramOptimization': 'true'
|
||||||
|
},
|
||||||
|
'VCLibrarianTool': {
|
||||||
|
'AdditionalOptions': [
|
||||||
|
'/LTCG:INCREMENTAL'
|
||||||
|
]
|
||||||
},
|
},
|
||||||
'VCLinkerTool': {
|
'VCLinkerTool': {
|
||||||
'ImageHasSafeExceptionHandlers': 'false'
|
'ImageHasSafeExceptionHandlers': 'false',
|
||||||
|
'OptimizeReferences': 2,
|
||||||
|
'EnableCOMDATFolding': 2,
|
||||||
|
'LinkIncremental': 1,
|
||||||
|
'AdditionalOptions': [
|
||||||
|
'/LTCG:INCREMENTAL'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'msvs_disabled_warnings': [
|
'msvs_disabled_warnings': [
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|||||||
As well as image resizing, operations such as
|
As well as image resizing, operations such as
|
||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern macOS, Windows and Linux systems running Node.js v10+
|
Most modern macOS, Windows and Linux systems running Node.js v10.16.0+
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
### Formats
|
### Formats
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Extract a single channel from a multi-channel image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `channel` **([number][1] \| [string][2])** zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
|
- `channel` **([number][1] \| [string][2])** zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
|
|||||||
@@ -2,32 +2,43 @@
|
|||||||
|
|
||||||
## Sharp
|
## Sharp
|
||||||
|
|
||||||
|
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.
|
||||||
|
When using Stream based output, derived attributes are available from the `info` event.
|
||||||
|
|
||||||
|
Non-critical problems encountered during processing are emitted as `warning` events.
|
||||||
|
|
||||||
|
Implements the [stream.Duplex][1] class.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `input` **([Buffer][1] \| [String][2])?** if present, can be
|
- `input` **([Buffer][2] \| [string][3])?** if present, can be
|
||||||
a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
||||||
a String containing the filesystem path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
a String containing the filesystem path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
||||||
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||||
- `options` **[Object][3]?** if present, is an Object with optional attributes.
|
- `options` **[Object][4]?** if present, is an Object with optional attributes.
|
||||||
- `options.failOnError` **[Boolean][4]** by default halt processing and raise an error when loading invalid images.
|
- `options.failOnError` **[boolean][5]** 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. (optional, default `true`)
|
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][5] \| [Boolean][4])** Do not process input images where the number of pixels
|
- `options.limitInputPixels` **([number][6] \| [boolean][5])** Do not process input images where the number of pixels
|
||||||
(width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
(width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
||||||
An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default `268402689`)
|
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.sequentialRead` **[Boolean][4]** Set this to `true` to use sequential rather than random access where possible.
|
- `options.sequentialRead` **[boolean][5]** 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. (optional, default `false`)
|
This can reduce memory usage and might improve performance on some systems. (optional, default `false`)
|
||||||
- `options.density` **[Number][5]** number representing the DPI for vector images. (optional, default `72`)
|
- `options.density` **[number][6]** number representing the DPI for vector images in the range 1 to 100000. (optional, default `72`)
|
||||||
- `options.pages` **[Number][5]** number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages. (optional, default `1`)
|
- `options.pages` **[number][6]** number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages. (optional, default `1`)
|
||||||
- `options.page` **[Number][5]** page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default `0`)
|
- `options.page` **[number][6]** page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default `0`)
|
||||||
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
- `options.level` **[number][6]** level to extract from a multi-level input (OpenSlide), zero based. (optional, default `0`)
|
||||||
- `options.raw.width` **[Number][5]?**
|
- `options.animated` **[boolean][5]** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default `false`)
|
||||||
- `options.raw.height` **[Number][5]?**
|
- `options.raw` **[Object][4]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
- `options.raw.channels` **[Number][5]?** 1-4
|
- `options.raw.width` **[number][6]?**
|
||||||
- `options.create` **[Object][3]?** describes a new image to be created.
|
- `options.raw.height` **[number][6]?**
|
||||||
- `options.create.width` **[Number][5]?**
|
- `options.raw.channels` **[number][6]?** 1-4
|
||||||
- `options.create.height` **[Number][5]?**
|
- `options.create` **[Object][4]?** describes a new image to be created.
|
||||||
- `options.create.channels` **[Number][5]?** 3-4
|
- `options.create.width` **[number][6]?**
|
||||||
- `options.create.background` **([String][2] \| [Object][3])?** parsed by the [color][6] module to extract values for red, green, blue and alpha.
|
- `options.create.height` **[number][6]?**
|
||||||
|
- `options.create.channels` **[number][6]?** 3-4
|
||||||
|
- `options.create.background` **([string][3] \| [Object][4])?** parsed by the [color][7] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -68,9 +79,14 @@ sharp({
|
|||||||
.then( ... );
|
.then( ... );
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][7]** Invalid parameters
|
```javascript
|
||||||
|
// Convert an animated GIF to an animated WebP
|
||||||
|
await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||||
|
```
|
||||||
|
|
||||||
Returns **[Sharp][8]**
|
- Throws **[Error][8]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **[Sharp][9]**
|
||||||
|
|
||||||
## clone
|
## clone
|
||||||
|
|
||||||
@@ -138,20 +154,22 @@ Promise.all(promises)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Sharp][8]**
|
Returns **[Sharp][9]**
|
||||||
|
|
||||||
[1]: https://nodejs.org/api/buffer.html
|
[1]: http://nodejs.org/api/stream.html#stream_class_stream_duplex
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[2]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[6]: https://www.npmjs.org/package/color
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[7]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
[8]: #sharp
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[9]: #sharp
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
- `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
|
||||||
- `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
|
||||||
@@ -70,6 +71,8 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
- `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)
|
||||||
|
- `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
@@ -86,6 +89,11 @@ image
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const { entropy, sharpness, dominant } = await sharp(input).stats();
|
||||||
|
const { r, g, b } = dominant;
|
||||||
|
```
|
||||||
|
|
||||||
Returns **[Promise][5]<[Object][6]>**
|
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
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ 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.
|
||||||
@@ -100,6 +101,7 @@ sRGB colour space and strip all metadata, including the removal of any ICC profi
|
|||||||
|
|
||||||
- `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.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -140,20 +142,22 @@ 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.quality` **[number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.progressive` **[boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.chromaSubsampling` **[string][2]** for quality < 90, set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' (use chroma subsampling); for quality >= 90 chroma is never subsampled (optional, default `'4:2:0'`)
|
- `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.optimiseCoding` **[boolean][7]** optimise Huffman coding tables (optional, default `true`)
|
||||||
|
- `options.optimizeCoding` **[boolean][7]** alternative spelling of optimiseCoding (optional, default `true`)
|
||||||
- `options.trellisQuantisation` **[boolean][7]** apply trellis quantisation, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
- `options.trellisQuantisation` **[boolean][7]** apply trellis quantisation, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.overshootDeringing` **[boolean][7]** apply overshoot deringing, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
- `options.overshootDeringing` **[boolean][7]** apply overshoot deringing, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.optimiseScans` **[boolean][7]** optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
- `options.optimiseScans` **[boolean][7]** optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.optimizeScans` **[boolean][7]** alternative spelling of optimiseScans (optional, default `false`)
|
- `options.optimizeScans` **[boolean][7]** alternative spelling of optimiseScans, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.optimiseCoding` **[boolean][7]** optimise Huffman coding tables (optional, default `true`)
|
|
||||||
- `options.optimizeCoding` **[boolean][7]** alternative spelling of optimiseCoding (optional, default `true`)
|
|
||||||
- `options.quantisationTable` **[number][9]** quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg (optional, default `0`)
|
- `options.quantisationTable` **[number][9]** quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg (optional, default `0`)
|
||||||
- `options.quantizationTable` **[number][9]** alternative spelling of quantisationTable (optional, default `0`)
|
- `options.quantizationTable` **[number][9]** alternative spelling of quantisationTable, requires libvips compiled with support for mozjpeg (optional, default `0`)
|
||||||
- `options.force` **[boolean][7]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[boolean][7]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
@@ -179,6 +183,8 @@ Use these PNG options for output image.
|
|||||||
PNG output is always full colour at 8 or 16 bits per pixel.
|
PNG output is always 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.
|
||||||
|
|
||||||
|
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]?**
|
||||||
@@ -186,10 +192,10 @@ Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
|||||||
- `options.compressionLevel` **[number][9]** zlib compression level, 0-9 (optional, default `9`)
|
- `options.compressionLevel` **[number][9]** zlib compression level, 0-9 (optional, default `9`)
|
||||||
- `options.adaptiveFiltering` **[boolean][7]** use adaptive row filtering (optional, default `false`)
|
- `options.adaptiveFiltering` **[boolean][7]** use adaptive row filtering (optional, default `false`)
|
||||||
- `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.palette` **[boolean][7]** quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant (optional, default `false`)
|
||||||
- `options.quality` **[number][9]** use the lowest number of colours needed to achieve given quality, requires libvips compiled with support for libimagequant (optional, default `100`)
|
- `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.colours` **[number][9]** maximum number of palette entries, requires libvips compiled with support for libimagequant (optional, default `256`)
|
- `options.colours` **[number][9]** maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant (optional, default `256`)
|
||||||
- `options.colors` **[number][9]** alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant (optional, default `256`)
|
- `options.colors` **[number][9]** alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant (optional, default `256`)
|
||||||
- `options.dither` **[number][9]** level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant (optional, default `1.0`)
|
- `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.force` **[boolean][7]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[boolean][7]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
@@ -218,6 +224,9 @@ Use these WebP options for output image.
|
|||||||
- `options.nearLossless` **[boolean][7]** use near_lossless compression mode (optional, default `false`)
|
- `options.nearLossless` **[boolean][7]** use near_lossless compression mode (optional, default `false`)
|
||||||
- `options.smartSubsample` **[boolean][7]** use high quality chroma subsampling (optional, default `false`)
|
- `options.smartSubsample` **[boolean][7]** use high quality chroma subsampling (optional, default `false`)
|
||||||
- `options.reductionEffort` **[number][9]** level of CPU effort to reduce file size, integer 0-6 (optional, default `4`)
|
- `options.reductionEffort` **[number][9]** level of CPU effort to reduce file size, integer 0-6 (optional, default `4`)
|
||||||
|
- `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 WebP output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[boolean][7]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
@@ -229,6 +238,27 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## gif
|
||||||
|
|
||||||
|
Use these GIF options for output image.
|
||||||
|
|
||||||
|
Requires libvips compiled with support for ImageMagick or GraphicsMagick.
|
||||||
|
The prebuilt binaries do not include this - see
|
||||||
|
[installing a custom libvips][11].
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `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`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][4]** Invalid options
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
@@ -250,7 +280,7 @@ Use these TIFF options for output image.
|
|||||||
- `options.tileHeight` **[boolean][7]** vertical tile size (optional, default `256`)
|
- `options.tileHeight` **[boolean][7]** vertical tile size (optional, default `256`)
|
||||||
- `options.xres` **[number][9]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
- `options.xres` **[number][9]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
||||||
- `options.yres` **[number][9]** vertical resolution in pixels/mm (optional, default `1.0`)
|
- `options.yres` **[number][9]** vertical resolution in pixels/mm (optional, default `1.0`)
|
||||||
- `options.squash` **[boolean][7]** squash 8-bit images down to 1 bit (optional, default `false`)
|
- `options.bitdepth` **[boolean][7]** reduce bitdepth to 1, 2 or 4 bit (optional, default `8`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -259,7 +289,7 @@ Use these TIFF options for output image.
|
|||||||
sharp('input.svg')
|
sharp('input.svg')
|
||||||
.tiff({
|
.tiff({
|
||||||
compression: 'lzw',
|
compression: 'lzw',
|
||||||
squash: true
|
bitdepth: 1
|
||||||
})
|
})
|
||||||
.toFile('1-bpp-output.tiff')
|
.toFile('1-bpp-output.tiff')
|
||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
@@ -337,7 +367,7 @@ Warning: multiple sharp instances concurrently producing tile output can expose
|
|||||||
- `options.size` **[number][9]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
- `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.overlap` **[number][9]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
- `options.angle` **[number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
- `options.angle` **[number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
||||||
- `options.background` **([string][2] \| [Object][6])** background colour, parsed by the [color][10] module, defaults to white without transparency. (optional, default `{r:255,g:255,b:255,alpha:1}`)
|
- `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.depth` **[string][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
- `options.depth` **[string][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
- `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.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.container` **[string][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
- `options.container` **[string][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
@@ -379,4 +409,8 @@ Returns **Sharp**
|
|||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[10]: https://www.npmjs.org/package/color
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
|
[11]: https://sharp.pixelplumbing.com/install#custom-libvips
|
||||||
|
|
||||||
|
[12]: https://www.npmjs.org/package/color
|
||||||
|
|||||||
@@ -1,9 +1,87 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v0.26 - *zoom*
|
||||||
|
|
||||||
|
Requires libvips v8.10.0
|
||||||
|
|
||||||
|
### 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+.
|
||||||
|
|
||||||
|
* TIFF output `squash` is replaced by `bitdepth` to reduce to 1, 2 or 4 bit.
|
||||||
|
|
||||||
|
* JPEG output `quality` >= 90 no longer automatically sets `chromaSubsampling` to `4:4:4`.
|
||||||
|
|
||||||
|
* Add most `dominant` colour to image `stats`.
|
||||||
|
[#640](https://github.com/lovell/sharp/issues/640)
|
||||||
|
|
||||||
|
* Add support for animated GIF (requires \*magick) and WebP output.
|
||||||
|
[#2012](https://github.com/lovell/sharp/pull/2012)
|
||||||
|
[@deftomat](https://github.com/deftomat)
|
||||||
|
|
||||||
|
* Add support for libvips ImageMagick v7 loaders.
|
||||||
|
[#2258](https://github.com/lovell/sharp/pull/2258)
|
||||||
|
[@vouillon](https://github.com/vouillon)
|
||||||
|
|
||||||
|
* Allow multi-page input via \*magick.
|
||||||
|
[#2259](https://github.com/lovell/sharp/pull/2259)
|
||||||
|
[@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.
|
||||||
|
[#2292](https://github.com/lovell/sharp/pull/2292)
|
||||||
|
[@diegodev3](https://github.com/diegodev3)
|
||||||
|
|
||||||
## v0.25 - *yield*
|
## v0.25 - *yield*
|
||||||
|
|
||||||
Requires libvips v8.9.1
|
Requires libvips v8.9.1
|
||||||
|
|
||||||
|
### v0.25.4 - 12th June 2020
|
||||||
|
|
||||||
|
* Allow libvips binary location override where version is appended.
|
||||||
|
[#2217](https://github.com/lovell/sharp/pull/2217)
|
||||||
|
[@malice00](https://github.com/malice00)
|
||||||
|
|
||||||
|
* Enable PNG palette when setting quality, colours, colors or dither.
|
||||||
|
[#2226](https://github.com/lovell/sharp/pull/2226)
|
||||||
|
[@romaleev](https://github.com/romaleev)
|
||||||
|
|
||||||
|
* Add `level` constructor option to use a specific level of a multi-level image.
|
||||||
|
Expose `levels` metadata for multi-level images.
|
||||||
|
[#2222](https://github.com/lovell/sharp/issues/2222)
|
||||||
|
|
||||||
|
* Add support for named `alpha` channel to `extractChannel` operation.
|
||||||
|
[#2138](https://github.com/lovell/sharp/issues/2138)
|
||||||
|
|
||||||
|
* Add experimental `sharpness` calculation to `stats()` response.
|
||||||
|
[#2251](https://github.com/lovell/sharp/issues/2251)
|
||||||
|
|
||||||
|
* Emit `warning` event for non-critical processing problems.
|
||||||
|
[#2032](https://github.com/lovell/sharp/issues/2032)
|
||||||
|
|
||||||
### v0.25.3 - 17th May 2020
|
### v0.25.3 - 17th May 2020
|
||||||
|
|
||||||
* Ensure libvips is initialised only once, improves worker thread safety.
|
* Ensure libvips is initialised only once, improves worker thread safety.
|
||||||
|
|||||||
@@ -182,3 +182,24 @@ GitHub: https://github.com/edsilv
|
|||||||
|
|
||||||
Name: Dumitru Deveatii
|
Name: Dumitru Deveatii
|
||||||
GitHub: https://github.com/dimadeveatii
|
GitHub: https://github.com/dimadeveatii
|
||||||
|
|
||||||
|
Name: Roland Asmann
|
||||||
|
GitHub: https://github.com/malice00
|
||||||
|
|
||||||
|
Name: Roman Malieiev
|
||||||
|
GitHub: https://github.com/romaleev
|
||||||
|
|
||||||
|
Name: Jerome Vouillon
|
||||||
|
GitHub: https://github.com/vouillon
|
||||||
|
|
||||||
|
Name: Tomáš Szabo
|
||||||
|
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
|
||||||
|
|||||||
@@ -10,19 +10,19 @@ yarn add sharp
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* Node.js v10+
|
* Node.js v10.16.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 with
|
||||||
Node.js v10+ on the most common platforms:
|
Node.js v10.16.0+ on the most common platforms:
|
||||||
|
|
||||||
* macOS x64 (>= 10.13)
|
* macOS x64 (>= 10.13)
|
||||||
* 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)
|
||||||
* Windows
|
* Windows
|
||||||
|
|
||||||
A ~10MB tarball containing libvips and its most commonly used dependencies
|
A ~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
|
||||||
@@ -81,24 +81,41 @@ Building from source requires:
|
|||||||
|
|
||||||
This is an advanced approach that most people will not require.
|
This is an advanced approach that most people will not require.
|
||||||
|
|
||||||
To install the prebuilt libvips binaries from a custom URL,
|
To install the prebuilt sharp binaries from a custom URL,
|
||||||
set the `sharp_dist_base_url` npm config option
|
set the `sharp_binary_host` npm config option
|
||||||
or the `SHARP_DIST_BASE_URL` environment variable.
|
or the `npm_config_sharp_binary_host` environment variable.
|
||||||
|
|
||||||
For example, both of the following will result in an attempt to download the file located at
|
To install the prebuilt libvips binaries from a custom URL,
|
||||||
`https://hostname/path/libvips-x.y.z-platform.tar.gz`.
|
set the `sharp_libvips_binary_host` npm config option
|
||||||
|
or the `npm_config_sharp_libvips_binary_host` environment variable.
|
||||||
|
|
||||||
|
The version subpath and file name are appended to these.
|
||||||
|
|
||||||
|
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
|
||||||
|
`https://hostname/path/v1.2.3/libvips-1.2.3-platform-arch.tar.br`.
|
||||||
|
|
||||||
|
See the Chinese mirror below for a further example.
|
||||||
|
|
||||||
|
## Chinese mirror
|
||||||
|
|
||||||
|
Alibaba provide a mirror site based in China containing binaries for both sharp and libvips.
|
||||||
|
|
||||||
|
To use this either set the following configuration:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm config set sharp_dist_base_url "https://hostname/path/"
|
npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
|
||||||
|
npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
|
||||||
npm install sharp
|
npm install sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
or set the following environment variables:
|
||||||
SHARP_DIST_BASE_URL="https://hostname/path/" npm install sharp
|
|
||||||
```
|
|
||||||
|
|
||||||
To install the prebuilt sharp binaries from a custom URL, please see
|
```sh
|
||||||
[https://github.com/prebuild/prebuild-install#custom-binaries](https://github.com/prebuild/prebuild-install#custom-binaries)
|
npm_config_sharp_binary_host="https://npm.taobao.org/mirrors/sharp" \
|
||||||
|
npm_config_sharp_libvips_binary_host="https://npm.taobao.org/mirrors/sharp-libvips" \
|
||||||
|
npm install sharp
|
||||||
|
```
|
||||||
|
|
||||||
## FreeBSD
|
## FreeBSD
|
||||||
|
|
||||||
@@ -160,3 +177,10 @@ npx electron-rebuild
|
|||||||
|
|
||||||
Further help can be found at
|
Further help can be found at
|
||||||
[https://electronjs.org/docs/tutorial/using-native-node-modules](https://electronjs.org/docs/tutorial/using-native-node-modules)
|
[https://electronjs.org/docs/tutorial/using-native-node-modules](https://electronjs.org/docs/tutorial/using-native-node-modules)
|
||||||
|
|
||||||
|
## Worker threads
|
||||||
|
|
||||||
|
The main thread must call `require('sharp')`
|
||||||
|
before worker threads are created
|
||||||
|
to ensure shared libraries remain loaded in memory
|
||||||
|
until after all threads are complete.
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ 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.0 - 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.2 - 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.
|
* sharp v0.26.0 / libvips v8.10.0 - Caching within libvips disabled to ensure a fair comparison.
|
||||||
|
|
||||||
## The task
|
## The task
|
||||||
|
|
||||||
@@ -18,25 +18,25 @@ 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 [c5d.large](https://aws.amazon.com/ec2/instance-types/c5/) (2x Xeon Platinum 8124M CPU @ 3.00GHz)
|
||||||
* Ubuntu 18.04 (hvm-ssd/ubuntu-bionic-18.04-amd64-server-20180912 ami-00035f41c82244dab)
|
* Ubuntu 20.04 (ami-0f1d11c92a9467c07)
|
||||||
* Node.js v12.14.1
|
* Node.js v14.8.0
|
||||||
|
|
||||||
## 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.75 | 1.0 |
|
||||||
| mapnik | buffer | buffer | 3.02 | 4.2 |
|
| mapnik | buffer | buffer | 3.00 | 4.0 |
|
||||||
| gm | buffer | buffer | 3.90 | 5.4 |
|
| gm | buffer | buffer | 4.12 | 5.5 |
|
||||||
| gm | file | file | 3.94 | 5.5 |
|
| gm | file | file | 4.13 | 5.5 |
|
||||||
| imagemagick | file | file | 4.30 | 6.0 |
|
| imagemagick | file | file | 4.30 | 5.7 |
|
||||||
| sharp | stream | stream | 23.65 | 32.8 |
|
| sharp | stream | stream | 22.37 | 29.8 |
|
||||||
| sharp | file | file | 24.66 | 34.3 |
|
| sharp | file | file | 23.40 | 31.2 |
|
||||||
| sharp | buffer | buffer | 25.14 | 34.9 |
|
| sharp | buffer | buffer | 24.01 | 32.0 |
|
||||||
|
|
||||||
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 4+ core machines, especially those with larger L1/L2 CPU caches.
|
||||||
|
|
||||||
The I/O limits of the relevant (de)compression library will generally determine maximum throughput.
|
The I/O limits of the relevant (de)compression library will generally determine maximum throughput.
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ const path = require('path');
|
|||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
const npmLog = require('npmlog');
|
const npmLog = require('npmlog');
|
||||||
|
|
||||||
|
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||||
|
|
||||||
const platform = process.env.npm_config_platform || process.platform;
|
const platform = process.env.npm_config_platform || process.platform;
|
||||||
if (platform === 'win32') {
|
if (platform === 'win32') {
|
||||||
const buildDir = path.join(__dirname, '..', 'build');
|
const buildDir = path.join(__dirname, '..', 'build');
|
||||||
@@ -15,7 +17,7 @@ if (platform === 'win32') {
|
|||||||
libvips.mkdirSync(buildDir);
|
libvips.mkdirSync(buildDir);
|
||||||
libvips.mkdirSync(buildReleaseDir);
|
libvips.mkdirSync(buildReleaseDir);
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
const vendorLibDir = path.join(__dirname, '..', 'vendor', 'lib');
|
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, 'lib');
|
||||||
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
||||||
try {
|
try {
|
||||||
fs
|
fs
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const stream = require('stream');
|
||||||
|
const zlib = require('zlib');
|
||||||
|
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
const npmLog = require('npmlog');
|
const npmLog = require('npmlog');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const simpleGet = require('simple-get');
|
const simpleGet = require('simple-get');
|
||||||
const tar = require('tar');
|
const tarFs = require('tar-fs');
|
||||||
|
|
||||||
const agent = require('../lib/agent');
|
const agent = require('../lib/agent');
|
||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
@@ -21,7 +23,8 @@ const minimumGlibcVersionByArch = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
|
const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
|
||||||
const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersionLabelled}/`;
|
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 fail = function (err) {
|
const fail = function (err) {
|
||||||
npmLog.error('sharp', err.message);
|
npmLog.error('sharp', err.message);
|
||||||
@@ -36,18 +39,21 @@ const fail = function (err) {
|
|||||||
const extractTarball = function (tarPath) {
|
const extractTarball = function (tarPath) {
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
const vendorPath = path.join(__dirname, '..', 'vendor');
|
||||||
libvips.mkdirSync(vendorPath);
|
libvips.mkdirSync(vendorPath);
|
||||||
tar
|
const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion);
|
||||||
.extract({
|
libvips.mkdirSync(versionedVendorPath);
|
||||||
file: tarPath,
|
stream.pipeline(
|
||||||
cwd: vendorPath,
|
fs.createReadStream(tarPath),
|
||||||
strict: true
|
new zlib.BrotliDecompress(),
|
||||||
})
|
tarFs.extract(versionedVendorPath),
|
||||||
.catch(function (err) {
|
function (err) {
|
||||||
if (/unexpected end of file/.test(err.message)) {
|
if (err) {
|
||||||
npmLog.error('sharp', `Please delete ${tarPath} as it is not a valid tarball`);
|
if (/unexpected end of file/.test(err.message)) {
|
||||||
|
npmLog.error('sharp', `Please delete ${tarPath} as it is not a valid tarball`);
|
||||||
|
}
|
||||||
|
fail(err);
|
||||||
}
|
}
|
||||||
fail(err);
|
}
|
||||||
});
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -74,8 +80,11 @@ try {
|
|||||||
throw new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Use with glibc ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!semver.satisfies(process.versions.node, process.env.npm_package_engines_node)) {
|
||||||
|
throw new Error(`Expected Node.js version ${process.env.npm_package_engines_node} but found ${process.versions.node}`);
|
||||||
|
}
|
||||||
// Download to per-process temporary file
|
// Download to per-process temporary file
|
||||||
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.gz';
|
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}`);
|
npmLog.info('sharp', `Using cached ${tarPathCache}`);
|
||||||
|
|||||||
12
install/prebuild-ci.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { spawnSync } = require('child_process');
|
||||||
|
|
||||||
|
const { prebuild_upload: hasToken, APPVEYOR_REPO_TAG_NAME, TRAVIS_TAG } = process.env;
|
||||||
|
|
||||||
|
if (hasToken && (APPVEYOR_REPO_TAG_NAME || TRAVIS_TAG)) {
|
||||||
|
spawnSync('node',
|
||||||
|
['./node_modules/prebuild/bin.js', '--runtime', 'napi', '--target', '3'],
|
||||||
|
{ shell: true, stdio: 'inherit' }
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -60,22 +60,19 @@ function ensureAlpha () {
|
|||||||
* // green.jpg is a greyscale image containing the green channel of the input
|
* // green.jpg is a greyscale image containing the green channel of the input
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @param {number|string} channel - zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
|
* @param {number|string} channel - zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid channel
|
* @throws {Error} Invalid channel
|
||||||
*/
|
*/
|
||||||
function extractChannel (channel) {
|
function extractChannel (channel) {
|
||||||
if (channel === 'red') {
|
const channelMap = { red: 0, green: 1, blue: 2, alpha: 3 };
|
||||||
channel = 0;
|
if (Object.keys(channelMap).includes(channel)) {
|
||||||
} else if (channel === 'green') {
|
channel = channelMap[channel];
|
||||||
channel = 1;
|
|
||||||
} else if (channel === 'blue') {
|
|
||||||
channel = 2;
|
|
||||||
}
|
}
|
||||||
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
|
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
|
||||||
this.options.extractChannel = channel;
|
this.options.extractChannel = channel;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue', channel);
|
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,15 +38,20 @@ try {
|
|||||||
const debuglog = util.debuglog('sharp');
|
const debuglog = util.debuglog('sharp');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructs 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 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.
|
||||||
|
*
|
||||||
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
* Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||||
*
|
*
|
||||||
|
* @constructs Sharp
|
||||||
|
*
|
||||||
|
* @emits Sharp#info
|
||||||
|
* @emits Sharp#warning
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('input.jpg')
|
* sharp('input.jpg')
|
||||||
* .resize(300, 200)
|
* .resize(300, 200)
|
||||||
@@ -81,30 +86,36 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* .toBuffer()
|
* .toBuffer()
|
||||||
* .then( ... );
|
* .then( ... );
|
||||||
*
|
*
|
||||||
* @param {(Buffer|String)} [input] - if present, can be
|
* @example
|
||||||
|
* // Convert an animated GIF to an animated WebP
|
||||||
|
* await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||||
|
*
|
||||||
|
* @param {(Buffer|string)} [input] - if present, can be
|
||||||
* a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
* a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
|
||||||
* a String containing the filesystem path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
* a String containing the filesystem path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
||||||
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
* JPEG, PNG, WebP, 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.
|
||||||
* @param {Number|Boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
|
* @param {number|boolean} [options.limitInputPixels=268402689] - Do not process input images where the number of pixels
|
||||||
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
||||||
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
|
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
|
||||||
* @param {Boolean} [options.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, 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, TIFF, PDF), 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]
|
||||||
* @param {Number} [options.raw.height]
|
* @param {number} [options.raw.height]
|
||||||
* @param {Number} [options.raw.channels] - 1-4
|
* @param {number} [options.raw.channels] - 1-4
|
||||||
* @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]
|
||||||
* @param {Number} [options.create.height]
|
* @param {number} [options.create.height]
|
||||||
* @param {Number} [options.create.channels] - 3-4
|
* @param {number} [options.create.channels] - 3-4
|
||||||
* @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.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -181,6 +192,7 @@ const Sharp = function (input, options) {
|
|||||||
streamOut: false,
|
streamOut: false,
|
||||||
withMetadata: false,
|
withMetadata: false,
|
||||||
withMetadataOrientation: -1,
|
withMetadataOrientation: -1,
|
||||||
|
withMetadataIcc: '',
|
||||||
resolveWithObject: false,
|
resolveWithObject: false,
|
||||||
// output format
|
// output format
|
||||||
jpegQuality: 80,
|
jpegQuality: 80,
|
||||||
@@ -208,7 +220,7 @@ const Sharp = function (input, options) {
|
|||||||
tiffCompression: 'jpeg',
|
tiffCompression: 'jpeg',
|
||||||
tiffPredictor: 'horizontal',
|
tiffPredictor: 'horizontal',
|
||||||
tiffPyramid: false,
|
tiffPyramid: false,
|
||||||
tiffSquash: false,
|
tiffBitdepth: 8,
|
||||||
tiffTile: false,
|
tiffTile: false,
|
||||||
tiffTileHeight: 256,
|
tiffTileHeight: 256,
|
||||||
tiffTileWidth: 256,
|
tiffTileWidth: 256,
|
||||||
@@ -229,7 +241,10 @@ const Sharp = function (input, options) {
|
|||||||
linearA: 1,
|
linearA: 1,
|
||||||
linearB: 0,
|
linearB: 0,
|
||||||
// Function to notify of libvips warnings
|
// Function to notify of libvips warnings
|
||||||
debuglog: debuglog,
|
debuglog: warning => {
|
||||||
|
this.emit('warning', warning);
|
||||||
|
debuglog(warning);
|
||||||
|
},
|
||||||
// Function to notify of queue length changes
|
// Function to notify of queue length changes
|
||||||
queueListener: function (queueLength) {
|
queueListener: function (queueLength) {
|
||||||
Sharp.queue.emit('change', queueLength);
|
Sharp.queue.emit('change', queueLength);
|
||||||
|
|||||||
32
lib/input.js
@@ -9,9 +9,9 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _inputOptionsFromObject (obj) {
|
function _inputOptionsFromObject (obj) {
|
||||||
const { raw, density, limitInputPixels, sequentialRead, failOnError } = obj;
|
const { raw, density, limitInputPixels, sequentialRead, failOnError, animated, page, pages } = obj;
|
||||||
return [raw, density, limitInputPixels, sequentialRead, failOnError].some(is.defined)
|
return [raw, density, limitInputPixels, sequentialRead, failOnError, animated, page, pages].some(is.defined)
|
||||||
? { raw, density, limitInputPixels, sequentialRead, failOnError }
|
? { raw, density, limitInputPixels, sequentialRead, failOnError, animated, page, pages }
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,10 +57,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
|
||||||
@@ -99,6 +99,13 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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;
|
||||||
@@ -113,6 +120,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw is.invalidParameterError('page', 'integer between 0 and 100000', inputOptions.page);
|
throw is.invalidParameterError('page', 'integer between 0 and 100000', inputOptions.page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Multi-level input (OpenSlide)
|
||||||
|
if (is.defined(inputOptions.level)) {
|
||||||
|
if (is.integer(inputOptions.level) && is.inRange(inputOptions.level, 0, 256)) {
|
||||||
|
inputDescriptor.level = inputOptions.level;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (is.defined(inputOptions.create)) {
|
if (is.defined(inputOptions.create)) {
|
||||||
if (
|
if (
|
||||||
@@ -208,6 +223,7 @@ function _isStreamInput () {
|
|||||||
* - `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
|
||||||
* - `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
|
||||||
@@ -290,6 +306,8 @@ function metadata (callback) {
|
|||||||
* - `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)
|
||||||
|
* - `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const image = sharp(inputJpg);
|
* const image = sharp(inputJpg);
|
||||||
@@ -299,6 +317,10 @@ function metadata (callback) {
|
|||||||
* // stats contains the channel-wise statistics array and the isOpaque value
|
* // stats contains the channel-wise statistics array and the isOpaque value
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* const { entropy, sharpness, dominant } = await sharp(input).stats();
|
||||||
|
* const { r, g, b } = dominant;
|
||||||
|
*
|
||||||
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
||||||
* @returns {Promise<Object>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const object = function (val) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const plainObject = function (val) {
|
const plainObject = function (val) {
|
||||||
return object(val) && Object.prototype.toString.call(val) === '[object Object]';
|
return Object.prototype.toString.call(val) === '[object Object]';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +45,7 @@ const bool = function (val) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const buffer = function (val) {
|
const buffer = function (val) {
|
||||||
return object(val) && val instanceof Buffer;
|
return val instanceof Buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +69,7 @@ const number = function (val) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const integer = function (val) {
|
const integer = function (val) {
|
||||||
return number(val) && val % 1 === 0;
|
return Number.isInteger(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +85,7 @@ const inRange = function (val, min, max) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
const inArray = function (val, list) {
|
const inArray = function (val, list) {
|
||||||
return list.indexOf(val) !== -1;
|
return list.includes(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -48,24 +48,18 @@ const globalLibvipsVersion = function () {
|
|||||||
|
|
||||||
const hasVendoredLibvips = function () {
|
const hasVendoredLibvips = function () {
|
||||||
const currentPlatformId = platform();
|
const currentPlatformId = platform();
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion);
|
||||||
let vendorVersionId;
|
|
||||||
let vendorPlatformId;
|
let vendorPlatformId;
|
||||||
try {
|
try {
|
||||||
vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips;
|
|
||||||
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
/* istanbul ignore if */
|
|
||||||
if (vendorVersionId && vendorVersionId !== minimumLibvipsVersion) {
|
|
||||||
throw new Error(`Found vendored libvips v${vendorVersionId} but require v${minimumLibvipsVersion}. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
|
||||||
}
|
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (vendorPlatformId) {
|
if (vendorPlatformId) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (currentPlatformId === vendorPlatformId) {
|
if (currentPlatformId === vendorPlatformId) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
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 {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
158
lib/output.js
@@ -11,7 +11,8 @@ const formats = new Map([
|
|||||||
['png', 'png'],
|
['png', 'png'],
|
||||||
['raw', 'raw'],
|
['raw', 'raw'],
|
||||||
['tiff', 'tiff'],
|
['tiff', 'tiff'],
|
||||||
['webp', 'webp']
|
['webp', 'webp'],
|
||||||
|
['gif', 'gif']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +119,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.
|
||||||
@@ -131,6 +133,7 @@ function toBuffer (options, callback) {
|
|||||||
*
|
*
|
||||||
* @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.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -144,6 +147,13 @@ 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.icc)) {
|
||||||
|
if (is.string(options.icc)) {
|
||||||
|
this.options.withMetadataIcc = options.icc;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('icc', 'string filesystem path to ICC profile', options.icc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -173,6 +183,8 @@ 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,15 +197,15 @@ function toFormat (format, options) {
|
|||||||
* @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'] - for quality < 90, set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' (use chroma subsampling); for quality >= 90 chroma is never subsampled
|
* @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.optimizeCoding=true] - alternative spelling of optimiseCoding
|
||||||
* @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
|
||||||
* @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
|
||||||
* @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
|
* @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
|
||||||
* @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
* @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans, requires libvips compiled with support for mozjpeg
|
||||||
* @param {boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
|
||||||
* @param {boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
|
||||||
* @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
|
* @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
|
||||||
* @param {number} [options.quantizationTable=0] - alternative spelling of quantisationTable
|
* @param {number} [options.quantizationTable=0] - alternative spelling of quantisationTable, requires libvips compiled with support for mozjpeg
|
||||||
* @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
|
||||||
@@ -253,6 +265,8 @@ function jpeg (options) {
|
|||||||
* PNG output is always full colour at 8 or 16 bits per pixel.
|
* PNG output is always 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.
|
||||||
*
|
*
|
||||||
|
* 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 PNG output
|
||||||
* const data = await sharp(input)
|
* const data = await sharp(input)
|
||||||
@@ -264,10 +278,10 @@ function jpeg (options) {
|
|||||||
* @param {number} [options.compressionLevel=9] - zlib compression level, 0-9
|
* @param {number} [options.compressionLevel=9] - zlib compression level, 0-9
|
||||||
* @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, requires libvips compiled with support for libimagequant
|
||||||
* @param {number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, 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`, requires libvips compiled with support for libimagequant
|
||||||
* @param {number} [options.colours=256] - maximum number of palette entries, requires libvips compiled with support for libimagequant
|
* @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||||
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant
|
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||||
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant
|
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
||||||
* @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
|
||||||
@@ -289,28 +303,30 @@ function png (options) {
|
|||||||
}
|
}
|
||||||
if (is.defined(options.palette)) {
|
if (is.defined(options.palette)) {
|
||||||
this._setBooleanOption('pngPalette', options.palette);
|
this._setBooleanOption('pngPalette', options.palette);
|
||||||
if (this.options.pngPalette) {
|
} else if (is.defined(options.quality) || is.defined(options.colours || options.colors) || is.defined(options.dither)) {
|
||||||
if (is.defined(options.quality)) {
|
this._setBooleanOption('pngPalette', true);
|
||||||
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
|
}
|
||||||
this.options.pngQuality = options.quality;
|
if (this.options.pngPalette) {
|
||||||
} else {
|
if (is.defined(options.quality)) {
|
||||||
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
|
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
|
||||||
}
|
this.options.pngQuality = options.quality;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
|
||||||
}
|
}
|
||||||
const colours = options.colours || options.colors;
|
}
|
||||||
if (is.defined(colours)) {
|
const colours = options.colours || options.colors;
|
||||||
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
if (is.defined(colours)) {
|
||||||
this.options.pngColours = colours;
|
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
||||||
} else {
|
this.options.pngColours = colours;
|
||||||
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
} else {
|
||||||
}
|
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
||||||
}
|
}
|
||||||
if (is.defined(options.dither)) {
|
}
|
||||||
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
|
if (is.defined(options.dither)) {
|
||||||
this.options.pngDither = options.dither;
|
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
|
||||||
} else {
|
this.options.pngDither = options.dither;
|
||||||
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
|
} else {
|
||||||
}
|
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,6 +350,9 @@ function png (options) {
|
|||||||
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
||||||
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
||||||
* @param {number} [options.reductionEffort=4] - level of CPU effort to reduce file size, integer 0-6
|
* @param {number} [options.reductionEffort=4] - level of CPU effort to reduce file size, integer 0-6
|
||||||
|
* @param {number} [options.pageHeight] - page height for animated output
|
||||||
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||||
|
* @param {number[]} [options.delay] - list of delays between animation frames (in milliseconds)
|
||||||
* @param {boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
* @param {boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@@ -369,9 +388,73 @@ function webp (options) {
|
|||||||
throw is.invalidParameterError('reductionEffort', 'integer between 0 and 6', options.reductionEffort);
|
throw is.invalidParameterError('reductionEffort', 'integer between 0 and 6', options.reductionEffort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trySetAnimationOptions(options, this.options);
|
||||||
return this._updateFormatOut('webp', options);
|
return this._updateFormatOut('webp', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use these GIF options for output image.
|
||||||
|
*
|
||||||
|
* Requires libvips compiled with support for ImageMagick or GraphicsMagick.
|
||||||
|
* The prebuilt binaries do not include this - see
|
||||||
|
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
||||||
|
*
|
||||||
|
* @param {Object} [options] - output options
|
||||||
|
* @param {number} [options.pageHeight] - page height for animated output
|
||||||
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||||
|
* @param {number[]} [options.delay] - list of delays between animation frames (in milliseconds)
|
||||||
|
* @param {boolean} [options.force=true] - force GIF output, otherwise attempt to use input format
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid options
|
||||||
|
*/
|
||||||
|
/* istanbul ignore next */
|
||||||
|
function gif (options) {
|
||||||
|
if (!this.constructor.format.magick.output.buffer) {
|
||||||
|
throw new Error('The gif operation requires libvips to have been installed with support for ImageMagick');
|
||||||
|
}
|
||||||
|
trySetAnimationOptions(options, this.options);
|
||||||
|
return this._updateFormatOut('gif', options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set animation options if available.
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* @param {Object} [source] - output options
|
||||||
|
* @param {number} [source.pageHeight] - page height for animated output
|
||||||
|
* @param {number} [source.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||||
|
* @param {number[]} [source.delay] - list of delays between animation frames (in milliseconds)
|
||||||
|
* @param {Object} [target] - target object for valid options
|
||||||
|
* @throws {Error} Invalid options
|
||||||
|
*/
|
||||||
|
function trySetAnimationOptions (source, target) {
|
||||||
|
if (is.object(source) && is.defined(source.pageHeight)) {
|
||||||
|
if (is.integer(source.pageHeight) && source.pageHeight > 0) {
|
||||||
|
target.pageHeight = source.pageHeight;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('pageHeight', 'integer larger than 0', source.pageHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.object(source) && is.defined(source.loop)) {
|
||||||
|
if (is.integer(source.loop) && is.inRange(source.loop, 0, 65535)) {
|
||||||
|
target.loop = source.loop;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('loop', 'integer between 0 and 65535', source.loop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.object(source) && is.defined(source.delay)) {
|
||||||
|
if (
|
||||||
|
Array.isArray(source.delay) &&
|
||||||
|
source.delay.every(is.integer) &&
|
||||||
|
source.delay.every(v => is.inRange(v, 0, 65535))) {
|
||||||
|
target.delay = source.delay;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('delay', 'array of integers between 0 and 65535', source.delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these TIFF options for output image.
|
* Use these TIFF options for output image.
|
||||||
*
|
*
|
||||||
@@ -380,7 +463,7 @@ function webp (options) {
|
|||||||
* sharp('input.svg')
|
* sharp('input.svg')
|
||||||
* .tiff({
|
* .tiff({
|
||||||
* compression: 'lzw',
|
* compression: 'lzw',
|
||||||
* squash: true
|
* bitdepth: 1
|
||||||
* })
|
* })
|
||||||
* .toFile('1-bpp-output.tiff')
|
* .toFile('1-bpp-output.tiff')
|
||||||
* .then(info => { ... });
|
* .then(info => { ... });
|
||||||
@@ -396,7 +479,7 @@ function webp (options) {
|
|||||||
* @param {boolean} [options.tileHeight=256] - vertical tile size
|
* @param {boolean} [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.squash=false] - squash 8-bit images down to 1 bit
|
* @param {boolean} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
@@ -409,8 +492,12 @@ function tiff (options) {
|
|||||||
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(options.squash)) {
|
if (is.defined(options.bitdepth)) {
|
||||||
this._setBooleanOption('tiffSquash', options.squash);
|
if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [1, 2, 4, 8])) {
|
||||||
|
this.options.tiffBitdepth = options.bitdepth;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('bitdepth', '1, 2, 4 or 8', options.bitdepth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// tiling
|
// tiling
|
||||||
if (is.defined(options.tile)) {
|
if (is.defined(options.tile)) {
|
||||||
@@ -798,6 +885,7 @@ module.exports = function (Sharp) {
|
|||||||
webp,
|
webp,
|
||||||
tiff,
|
tiff,
|
||||||
heif,
|
heif,
|
||||||
|
gif,
|
||||||
raw,
|
raw,
|
||||||
tile,
|
tile,
|
||||||
// Private
|
// Private
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ module.exports = function () {
|
|||||||
const platformId = [`${platform}${libc}`];
|
const platformId = [`${platform}${libc}`];
|
||||||
|
|
||||||
if (arch === 'arm') {
|
if (arch === 'arm') {
|
||||||
platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || '6'}`);
|
const fallback = process.versions.electron ? '7' : '6';
|
||||||
|
platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || fallback}`);
|
||||||
} else if (arch === 'arm64') {
|
} else if (arch === 'arm64') {
|
||||||
platformId.push(`arm64v${env.npm_config_arm_version || '8'}`);
|
platformId.push(`arm64v${env.npm_config_arm_version || '8'}`);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ let versions = {
|
|||||||
vips: sharp.libvipsVersion()
|
vips: sharp.libvipsVersion()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
versions = require('../vendor/versions.json');
|
versions = require(`../vendor/${versions.vips}/versions.json`);
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
39
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 and TIFF images",
|
||||||
"version": "0.25.3",
|
"version": "0.26.1",
|
||||||
"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": [
|
||||||
@@ -66,12 +66,15 @@
|
|||||||
"Paul Neave <paul.neave@gmail.com>",
|
"Paul Neave <paul.neave@gmail.com>",
|
||||||
"Brendan Kennedy <brenwken@gmail.com>",
|
"Brendan Kennedy <brenwken@gmail.com>",
|
||||||
"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>",
|
||||||
|
"Tomas Szabo <tomas.szabo@deftomat.com>",
|
||||||
|
"Robert O'Rourke <robert@o-rourke.org>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)",
|
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (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 && prebuild-ci",
|
"test": "semistandard && cpplint && npm run test-unit && npm run test-licensing && node install/prebuild-ci",
|
||||||
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --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",
|
||||||
@@ -84,6 +87,7 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"binding.gyp",
|
"binding.gyp",
|
||||||
"install/**",
|
"install/**",
|
||||||
|
"!install/prebuild-ci.js",
|
||||||
"lib/**",
|
"lib/**",
|
||||||
"src/**"
|
"src/**"
|
||||||
],
|
],
|
||||||
@@ -110,36 +114,37 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^3.1.2",
|
"color": "^3.1.2",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"node-addon-api": "^3.0.0",
|
"node-addon-api": "^3.0.2",
|
||||||
"npmlog": "^4.1.2",
|
"npmlog": "^4.1.2",
|
||||||
"prebuild-install": "^5.3.3",
|
"prebuild-install": "^5.3.5",
|
||||||
"semver": "^7.3.2",
|
"semver": "^7.3.2",
|
||||||
"simple-get": "^4.0.0",
|
"simple-get": "^4.0.0",
|
||||||
"tar": "^6.0.2",
|
"tar-fs": "^2.1.0",
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^3.2.0",
|
"async": "^3.2.0",
|
||||||
"cc": "^2.0.1",
|
"cc": "^2.0.1",
|
||||||
"decompress-zip": "^0.3.2",
|
"decompress-zip": "^0.3.2",
|
||||||
"documentation": "^13.0.0",
|
"documentation": "^13.0.2",
|
||||||
"exif-reader": "^1.0.3",
|
"exif-reader": "^1.0.3",
|
||||||
"icc": "^1.0.0",
|
"icc": "^2.0.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^7.1.2",
|
"mocha": "^8.1.1",
|
||||||
"mock-fs": "^4.12.0",
|
"mock-fs": "^4.13.0",
|
||||||
"nyc": "^15.0.1",
|
"nyc": "^15.1.0",
|
||||||
"prebuild": "^10.0.0",
|
"prebuild": "^10.0.1",
|
||||||
"prebuild-ci": "^3.1.0",
|
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"semistandard": "^14.2.0"
|
"semistandard": "^14.2.3"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"config": {
|
"config": {
|
||||||
"libvips": "8.9.1"
|
"libvips": "8.10.0",
|
||||||
|
"runtime": "napi",
|
||||||
|
"target": 3
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10.16.0"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://opencollective.com/libvips"
|
"url": "https://opencollective.com/libvips"
|
||||||
|
|||||||
173
src/common.cc
@@ -17,6 +17,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <map>
|
||||||
#include <mutex> // NOLINT(build/c++11)
|
#include <mutex> // NOLINT(build/c++11)
|
||||||
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
@@ -41,6 +42,9 @@ namespace sharp {
|
|||||||
int32_t AttrAsInt32(Napi::Object obj, std::string attr) {
|
int32_t AttrAsInt32(Napi::Object obj, std::string attr) {
|
||||||
return obj.Get(attr).As<Napi::Number>().Int32Value();
|
return obj.Get(attr).As<Napi::Number>().Int32Value();
|
||||||
}
|
}
|
||||||
|
int32_t AttrAsInt32(Napi::Object obj, unsigned int const attr) {
|
||||||
|
return obj.Get(attr).As<Napi::Number>().Int32Value();
|
||||||
|
}
|
||||||
double AttrAsDouble(Napi::Object obj, std::string attr) {
|
double AttrAsDouble(Napi::Object obj, std::string attr) {
|
||||||
return obj.Get(attr).As<Napi::Number>().DoubleValue();
|
return obj.Get(attr).As<Napi::Number>().DoubleValue();
|
||||||
}
|
}
|
||||||
@@ -58,6 +62,14 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
return rgba;
|
return rgba;
|
||||||
}
|
}
|
||||||
|
std::vector<int32_t> AttrAsInt32Vector(Napi::Object obj, std::string attr) {
|
||||||
|
Napi::Array array = obj.Get(attr).As<Napi::Array>();
|
||||||
|
std::vector<int32_t> vector(array.Length());
|
||||||
|
for (unsigned int i = 0; i < array.Length(); i++) {
|
||||||
|
vector[i] = AttrAsInt32(array, i);
|
||||||
|
}
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
|
||||||
// Create an InputDescriptor instance from a Napi::Object describing an input image
|
// Create an InputDescriptor instance from a Napi::Object describing an input image
|
||||||
InputDescriptor* CreateInputDescriptor(Napi::Object input) {
|
InputDescriptor* CreateInputDescriptor(Napi::Object input) {
|
||||||
@@ -88,6 +100,10 @@ namespace sharp {
|
|||||||
if (HasAttr(input, "page")) {
|
if (HasAttr(input, "page")) {
|
||||||
descriptor->page = AttrAsUint32(input, "page");
|
descriptor->page = AttrAsUint32(input, "page");
|
||||||
}
|
}
|
||||||
|
// Multi-level input (OpenSlide)
|
||||||
|
if (HasAttr(input, "level")) {
|
||||||
|
descriptor->level = AttrAsUint32(input, "level");
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (HasAttr(input, "createChannels")) {
|
if (HasAttr(input, "createChannels")) {
|
||||||
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
||||||
@@ -121,6 +137,9 @@ namespace sharp {
|
|||||||
bool IsWebp(std::string const &str) {
|
bool IsWebp(std::string const &str) {
|
||||||
return EndsWith(str, ".webp") || EndsWith(str, ".WEBP");
|
return EndsWith(str, ".webp") || EndsWith(str, ".WEBP");
|
||||||
}
|
}
|
||||||
|
bool IsGif(std::string const &str) {
|
||||||
|
return EndsWith(str, ".gif") || EndsWith(str, ".GIF");
|
||||||
|
}
|
||||||
bool IsTiff(std::string const &str) {
|
bool IsTiff(std::string const &str) {
|
||||||
return EndsWith(str, ".tif") || EndsWith(str, ".tiff") || EndsWith(str, ".TIF") || EndsWith(str, ".TIFF");
|
return EndsWith(str, ".tif") || EndsWith(str, ".tiff") || EndsWith(str, ".TIF") || EndsWith(str, ".TIFF");
|
||||||
}
|
}
|
||||||
@@ -169,32 +188,42 @@ namespace sharp {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, ImageType> loaderToType = {
|
||||||
|
{ "jpegload", ImageType::JPEG },
|
||||||
|
{ "jpegload_buffer", ImageType::JPEG },
|
||||||
|
{ "pngload", ImageType::PNG },
|
||||||
|
{ "pngload_buffer", ImageType::PNG },
|
||||||
|
{ "webpload", ImageType::WEBP },
|
||||||
|
{ "webpload_buffer", ImageType::WEBP },
|
||||||
|
{ "tiffload", ImageType::TIFF },
|
||||||
|
{ "tiffload_buffer", ImageType::TIFF },
|
||||||
|
{ "gifload", ImageType::GIF },
|
||||||
|
{ "gifload_buffer", ImageType::GIF },
|
||||||
|
{ "svgload", ImageType::SVG },
|
||||||
|
{ "svgload_buffer", ImageType::SVG },
|
||||||
|
{ "heifload", ImageType::HEIF },
|
||||||
|
{ "heifload_buffer", ImageType::HEIF },
|
||||||
|
{ "pdfload", ImageType::PDF },
|
||||||
|
{ "pdfload_buffer", ImageType::PDF },
|
||||||
|
{ "magickload", ImageType::MAGICK },
|
||||||
|
{ "magickload_buffer", ImageType::MAGICK },
|
||||||
|
{ "openslideload", ImageType::OPENSLIDE },
|
||||||
|
{ "ppmload", ImageType::PPM },
|
||||||
|
{ "fitsload", ImageType::FITS },
|
||||||
|
{ "vipsload", ImageType::VIPS },
|
||||||
|
{ "rawload", ImageType::RAW }
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Determine image format of a buffer.
|
Determine image format of a buffer.
|
||||||
*/
|
*/
|
||||||
ImageType DetermineImageType(void *buffer, size_t const length) {
|
ImageType DetermineImageType(void *buffer, size_t const length) {
|
||||||
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 != NULL) {
|
if (load != nullptr) {
|
||||||
std::string const loader = load;
|
auto it = loaderToType.find(vips_nickname_find(g_type_from_name(load)));
|
||||||
if (EndsWith(loader, "JpegBuffer")) {
|
if (it != loaderToType.end()) {
|
||||||
imageType = ImageType::JPEG;
|
imageType = it->second;
|
||||||
} else if (EndsWith(loader, "PngBuffer")) {
|
|
||||||
imageType = ImageType::PNG;
|
|
||||||
} else if (EndsWith(loader, "WebpBuffer")) {
|
|
||||||
imageType = ImageType::WEBP;
|
|
||||||
} else if (EndsWith(loader, "TiffBuffer")) {
|
|
||||||
imageType = ImageType::TIFF;
|
|
||||||
} else if (EndsWith(loader, "GifBuffer")) {
|
|
||||||
imageType = ImageType::GIF;
|
|
||||||
} else if (EndsWith(loader, "SvgBuffer")) {
|
|
||||||
imageType = ImageType::SVG;
|
|
||||||
} else if (EndsWith(loader, "HeifBuffer")) {
|
|
||||||
imageType = ImageType::HEIF;
|
|
||||||
} else if (EndsWith(loader, "PdfBuffer")) {
|
|
||||||
imageType = ImageType::PDF;
|
|
||||||
} else if (EndsWith(loader, "MagickBuffer")) {
|
|
||||||
imageType = ImageType::MAGICK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return imageType;
|
return imageType;
|
||||||
@@ -207,36 +236,12 @@ 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) {
|
||||||
std::string const loader = load;
|
auto it = loaderToType.find(vips_nickname_find(g_type_from_name(load)));
|
||||||
if (EndsWith(loader, "JpegFile")) {
|
if (it != loaderToType.end()) {
|
||||||
imageType = ImageType::JPEG;
|
imageType = it->second;
|
||||||
} else if (EndsWith(loader, "PngFile")) {
|
|
||||||
imageType = ImageType::PNG;
|
|
||||||
} else if (EndsWith(loader, "WebpFile")) {
|
|
||||||
imageType = ImageType::WEBP;
|
|
||||||
} else if (EndsWith(loader, "Openslide")) {
|
|
||||||
imageType = ImageType::OPENSLIDE;
|
|
||||||
} else if (EndsWith(loader, "TiffFile")) {
|
|
||||||
imageType = ImageType::TIFF;
|
|
||||||
} else if (EndsWith(loader, "GifFile")) {
|
|
||||||
imageType = ImageType::GIF;
|
|
||||||
} else if (EndsWith(loader, "SvgFile")) {
|
|
||||||
imageType = ImageType::SVG;
|
|
||||||
} else if (EndsWith(loader, "HeifFile")) {
|
|
||||||
imageType = ImageType::HEIF;
|
|
||||||
} else if (EndsWith(loader, "PdfFile")) {
|
|
||||||
imageType = ImageType::PDF;
|
|
||||||
} else if (EndsWith(loader, "Ppm")) {
|
|
||||||
imageType = ImageType::PPM;
|
|
||||||
} else if (EndsWith(loader, "Fits")) {
|
|
||||||
imageType = ImageType::FITS;
|
|
||||||
} else if (EndsWith(loader, "Vips")) {
|
|
||||||
imageType = ImageType::VIPS;
|
|
||||||
} else if (EndsWith(loader, "Magick") || EndsWith(loader, "MagickFile")) {
|
|
||||||
imageType = ImageType::MAGICK;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (EndsWith(vips::VError().what(), " not found\n")) {
|
if (EndsWith(vips::VError().what(), " does not exist\n")) {
|
||||||
imageType = ImageType::MISSING;
|
imageType = ImageType::MISSING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,6 +253,8 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
bool ImageTypeSupportsPage(ImageType imageType) {
|
bool ImageTypeSupportsPage(ImageType imageType) {
|
||||||
return
|
return
|
||||||
|
imageType == ImageType::WEBP ||
|
||||||
|
imageType == ImageType::MAGICK ||
|
||||||
imageType == ImageType::GIF ||
|
imageType == ImageType::GIF ||
|
||||||
imageType == ImageType::TIFF ||
|
imageType == ImageType::TIFF ||
|
||||||
imageType == ImageType::HEIF ||
|
imageType == ImageType::HEIF ||
|
||||||
@@ -292,6 +299,9 @@ namespace sharp {
|
|||||||
option->set("n", descriptor->pages);
|
option->set("n", descriptor->pages);
|
||||||
option->set("page", descriptor->page);
|
option->set("page", descriptor->page);
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::OPENSLIDE) {
|
||||||
|
option->set("level", descriptor->level);
|
||||||
|
}
|
||||||
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);
|
||||||
@@ -341,6 +351,9 @@ namespace sharp {
|
|||||||
option->set("n", descriptor->pages);
|
option->set("n", descriptor->pages);
|
||||||
option->set("page", descriptor->page);
|
option->set("page", descriptor->page);
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::OPENSLIDE) {
|
||||||
|
option->set("level", descriptor->level);
|
||||||
|
}
|
||||||
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);
|
||||||
@@ -410,6 +423,38 @@ namespace sharp {
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set animation properties if necessary.
|
||||||
|
Non-provided properties will be loaded from image.
|
||||||
|
*/
|
||||||
|
VImage SetAnimationProperties(VImage image, int pageHeight, std::vector<int> delay, int loop) {
|
||||||
|
bool hasDelay = delay.size() != 1 || delay.front() != -1;
|
||||||
|
|
||||||
|
if (pageHeight == 0 && image.get_typeof(VIPS_META_PAGE_HEIGHT) == G_TYPE_INT) {
|
||||||
|
pageHeight = image.get_int(VIPS_META_PAGE_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasDelay && image.get_typeof("delay") == VIPS_TYPE_ARRAY_INT) {
|
||||||
|
delay = image.get_array_int("delay");
|
||||||
|
hasDelay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loop == -1 && image.get_typeof("loop") == G_TYPE_INT) {
|
||||||
|
loop = image.get_int("loop");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageHeight == 0) return image;
|
||||||
|
|
||||||
|
// It is necessary to create the copy as otherwise, pageHeight will be ignored!
|
||||||
|
VImage copy = image.copy();
|
||||||
|
|
||||||
|
copy.set(VIPS_META_PAGE_HEIGHT, pageHeight);
|
||||||
|
if (hasDelay) copy.set("delay", delay);
|
||||||
|
if (loop != -1) copy.set("loop", loop);
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Does this image have a non-default density?
|
Does this image have a non-default density?
|
||||||
*/
|
*/
|
||||||
@@ -440,14 +485,21 @@ 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(VIPS_META_PAGE_HEIGHT) == G_TYPE_INT
|
||||||
|
? image.get_int(VIPS_META_PAGE_HEIGHT)
|
||||||
|
: image.height();
|
||||||
if (imageType == ImageType::JPEG) {
|
if (imageType == ImageType::JPEG) {
|
||||||
if (image.width() > 65535 || image.height() > 65535) {
|
if (image.width() > 65535 || height > 65535) {
|
||||||
throw vips::VError("Processed image is too large for the JPEG format");
|
throw vips::VError("Processed image is too large for the JPEG format");
|
||||||
}
|
}
|
||||||
} else if (imageType == ImageType::WEBP) {
|
} else if (imageType == ImageType::WEBP) {
|
||||||
if (image.width() > 16383 || image.height() > 16383) {
|
if (image.width() > 16383 || height > 16383) {
|
||||||
throw vips::VError("Processed image is too large for the WebP format");
|
throw vips::VError("Processed image is too large for the WebP format");
|
||||||
}
|
}
|
||||||
|
} else if (imageType == ImageType::GIF) {
|
||||||
|
if (image.width() > 65535 || height > 65535) {
|
||||||
|
throw vips::VError("Processed image is too large for the GIF format");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,4 +762,25 @@ namespace sharp {
|
|||||||
return std::make_tuple(image, alphaColour);
|
return std::make_tuple(image, alphaColour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Removes alpha channel, if any.
|
||||||
|
*/
|
||||||
|
VImage RemoveAlpha(VImage image) {
|
||||||
|
if (HasAlpha(image)) {
|
||||||
|
image = image.extract_band(0, VImage::option()->set("n", image.bands() - 1));
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Ensures alpha channel, if missing.
|
||||||
|
*/
|
||||||
|
VImage EnsureAlpha(VImage image) {
|
||||||
|
if (!HasAlpha(image)) {
|
||||||
|
std::vector<double> alpha;
|
||||||
|
alpha.push_back(sharp::MaximumImageAlpha(image.interpretation()));
|
||||||
|
image = image.bandjoin_const(alpha);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|||||||
25
src/common.h
@@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
// 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 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 10))
|
||||||
#error "libvips version 8.9.1+ is required - please see https://sharp.pixelplumbing.com/install"
|
#error "libvips version 8.10.0+ 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)))
|
||||||
@@ -57,6 +57,7 @@ namespace sharp {
|
|||||||
int rawHeight;
|
int rawHeight;
|
||||||
int pages;
|
int pages;
|
||||||
int page;
|
int page;
|
||||||
|
int level;
|
||||||
int createChannels;
|
int createChannels;
|
||||||
int createWidth;
|
int createWidth;
|
||||||
int createHeight;
|
int createHeight;
|
||||||
@@ -75,6 +76,7 @@ namespace sharp {
|
|||||||
rawHeight(0),
|
rawHeight(0),
|
||||||
pages(1),
|
pages(1),
|
||||||
page(0),
|
page(0),
|
||||||
|
level(0),
|
||||||
createChannels(0),
|
createChannels(0),
|
||||||
createWidth(0),
|
createWidth(0),
|
||||||
createHeight(0),
|
createHeight(0),
|
||||||
@@ -86,10 +88,12 @@ namespace sharp {
|
|||||||
std::string AttrAsStr(Napi::Object obj, std::string attr);
|
std::string AttrAsStr(Napi::Object obj, std::string 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);
|
||||||
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> AttrAsRgba(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
|
||||||
InputDescriptor* CreateInputDescriptor(Napi::Object input);
|
InputDescriptor* CreateInputDescriptor(Napi::Object input);
|
||||||
@@ -123,6 +127,7 @@ namespace sharp {
|
|||||||
bool IsJpeg(std::string const &str);
|
bool IsJpeg(std::string const &str);
|
||||||
bool IsPng(std::string const &str);
|
bool IsPng(std::string const &str);
|
||||||
bool IsWebp(std::string const &str);
|
bool IsWebp(std::string const &str);
|
||||||
|
bool IsGif(std::string const &str);
|
||||||
bool IsTiff(std::string const &str);
|
bool IsTiff(std::string const &str);
|
||||||
bool IsHeic(std::string const &str);
|
bool IsHeic(std::string const &str);
|
||||||
bool IsHeif(std::string const &str);
|
bool IsHeif(std::string const &str);
|
||||||
@@ -182,6 +187,12 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage RemoveExifOrientation(VImage image);
|
VImage RemoveExifOrientation(VImage image);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Set animation properties if necessary.
|
||||||
|
Non-provided properties will be loaded from image.
|
||||||
|
*/
|
||||||
|
VImage SetAnimationProperties(VImage image, int pageHeight, std::vector<int> delay, int loop);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Does this image have a non-default density?
|
Does this image have a non-default density?
|
||||||
*/
|
*/
|
||||||
@@ -269,6 +280,16 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour);
|
std::tuple<VImage, std::vector<double>> ApplyAlpha(VImage image, std::vector<double> colour);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Removes alpha channel, if any.
|
||||||
|
*/
|
||||||
|
VImage RemoveAlpha(VImage image);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Ensures alpha channel, if missing.
|
||||||
|
*/
|
||||||
|
VImage EnsureAlpha(VImage image);
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
#endif // SRC_COMMON_H_
|
#endif // SRC_COMMON_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// bodies for vips operations
|
// bodies for vips operations
|
||||||
// Wed 01 Jan 2020 12:22:12 PM CET
|
// Sun 5 Jul 22:36:37 BST 2020
|
||||||
// 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
|
||||||
@@ -754,6 +754,18 @@ VImage VImage::csvload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::csvload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "csvload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::csvsave( const char *filename, VOption *options ) const
|
void VImage::csvsave( const char *filename, VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "csvsave",
|
call( "csvsave",
|
||||||
@@ -762,6 +774,14 @@ void VImage::csvsave( const char *filename, VOption *options ) const
|
|||||||
set( "filename", filename ) );
|
set( "filename", filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VImage::csvsave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "csvsave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::dE00( VImage right, VOption *options ) const
|
VImage VImage::dE00( VImage right, VOption *options ) const
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -1218,6 +1238,18 @@ VImage VImage::gifload_buffer( VipsBlob *buffer, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::gifload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "gifload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::globalbalance( VOption *options ) const
|
VImage VImage::globalbalance( VOption *options ) const
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -1297,6 +1329,18 @@ VImage VImage::heifload_buffer( VipsBlob *buffer, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::heifload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "heifload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::heifsave( const char *filename, VOption *options ) const
|
void VImage::heifsave( const char *filename, VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "heifsave",
|
call( "heifsave",
|
||||||
@@ -1317,6 +1361,14 @@ VipsBlob *VImage::heifsave_buffer( VOption *options ) const
|
|||||||
return( buffer );
|
return( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VImage::heifsave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "heifsave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::hist_cum( VOption *options ) const
|
VImage VImage::hist_cum( VOption *options ) const
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -2028,6 +2080,18 @@ VImage VImage::matload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::matrixinvert( VOption *options ) const
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "matrixinvert",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "out", &out ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::matrixload( const char *filename, VOption *options )
|
VImage VImage::matrixload( const char *filename, VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -2040,6 +2104,18 @@ VImage VImage::matrixload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::matrixload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "matrixload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::matrixprint( VOption *options ) const
|
void VImage::matrixprint( VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "matrixprint",
|
call( "matrixprint",
|
||||||
@@ -2055,6 +2131,14 @@ void VImage::matrixsave( const char *filename, VOption *options ) const
|
|||||||
set( "filename", filename ) );
|
set( "filename", filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VImage::matrixsave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "matrixsave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
double VImage::max( VOption *options ) const
|
double VImage::max( VOption *options ) const
|
||||||
{
|
{
|
||||||
double out;
|
double out;
|
||||||
@@ -2256,6 +2340,18 @@ VImage VImage::pdfload_buffer( VipsBlob *buffer, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::pdfload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "pdfload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
int VImage::percent( double percent, VOption *options ) const
|
int VImage::percent( double percent, VOption *options ) const
|
||||||
{
|
{
|
||||||
int threshold;
|
int threshold;
|
||||||
@@ -2371,6 +2467,18 @@ VImage VImage::ppmload( const char *filename, VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::ppmload_source( VSource source, VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "ppmload_source",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "out", &out )->
|
||||||
|
set( "source", source ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::ppmsave( const char *filename, VOption *options ) const
|
void VImage::ppmsave( const char *filename, VOption *options ) const
|
||||||
{
|
{
|
||||||
call( "ppmsave",
|
call( "ppmsave",
|
||||||
@@ -2379,6 +2487,14 @@ void VImage::ppmsave( const char *filename, VOption *options ) const
|
|||||||
set( "filename", filename ) );
|
set( "filename", filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VImage::ppmsave_target( VTarget target, VOption *options ) const
|
||||||
|
{
|
||||||
|
call( "ppmsave_target",
|
||||||
|
(options ? options : VImage::option())->
|
||||||
|
set( "in", *this )->
|
||||||
|
set( "target", target ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::premultiply( VOption *options ) const
|
VImage VImage::premultiply( VOption *options ) const
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ 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("openslide.level-count") == VIPS_TYPE_REF_STRING) {
|
||||||
|
int const levels = std::stoi(image.get_string("openslide.level-count"));
|
||||||
|
for (int l = 0; l < levels; l++) {
|
||||||
|
std::string prefix = "openslide.level[" + std::to_string(l) + "].";
|
||||||
|
int const width = std::stoi(image.get_string((prefix + "width").data()));
|
||||||
|
int const height = std::stoi(image.get_string((prefix + "height").data()));
|
||||||
|
baton->levels.push_back(std::pair<int, int>(width, height));
|
||||||
|
}
|
||||||
|
}
|
||||||
baton->hasProfile = sharp::HasProfile(image);
|
baton->hasProfile = sharp::HasProfile(image);
|
||||||
// Derived attributes
|
// Derived attributes
|
||||||
baton->hasAlpha = sharp::HasAlpha(image);
|
baton->hasAlpha = sharp::HasAlpha(image);
|
||||||
@@ -177,6 +186,17 @@ 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->levels.empty()) {
|
||||||
|
int i = 0;
|
||||||
|
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
|
||||||
|
for (std::pair<int, int> const &l : baton->levels) {
|
||||||
|
Napi::Object level = Napi::Object::New(env);
|
||||||
|
level.Set("width", l.first);
|
||||||
|
level.Set("height", l.second);
|
||||||
|
levels.Set(i++, level);
|
||||||
|
}
|
||||||
|
info.Set("levels", levels);
|
||||||
|
}
|
||||||
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,6 +39,7 @@ struct MetadataBaton {
|
|||||||
int loop;
|
int loop;
|
||||||
std::vector<int> delay;
|
std::vector<int> delay;
|
||||||
int pagePrimary;
|
int pagePrimary;
|
||||||
|
std::vector<std::pair<int, int>> levels;
|
||||||
bool hasProfile;
|
bool hasProfile;
|
||||||
bool hasAlpha;
|
bool hasAlpha;
|
||||||
int orientation;
|
int orientation;
|
||||||
|
|||||||
@@ -27,29 +27,6 @@ using vips::VImage;
|
|||||||
using vips::VError;
|
using vips::VError;
|
||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
/*
|
|
||||||
Removes alpha channel, if any.
|
|
||||||
*/
|
|
||||||
VImage RemoveAlpha(VImage image) {
|
|
||||||
if (HasAlpha(image)) {
|
|
||||||
image = image.extract_band(0, VImage::option()->set("n", image.bands() - 1));
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Ensures alpha channel, if missing.
|
|
||||||
*/
|
|
||||||
VImage EnsureAlpha(VImage image) {
|
|
||||||
if (!HasAlpha(image)) {
|
|
||||||
std::vector<double> alpha;
|
|
||||||
alpha.push_back(sharp::MaximumImageAlpha(image.interpretation()));
|
|
||||||
image = image.bandjoin_const(alpha);
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tint an image using the specified chroma, preserving the original image luminance
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -25,16 +25,6 @@ using vips::VImage;
|
|||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
/*
|
|
||||||
Removes alpha channel, if any.
|
|
||||||
*/
|
|
||||||
VImage RemoveAlpha(VImage image);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Ensures alpha channel, if missing.
|
|
||||||
*/
|
|
||||||
VImage EnsureAlpha(VImage image);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tint an image using the specified chroma, preserving the original image luminance
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -645,8 +645,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Extract an image channel (aka vips band)
|
// Extract an image channel (aka vips band)
|
||||||
if (baton->extractChannel > -1) {
|
if (baton->extractChannel > -1) {
|
||||||
if (baton->extractChannel >= image.bands()) {
|
if (baton->extractChannel >= image.bands()) {
|
||||||
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
|
if (baton->extractChannel == 3 && sharp::HasAlpha(image)) {
|
||||||
return Error();
|
baton->extractChannel = image.bands() - 1;
|
||||||
|
} else {
|
||||||
|
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
|
||||||
|
return Error();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
VipsInterpretation const interpretation = sharp::Is16Bit(image.interpretation())
|
VipsInterpretation const interpretation = sharp::Is16Bit(image.interpretation())
|
||||||
? VIPS_INTERPRETATION_GREY16
|
? VIPS_INTERPRETATION_GREY16
|
||||||
@@ -680,6 +684,15 @@ 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);
|
||||||
@@ -689,6 +702,16 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
baton->channels = image.bands();
|
baton->channels = image.bands();
|
||||||
baton->width = image.width();
|
baton->width = image.width();
|
||||||
baton->height = image.height();
|
baton->height = image.height();
|
||||||
|
|
||||||
|
bool const supportsGifOutput = vips_type_find("VipsOperation", "magicksave") != 0 &&
|
||||||
|
vips_type_find("VipsOperation", "magicksave_buffer") != 0;
|
||||||
|
|
||||||
|
image = sharp::SetAnimationProperties(
|
||||||
|
image,
|
||||||
|
baton->pageHeight,
|
||||||
|
baton->delay,
|
||||||
|
baton->loop);
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
if (baton->fileOut.empty()) {
|
if (baton->fileOut.empty()) {
|
||||||
// Buffer output
|
// Buffer output
|
||||||
@@ -699,7 +722,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
->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("no_subsample", baton->jpegChromaSubsampling == "4:4:4")
|
->set("subsample_mode", baton->jpegChromaSubsampling == "4:4:4"
|
||||||
|
? VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF
|
||||||
|
: VIPS_FOREIGN_JPEG_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)
|
||||||
@@ -716,8 +741,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
}
|
}
|
||||||
} else if (baton->formatOut == "png" || (baton->formatOut == "input" &&
|
} else if (baton->formatOut == "png" || (baton->formatOut == "input" &&
|
||||||
(inputImageType == sharp::ImageType::PNG || inputImageType == sharp::ImageType::GIF ||
|
(inputImageType == sharp::ImageType::PNG || (inputImageType == sharp::ImageType::GIF && !supportsGifOutput) ||
|
||||||
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 = VIPS_AREA(image.pngsave_buffer(VImage::option()
|
||||||
@@ -751,6 +776,20 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
vips_area_unref(area);
|
vips_area_unref(area);
|
||||||
baton->formatOut = "webp";
|
baton->formatOut = "webp";
|
||||||
|
} else if (baton->formatOut == "gif" ||
|
||||||
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::GIF && supportsGifOutput)) {
|
||||||
|
// Write GIF to buffer
|
||||||
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
||||||
|
VipsArea *area = VIPS_AREA(image.magicksave_buffer(VImage::option()
|
||||||
|
->set("strip", !baton->withMetadata)
|
||||||
|
->set("optimize_gif_frames", TRUE)
|
||||||
|
->set("optimize_gif_transparency", TRUE)
|
||||||
|
->set("format", "gif")));
|
||||||
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
|
baton->bufferOutLength = area->length;
|
||||||
|
area->free_fn = nullptr;
|
||||||
|
vips_area_unref(area);
|
||||||
|
baton->formatOut = "gif";
|
||||||
} else if (baton->formatOut == "tiff" ||
|
} else if (baton->formatOut == "tiff" ||
|
||||||
(baton->formatOut == "input" && inputImageType == sharp::ImageType::TIFF)) {
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::TIFF)) {
|
||||||
// Write TIFF to buffer
|
// Write TIFF to buffer
|
||||||
@@ -765,7 +804,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
VipsArea *area = VIPS_AREA(image.tiffsave_buffer(VImage::option()
|
VipsArea *area = VIPS_AREA(image.tiffsave_buffer(VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->tiffQuality)
|
->set("Q", baton->tiffQuality)
|
||||||
->set("squash", baton->tiffSquash)
|
->set("bitdepth", baton->tiffBitdepth)
|
||||||
->set("compression", baton->tiffCompression)
|
->set("compression", baton->tiffCompression)
|
||||||
->set("predictor", baton->tiffPredictor)
|
->set("predictor", baton->tiffPredictor)
|
||||||
->set("pyramid", baton->tiffPyramid)
|
->set("pyramid", baton->tiffPyramid)
|
||||||
@@ -826,13 +865,16 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
bool const isJpeg = sharp::IsJpeg(baton->fileOut);
|
bool const isJpeg = sharp::IsJpeg(baton->fileOut);
|
||||||
bool const isPng = sharp::IsPng(baton->fileOut);
|
bool const isPng = sharp::IsPng(baton->fileOut);
|
||||||
bool const isWebp = sharp::IsWebp(baton->fileOut);
|
bool const isWebp = sharp::IsWebp(baton->fileOut);
|
||||||
|
bool const isGif = sharp::IsGif(baton->fileOut);
|
||||||
bool const isTiff = sharp::IsTiff(baton->fileOut);
|
bool const isTiff = sharp::IsTiff(baton->fileOut);
|
||||||
bool const isHeif = sharp::IsHeif(baton->fileOut);
|
bool const isHeif = sharp::IsHeif(baton->fileOut);
|
||||||
bool const isDz = sharp::IsDz(baton->fileOut);
|
bool const isDz = sharp::IsDz(baton->fileOut);
|
||||||
bool const isDzZip = sharp::IsDzZip(baton->fileOut);
|
bool const isDzZip = sharp::IsDzZip(baton->fileOut);
|
||||||
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 && !(isJpeg || isPng || isWebp || isTiff || isDz || isDzZip || isV);
|
bool const willMatchInput = mightMatchInput &&
|
||||||
|
!(isJpeg || isPng || isWebp || isGif || isTiff || 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)) {
|
||||||
// Write JPEG to file
|
// Write JPEG to file
|
||||||
@@ -841,7 +883,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
->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("no_subsample", baton->jpegChromaSubsampling == "4:4:4")
|
->set("subsample_mode", baton->jpegChromaSubsampling == "4:4:4"
|
||||||
|
? VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF
|
||||||
|
: VIPS_FOREIGN_JPEG_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)
|
||||||
@@ -850,8 +894,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
baton->formatOut = "jpeg";
|
baton->formatOut = "jpeg";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
} else if (baton->formatOut == "png" || (mightMatchInput && isPng) || (willMatchInput &&
|
} else if (baton->formatOut == "png" || (mightMatchInput && isPng) || (willMatchInput &&
|
||||||
(inputImageType == sharp::ImageType::PNG || inputImageType == sharp::ImageType::GIF ||
|
(inputImageType == sharp::ImageType::PNG || (inputImageType == sharp::ImageType::GIF && !supportsGifOutput) ||
|
||||||
inputImageType == sharp::ImageType::SVG))) {
|
inputImageType == sharp::ImageType::SVG))) {
|
||||||
// Write PNG to file
|
// Write PNG to file
|
||||||
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::PNG);
|
||||||
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
@@ -877,6 +921,16 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
->set("reduction_effort", baton->webpReductionEffort)
|
->set("reduction_effort", baton->webpReductionEffort)
|
||||||
->set("alpha_q", baton->webpAlphaQuality));
|
->set("alpha_q", baton->webpAlphaQuality));
|
||||||
baton->formatOut = "webp";
|
baton->formatOut = "webp";
|
||||||
|
} else if (baton->formatOut == "gif" || (mightMatchInput && isGif) ||
|
||||||
|
(willMatchInput && inputImageType == sharp::ImageType::GIF && supportsGifOutput)) {
|
||||||
|
// Write GIF to file
|
||||||
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::GIF);
|
||||||
|
image.magicksave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
|
->set("strip", !baton->withMetadata)
|
||||||
|
->set("optimize_gif_frames", TRUE)
|
||||||
|
->set("optimize_gif_transparency", TRUE)
|
||||||
|
->set("format", "gif"));
|
||||||
|
baton->formatOut = "gif";
|
||||||
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
||||||
(willMatchInput && inputImageType == sharp::ImageType::TIFF)) {
|
(willMatchInput && inputImageType == sharp::ImageType::TIFF)) {
|
||||||
// Write TIFF to file
|
// Write TIFF to file
|
||||||
@@ -887,7 +941,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
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)
|
||||||
->set("squash", baton->tiffSquash)
|
->set("bitdepth", baton->tiffBitdepth)
|
||||||
->set("compression", baton->tiffCompression)
|
->set("compression", baton->tiffCompression)
|
||||||
->set("predictor", baton->tiffPredictor)
|
->set("predictor", baton->tiffPredictor)
|
||||||
->set("pyramid", baton->tiffPyramid)
|
->set("pyramid", baton->tiffPyramid)
|
||||||
@@ -936,7 +990,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::vector<std::pair<std::string, std::string>> options {
|
std::vector<std::pair<std::string, std::string>> options {
|
||||||
{"Q", std::to_string(baton->jpegQuality)},
|
{"Q", std::to_string(baton->jpegQuality)},
|
||||||
{"interlace", baton->jpegProgressive ? "TRUE" : "FALSE"},
|
{"interlace", baton->jpegProgressive ? "TRUE" : "FALSE"},
|
||||||
{"no_subsample", baton->jpegChromaSubsampling == "4:4:4" ? "TRUE": "FALSE"},
|
{"subsample_mode", baton->jpegChromaSubsampling == "4:4:4" ? "off" : "on"},
|
||||||
{"trellis_quant", baton->jpegTrellisQuantisation ? "TRUE" : "FALSE"},
|
{"trellis_quant", baton->jpegTrellisQuantisation ? "TRUE" : "FALSE"},
|
||||||
{"quant_table", std::to_string(baton->jpegQuantisationTable)},
|
{"quant_table", std::to_string(baton->jpegQuantisationTable)},
|
||||||
{"overshoot_deringing", baton->jpegOvershootDeringing ? "TRUE": "FALSE"},
|
{"overshoot_deringing", baton->jpegOvershootDeringing ? "TRUE": "FALSE"},
|
||||||
@@ -1278,6 +1332,7 @@ 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->withMetadataIcc = sharp::AttrAsStr(options, "withMetadataIcc");
|
||||||
// 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");
|
||||||
@@ -1302,7 +1357,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->webpReductionEffort = sharp::AttrAsUint32(options, "webpReductionEffort");
|
baton->webpReductionEffort = sharp::AttrAsUint32(options, "webpReductionEffort");
|
||||||
baton->tiffQuality = sharp::AttrAsUint32(options, "tiffQuality");
|
baton->tiffQuality = sharp::AttrAsUint32(options, "tiffQuality");
|
||||||
baton->tiffPyramid = sharp::AttrAsBool(options, "tiffPyramid");
|
baton->tiffPyramid = sharp::AttrAsBool(options, "tiffPyramid");
|
||||||
baton->tiffSquash = sharp::AttrAsBool(options, "tiffSquash");
|
baton->tiffBitdepth = sharp::AttrAsUint32(options, "tiffBitdepth");
|
||||||
baton->tiffTile = sharp::AttrAsBool(options, "tiffTile");
|
baton->tiffTile = sharp::AttrAsBool(options, "tiffTile");
|
||||||
baton->tiffTileWidth = sharp::AttrAsUint32(options, "tiffTileWidth");
|
baton->tiffTileWidth = sharp::AttrAsUint32(options, "tiffTileWidth");
|
||||||
baton->tiffTileHeight = sharp::AttrAsUint32(options, "tiffTileHeight");
|
baton->tiffTileHeight = sharp::AttrAsUint32(options, "tiffTileHeight");
|
||||||
@@ -1320,6 +1375,18 @@ 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()));
|
||||||
|
|
||||||
|
// Animated output
|
||||||
|
if (sharp::HasAttr(options, "pageHeight")) {
|
||||||
|
baton->pageHeight = sharp::AttrAsUint32(options, "pageHeight");
|
||||||
|
}
|
||||||
|
if (sharp::HasAttr(options, "loop")) {
|
||||||
|
baton->loop = sharp::AttrAsUint32(options, "loop");
|
||||||
|
}
|
||||||
|
if (sharp::HasAttr(options, "delay")) {
|
||||||
|
baton->delay = sharp::AttrAsInt32Vector(options, "delay");
|
||||||
|
}
|
||||||
|
|
||||||
// Tile output
|
// Tile output
|
||||||
baton->tileSize = sharp::AttrAsUint32(options, "tileSize");
|
baton->tileSize = sharp::AttrAsUint32(options, "tileSize");
|
||||||
baton->tileOverlap = sharp::AttrAsUint32(options, "tileOverlap");
|
baton->tileOverlap = sharp::AttrAsUint32(options, "tileOverlap");
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ struct PipelineBaton {
|
|||||||
VipsForeignTiffCompression tiffCompression;
|
VipsForeignTiffCompression tiffCompression;
|
||||||
VipsForeignTiffPredictor tiffPredictor;
|
VipsForeignTiffPredictor tiffPredictor;
|
||||||
bool tiffPyramid;
|
bool tiffPyramid;
|
||||||
bool tiffSquash;
|
int tiffBitdepth;
|
||||||
bool tiffTile;
|
bool tiffTile;
|
||||||
int tiffTileHeight;
|
int tiffTileHeight;
|
||||||
int tiffTileWidth;
|
int tiffTileWidth;
|
||||||
@@ -155,6 +155,7 @@ struct PipelineBaton {
|
|||||||
std::string err;
|
std::string err;
|
||||||
bool withMetadata;
|
bool withMetadata;
|
||||||
int withMetadataOrientation;
|
int withMetadataOrientation;
|
||||||
|
std::string withMetadataIcc;
|
||||||
std::unique_ptr<double[]> convKernel;
|
std::unique_ptr<double[]> convKernel;
|
||||||
int convKernelWidth;
|
int convKernelWidth;
|
||||||
int convKernelHeight;
|
int convKernelHeight;
|
||||||
@@ -167,6 +168,9 @@ struct PipelineBaton {
|
|||||||
bool removeAlpha;
|
bool removeAlpha;
|
||||||
bool ensureAlpha;
|
bool ensureAlpha;
|
||||||
VipsInterpretation colourspace;
|
VipsInterpretation colourspace;
|
||||||
|
int pageHeight;
|
||||||
|
std::vector<int> delay;
|
||||||
|
int loop;
|
||||||
int tileSize;
|
int tileSize;
|
||||||
int tileOverlap;
|
int tileOverlap;
|
||||||
VipsForeignDzContainer tileContainer;
|
VipsForeignDzContainer tileContainer;
|
||||||
@@ -251,7 +255,7 @@ struct PipelineBaton {
|
|||||||
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
|
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
|
||||||
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
||||||
tiffPyramid(false),
|
tiffPyramid(false),
|
||||||
tiffSquash(false),
|
tiffBitdepth(8),
|
||||||
tiffTile(false),
|
tiffTile(false),
|
||||||
tiffTileHeight(256),
|
tiffTileHeight(256),
|
||||||
tiffTileWidth(256),
|
tiffTileWidth(256),
|
||||||
@@ -273,6 +277,9 @@ struct PipelineBaton {
|
|||||||
removeAlpha(false),
|
removeAlpha(false),
|
||||||
ensureAlpha(false),
|
ensureAlpha(false),
|
||||||
colourspace(VIPS_INTERPRETATION_LAST),
|
colourspace(VIPS_INTERPRETATION_LAST),
|
||||||
|
pageHeight(0),
|
||||||
|
delay{-1},
|
||||||
|
loop(-1),
|
||||||
tileSize(256),
|
tileSize(256),
|
||||||
tileOverlap(0),
|
tileOverlap(0),
|
||||||
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
||||||
|
|||||||
31
src/stats.cc
@@ -75,8 +75,31 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
baton->isOpaque = false;
|
baton->isOpaque = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Convert to greyscale
|
||||||
|
vips::VImage greyscale = image.colourspace(VIPS_INTERPRETATION_B_W)[0];
|
||||||
// Estimate entropy via histogram of greyscale value frequency
|
// Estimate entropy via histogram of greyscale value frequency
|
||||||
baton->entropy = std::abs(image.colourspace(VIPS_INTERPRETATION_B_W)[0].hist_find().hist_entropy());
|
baton->entropy = std::abs(greyscale.hist_find().hist_entropy());
|
||||||
|
// Estimate sharpness via standard deviation of greyscale laplacian
|
||||||
|
if (image.width() > 1 || image.height() > 1) {
|
||||||
|
VImage laplacian = VImage::new_matrixv(3, 3,
|
||||||
|
0.0, 1.0, 0.0,
|
||||||
|
1.0, -4.0, 1.0,
|
||||||
|
0.0, 1.0, 0.0);
|
||||||
|
laplacian.set("scale", 9.0);
|
||||||
|
baton->sharpness = greyscale.conv(laplacian).deviate();
|
||||||
|
}
|
||||||
|
// Most dominant sRGB colour via 4096-bin 3D histogram
|
||||||
|
vips::VImage hist = sharp::RemoveAlpha(image)
|
||||||
|
.colourspace(VIPS_INTERPRETATION_sRGB)
|
||||||
|
.hist_find_ndim(VImage::option()->set("bins", 16));
|
||||||
|
std::complex<double> maxpos = hist.maxpos();
|
||||||
|
int const dx = static_cast<int>(std::real(maxpos));
|
||||||
|
int const dy = static_cast<int>(std::imag(maxpos));
|
||||||
|
std::vector<double> pel = hist(dx, dy);
|
||||||
|
int const dz = std::distance(pel.begin(), std::find(pel.begin(), pel.end(), hist.max()));
|
||||||
|
baton->dominantRed = dx * 16 + 8;
|
||||||
|
baton->dominantGreen = dy * 16 + 8;
|
||||||
|
baton->dominantBlue = dz * 16 + 8;
|
||||||
} catch (vips::VError const &err) {
|
} catch (vips::VError const &err) {
|
||||||
(baton->err).append(err.what());
|
(baton->err).append(err.what());
|
||||||
}
|
}
|
||||||
@@ -123,6 +146,12 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
info.Set("channels", channels);
|
info.Set("channels", channels);
|
||||||
info.Set("isOpaque", baton->isOpaque);
|
info.Set("isOpaque", baton->isOpaque);
|
||||||
info.Set("entropy", baton->entropy);
|
info.Set("entropy", baton->entropy);
|
||||||
|
info.Set("sharpness", baton->sharpness);
|
||||||
|
Napi::Object dominant = Napi::Object::New(env);
|
||||||
|
dominant.Set("r", baton->dominantRed);
|
||||||
|
dominant.Set("g", baton->dominantGreen);
|
||||||
|
dominant.Set("b", baton->dominantBlue);
|
||||||
|
info.Set("dominant", dominant);
|
||||||
Callback().MakeCallback(Receiver().Value(), { env.Null(), info });
|
Callback().MakeCallback(Receiver().Value(), { env.Null(), info });
|
||||||
} else {
|
} else {
|
||||||
Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, baton->err).Value() });
|
Callback().MakeCallback(Receiver().Value(), { Napi::Error::New(env, baton->err).Value() });
|
||||||
|
|||||||
10
src/stats.h
@@ -47,13 +47,21 @@ struct StatsBaton {
|
|||||||
std::vector<ChannelStats> channelStats;
|
std::vector<ChannelStats> channelStats;
|
||||||
bool isOpaque;
|
bool isOpaque;
|
||||||
double entropy;
|
double entropy;
|
||||||
|
double sharpness;
|
||||||
|
int dominantRed;
|
||||||
|
int dominantGreen;
|
||||||
|
int dominantBlue;
|
||||||
|
|
||||||
std::string err;
|
std::string err;
|
||||||
|
|
||||||
StatsBaton():
|
StatsBaton():
|
||||||
input(nullptr),
|
input(nullptr),
|
||||||
isOpaque(true),
|
isOpaque(true),
|
||||||
entropy(0.0)
|
entropy(0.0),
|
||||||
|
sharpness(0.0),
|
||||||
|
dominantRed(0),
|
||||||
|
dominantGreen(0),
|
||||||
|
dominantBlue(0)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,12 @@
|
|||||||
"benchmark": "^2.1.4",
|
"benchmark": "^2.1.4",
|
||||||
"gm": "^1.23.1",
|
"gm": "^1.23.1",
|
||||||
"imagemagick": "^0.1.3",
|
"imagemagick": "^0.1.3",
|
||||||
"jimp": "^0.9.3",
|
"jimp": "^0.16.0",
|
||||||
"mapnik": "^4.3.1",
|
"mapnik": "^4.5.2",
|
||||||
"semver": "^7.1.1"
|
"semver": "^7.1.1"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.5.0"
|
"node": ">=10.16.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -564,8 +564,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 +577,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,12 +592,14 @@ 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)
|
||||||
|
.deflateLevel(6)
|
||||||
|
.filterType(0)
|
||||||
.write(fixtures.outputPng, function (err) {
|
.write(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -610,7 +615,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;
|
||||||
@@ -657,11 +662,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: fixtures.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,9 +684,11 @@ 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)
|
||||||
|
.define('PNG:compression-level=6')
|
||||||
|
.define('PNG:compression-filter=0')
|
||||||
.write(fixtures.outputPng, function (err) {
|
.write(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -689,9 +700,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,9 +718,11 @@ 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)
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
.toFile(fixtures.outputPng, function (err) {
|
.toFile(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -718,9 +733,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,9 +749,11 @@ 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)
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
.toFile(fixtures.outputPng, function (err) {
|
.toFile(fixtures.outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -745,9 +764,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 +780,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 +796,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;
|
||||||
|
|||||||
BIN
test/fixtures/animated-loop-3.webp
vendored
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
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/expected/circle.png
vendored
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
test/fixtures/expected/conv-sobel-horizontal.jpg
vendored
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 18 KiB |
BIN
test/fixtures/expected/extract-alpha-2-channel.png
vendored
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
test/fixtures/expected/extract.webp
vendored
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.8 KiB |
BIN
test/fixtures/expected/hilutite.jpg
vendored
Normal file
|
After Width: | Height: | Size: 1.0 MiB |
BIN
test/fixtures/expected/icc-cmyk.jpg
vendored
Normal file
|
After Width: | Height: | Size: 2.8 MiB |
BIN
test/fixtures/expected/tint-cmyk.jpg
vendored
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
BIN
test/fixtures/hilutite.icm
vendored
Normal file
4
test/fixtures/index.js
vendored
@@ -93,6 +93,9 @@ module.exports = {
|
|||||||
|
|
||||||
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
||||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||||
|
inputWebPAnimated: getPath('rotating-squares.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||||
|
inputWebPAnimatedLoop3: getPath('animated-loop-3.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||||
|
inputWebPAnimatedBigHeight: getPath('big-height.webp'),
|
||||||
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
||||||
inputTiffMultipage: getPath('G31D_MULTI.TIF'), // gm convert G31D.TIF -resize 50% G31D_2.TIF ; tiffcp G31D.TIF G31D_2.TIF G31D_MULTI.TIF
|
inputTiffMultipage: getPath('G31D_MULTI.TIF'), // gm convert G31D.TIF -resize 50% G31D_2.TIF ; tiffcp G31D.TIF G31D_2.TIF G31D_MULTI.TIF
|
||||||
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
||||||
@@ -104,6 +107,7 @@ module.exports = {
|
|||||||
inputGifAnimated: getPath('rotating-squares.gif'), // CC0 https://loading.io/spinner/blocks/-rotating-squares-preloader-gif
|
inputGifAnimated: getPath('rotating-squares.gif'), // CC0 https://loading.io/spinner/blocks/-rotating-squares-preloader-gif
|
||||||
inputGifAnimatedLoop3: getPath('animated-loop-3.gif'), // CC-BY-SA-4.0 Petrus3743 https://commons.wikimedia.org/wiki/File:01-Goldener_Schnitt_Formel-Animation.gif
|
inputGifAnimatedLoop3: getPath('animated-loop-3.gif'), // CC-BY-SA-4.0 Petrus3743 https://commons.wikimedia.org/wiki/File:01-Goldener_Schnitt_Formel-Animation.gif
|
||||||
inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg
|
inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg
|
||||||
|
inputSvgSmallViewBox: getPath('circle.svg'),
|
||||||
inputSvgWithEmbeddedImages: getPath('struct-image-04-t.svg'), // https://dev.w3.org/SVG/profiles/1.2T/test/svg/struct-image-04-t.svg
|
inputSvgWithEmbeddedImages: getPath('struct-image-04-t.svg'), // https://dev.w3.org/SVG/profiles/1.2T/test/svg/struct-image-04-t.svg
|
||||||
|
|
||||||
inputJPGBig: getPath('flowers.jpeg'),
|
inputJPGBig: getPath('flowers.jpeg'),
|
||||||
|
|||||||
BIN
test/fixtures/rotating-squares.webp
vendored
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
@@ -39,6 +39,16 @@
|
|||||||
Memcheck:Cond
|
Memcheck:Cond
|
||||||
obj:*/libjpeg.so*
|
obj:*/libjpeg.so*
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
value_jpeg_obj_static
|
||||||
|
Memcheck:Value8
|
||||||
|
obj:*/libvips.so*
|
||||||
|
}
|
||||||
|
{
|
||||||
|
cond_jpeg_obj_static
|
||||||
|
Memcheck:Cond
|
||||||
|
obj:*/libvips.so*
|
||||||
|
}
|
||||||
{
|
{
|
||||||
param_jpeg_jpeg_finish_compress
|
param_jpeg_jpeg_finish_compress
|
||||||
Memcheck:Param
|
Memcheck:Param
|
||||||
@@ -304,6 +314,16 @@
|
|||||||
...
|
...
|
||||||
fun:vips__init
|
fun:vips__init
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
leak_rsvg_static_data
|
||||||
|
Memcheck:Leak
|
||||||
|
match-leak-kinds: definite
|
||||||
|
fun:malloc
|
||||||
|
...
|
||||||
|
fun:rsvg_rust_handle_new_from_stream_sync
|
||||||
|
...
|
||||||
|
fun:vips_object_build
|
||||||
|
}
|
||||||
|
|
||||||
# libuv warnings
|
# libuv warnings
|
||||||
{
|
{
|
||||||
@@ -418,6 +438,13 @@
|
|||||||
...
|
...
|
||||||
fun:_ZN4node17CreateEnvironmentEPN2v87IsolateEP9uv_loop_sNS0_5LocalINS0_7ContextEEEiPKPKciSB_
|
fun:_ZN4node17CreateEnvironmentEPN2v87IsolateEP9uv_loop_sNS0_5LocalINS0_7ContextEEEiPKPKciSB_
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
leak_nodejs_CreateEnvironment_IsolateData
|
||||||
|
Memcheck:Leak
|
||||||
|
match-leak-kinds: possible
|
||||||
|
...
|
||||||
|
fun:_ZN4node17CreateEnvironmentEPNS_11IsolateDataEN2v85LocalINS2_7ContextEEERKSt6vectorISsSaISsEESA_NS_16EnvironmentFlags5FlagsENS_8ThreadIdESt10unique_ptrINS_21InspectorParentHandleESt14default_deleteISF_EE
|
||||||
|
}
|
||||||
{
|
{
|
||||||
leak_nodejs_Environment_Start
|
leak_nodejs_Environment_Start
|
||||||
Memcheck:Leak
|
Memcheck:Leak
|
||||||
|
|||||||
@@ -80,6 +80,19 @@ describe('Image channel extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Alpha from 2-channel input', function (done) {
|
||||||
|
const output = fixtures.path('output.extract-alpha-2-channel.png');
|
||||||
|
sharp(fixtures.inputPngWithGreyAlpha)
|
||||||
|
.extractChannel('alpha')
|
||||||
|
.toColourspace('b-w')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(1, info.channels);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-alpha-2-channel.png'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Invalid channel number', function () {
|
it('Invalid channel number', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
|
|||||||
@@ -19,11 +19,17 @@ describe('failOnError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles truncated PNG', function (done) {
|
it('handles truncated PNG, emits warnings', function (done) {
|
||||||
|
let isWarningEmitted = false;
|
||||||
sharp(fixtures.inputPngTruncated, { failOnError: false })
|
sharp(fixtures.inputPngTruncated, { failOnError: false })
|
||||||
|
.on('warning', function (warning) {
|
||||||
|
assert.ok(warning.includes('not enough data') || warning.includes('end of stream'));
|
||||||
|
isWarningEmitted = true;
|
||||||
|
})
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, isWarningEmitted);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
@@ -56,7 +62,7 @@ describe('failOnError', function () {
|
|||||||
|
|
||||||
it('returns errors to callback for truncated PNG', function (done) {
|
it('returns errors to callback for truncated PNG', function (done) {
|
||||||
sharp(fixtures.inputPngTruncated).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputPngTruncated).toBuffer(function (err, data, info) {
|
||||||
assert.ok(err.message.includes('vipspng: libpng read error'), err);
|
assert.ok(err.message.includes('read error'), err);
|
||||||
assert.strictEqual(data, undefined);
|
assert.strictEqual(data, undefined);
|
||||||
assert.strictEqual(info, undefined);
|
assert.strictEqual(info, undefined);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ describe('GIF input', () => {
|
|||||||
.then(({ data, info }) => {
|
.then(({ data, info }) => {
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual(sharp.format.magick.input.buffer ? 'gif' : 'png', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
@@ -55,10 +55,79 @@ describe('GIF input', () => {
|
|||||||
.then(({ data, info }) => {
|
.then(({ data, info }) => {
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual(sharp.format.magick.input.buffer ? 'gif' : 'png', info.format);
|
||||||
assert.strictEqual(80, info.width);
|
assert.strictEqual(80, info.width);
|
||||||
assert.strictEqual(2400, info.height);
|
assert.strictEqual(2400, info.height);
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!sharp.format.magick.output.buffer) {
|
||||||
|
it('GIF output should fail due to missing ImageMagick', () => {
|
||||||
|
assert.throws(
|
||||||
|
() => {
|
||||||
|
sharp().gif();
|
||||||
|
},
|
||||||
|
/The gif operation requires libvips to have been installed with support for ImageMagick/
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('invalid pageHeight throws', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().gif({ pageHeight: 0 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid loop throws', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().gif({ loop: -1 });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().gif({ loop: 65536 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid delay throws', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().gif({ delay: [-1] });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().gif({ delay: [65536] });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with streams when only animated is set', function (done) {
|
||||||
|
if (sharp.format.magick.output.buffer) {
|
||||||
|
fs.createReadStream(fixtures.inputGifAnimated)
|
||||||
|
.pipe(sharp({ animated: true }))
|
||||||
|
.gif()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('gif', info.format);
|
||||||
|
fixtures.assertSimilar(fixtures.inputGifAnimated, data, done);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with streams when only pages is set', function (done) {
|
||||||
|
if (sharp.format.magick.output.buffer) {
|
||||||
|
fs.createReadStream(fixtures.inputGifAnimated)
|
||||||
|
.pipe(sharp({ pages: -1 }))
|
||||||
|
.gif()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('gif', info.format);
|
||||||
|
fixtures.assertSimilar(fixtures.inputGifAnimated, data, done);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Fail when input is empty Buffer', function (done) {
|
it('Fail when input is empty Buffer', function (done) {
|
||||||
if (process.platform === 'freebsd') return this.skip(); // can be removed with libvips 8.10.0+
|
if (sharp.format.magick.input.buffer) return this.skip(); // can be removed with libvips 8.10.1+
|
||||||
sharp(Buffer.alloc(0)).toBuffer().then(function () {
|
sharp(Buffer.alloc(0)).toBuffer().then(function () {
|
||||||
assert(false);
|
assert(false);
|
||||||
done();
|
done();
|
||||||
@@ -470,7 +470,7 @@ describe('Input/output', function () {
|
|||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(fixtures.outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual(sharp.format.magick.input.buffer ? 'gif' : 'png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(fixtures.outputZoinks, done);
|
||||||
@@ -647,7 +647,16 @@ describe('Input/output', function () {
|
|||||||
it('Invalid density: string', function () {
|
it('Invalid density: string', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp({ density: 'zoinks' });
|
sharp({ density: 'zoinks' });
|
||||||
}, /Expected number between 1 and 2400 for density but received zoinks of type string/);
|
}, /Expected number between 1 and 100000 for density but received zoinks of type string/);
|
||||||
|
});
|
||||||
|
it('Setting animated property updates pages property', function () {
|
||||||
|
assert.strictEqual(sharp({ animated: false }).options.input.pages, 1);
|
||||||
|
assert.strictEqual(sharp({ animated: true }).options.input.pages, -1);
|
||||||
|
});
|
||||||
|
it('Invalid animated property throws', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp({ animated: -1 });
|
||||||
|
}, /Expected boolean for animated but received -1 of type number/);
|
||||||
});
|
});
|
||||||
it('Invalid page property throws', function () {
|
it('Invalid page property throws', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
@@ -659,6 +668,19 @@ describe('Input/output', function () {
|
|||||||
sharp({ pages: '1' });
|
sharp({ pages: '1' });
|
||||||
}, /Expected integer between -1 and 100000 for pages but received 1 of type string/);
|
}, /Expected integer between -1 and 100000 for pages but received 1 of type string/);
|
||||||
});
|
});
|
||||||
|
it('Valid level property', function () {
|
||||||
|
sharp({ level: 1 });
|
||||||
|
});
|
||||||
|
it('Invalid level property (string) throws', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp({ level: '1' });
|
||||||
|
}, /Expected integer between 0 and 256 for level but received 1 of type string/);
|
||||||
|
});
|
||||||
|
it('Invalid level property (negative) throws', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp({ level: -1 });
|
||||||
|
}, /Expected integer between 0 and 256 for level but received -1 of type number/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create new image', function () {
|
describe('create new image', function () {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual('srgb', metadata.space);
|
assert.strictEqual('srgb', metadata.space);
|
||||||
assert.strictEqual(3, metadata.channels);
|
assert.strictEqual(3, metadata.channels);
|
||||||
assert.strictEqual('uchar', metadata.depth);
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
assert.strictEqual('undefined', typeof metadata.density);
|
assert.strictEqual(true, ['undefined', 'number'].includes(typeof metadata.density));
|
||||||
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
||||||
assert.strictEqual(false, metadata.isProgressive);
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
@@ -192,6 +192,54 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Animated WebP', () =>
|
||||||
|
sharp(fixtures.inputWebPAnimated)
|
||||||
|
.metadata()
|
||||||
|
.then(({
|
||||||
|
format, width, height, space, channels, depth,
|
||||||
|
isProgressive, pages, pageHeight, loop, delay,
|
||||||
|
hasProfile, hasAlpha
|
||||||
|
}) => {
|
||||||
|
assert.strictEqual(format, 'webp');
|
||||||
|
assert.strictEqual(width, 80);
|
||||||
|
assert.strictEqual(height, 80);
|
||||||
|
assert.strictEqual(space, 'srgb');
|
||||||
|
assert.strictEqual(channels, 4);
|
||||||
|
assert.strictEqual(depth, 'uchar');
|
||||||
|
assert.strictEqual(isProgressive, false);
|
||||||
|
assert.strictEqual(pages, 9);
|
||||||
|
assert.strictEqual(pageHeight, 80);
|
||||||
|
assert.strictEqual(loop, 0);
|
||||||
|
assert.deepStrictEqual(delay, [120, 120, 90, 120, 120, 90, 120, 90, 30]);
|
||||||
|
assert.strictEqual(hasProfile, false);
|
||||||
|
assert.strictEqual(hasAlpha, true);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
it('Animated WebP with limited looping', () =>
|
||||||
|
sharp(fixtures.inputWebPAnimatedLoop3)
|
||||||
|
.metadata()
|
||||||
|
.then(({
|
||||||
|
format, width, height, space, channels, depth,
|
||||||
|
isProgressive, pages, pageHeight, loop, delay,
|
||||||
|
hasProfile, hasAlpha
|
||||||
|
}) => {
|
||||||
|
assert.strictEqual(format, 'webp');
|
||||||
|
assert.strictEqual(width, 370);
|
||||||
|
assert.strictEqual(height, 285);
|
||||||
|
assert.strictEqual(space, 'srgb');
|
||||||
|
assert.strictEqual(channels, 4);
|
||||||
|
assert.strictEqual(depth, 'uchar');
|
||||||
|
assert.strictEqual(isProgressive, false);
|
||||||
|
assert.strictEqual(pages, 10);
|
||||||
|
assert.strictEqual(pageHeight, 285);
|
||||||
|
assert.strictEqual(loop, 3);
|
||||||
|
assert.deepStrictEqual(delay, [...Array(9).fill(3000), 15000]);
|
||||||
|
assert.strictEqual(hasProfile, false);
|
||||||
|
assert.strictEqual(hasAlpha, true);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
it('GIF via giflib', function (done) {
|
it('GIF via giflib', function (done) {
|
||||||
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
sharp(fixtures.inputGif).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -311,7 +359,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual('srgb', metadata.space);
|
assert.strictEqual('srgb', metadata.space);
|
||||||
assert.strictEqual(3, metadata.channels);
|
assert.strictEqual(3, metadata.channels);
|
||||||
assert.strictEqual('uchar', metadata.depth);
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
assert.strictEqual('undefined', typeof metadata.density);
|
assert.strictEqual(true, ['undefined', 'number'].includes(typeof metadata.density));
|
||||||
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
||||||
assert.strictEqual(false, metadata.isProgressive);
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
@@ -343,7 +391,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual('srgb', metadata.space);
|
assert.strictEqual('srgb', metadata.space);
|
||||||
assert.strictEqual(3, metadata.channels);
|
assert.strictEqual(3, metadata.channels);
|
||||||
assert.strictEqual('uchar', metadata.depth);
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
assert.strictEqual('undefined', typeof metadata.density);
|
assert.strictEqual(true, ['undefined', 'number'].includes(typeof metadata.density));
|
||||||
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
||||||
assert.strictEqual(false, metadata.isProgressive);
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
@@ -381,7 +429,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual('srgb', metadata.space);
|
assert.strictEqual('srgb', metadata.space);
|
||||||
assert.strictEqual(3, metadata.channels);
|
assert.strictEqual(3, metadata.channels);
|
||||||
assert.strictEqual('uchar', metadata.depth);
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
assert.strictEqual('undefined', typeof metadata.density);
|
assert.strictEqual(true, ['undefined', 'number'].includes(typeof metadata.density));
|
||||||
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
||||||
assert.strictEqual(false, metadata.isProgressive);
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
@@ -405,7 +453,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual('srgb', metadata.space);
|
assert.strictEqual('srgb', metadata.space);
|
||||||
assert.strictEqual(3, metadata.channels);
|
assert.strictEqual(3, metadata.channels);
|
||||||
assert.strictEqual('uchar', metadata.depth);
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
assert.strictEqual('undefined', typeof metadata.density);
|
assert.strictEqual(true, ['undefined', 'number'].includes(typeof metadata.density));
|
||||||
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
assert.strictEqual('4:2:0', metadata.chromaSubsampling);
|
||||||
assert.strictEqual(false, metadata.isProgressive);
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
assert.strictEqual(false, metadata.hasProfile);
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
@@ -453,6 +501,42 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Apply CMYK output ICC profile', function (done) {
|
||||||
|
const output = fixtures.path('output.icc-cmyk.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.withMetadata({ icc: 'cmyk' })
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
sharp(output).metadata(function (err, metadata) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, metadata.hasProfile);
|
||||||
|
assert.strictEqual('cmyk', metadata.space);
|
||||||
|
assert.strictEqual(4, metadata.channels);
|
||||||
|
// ICC
|
||||||
|
assert.strictEqual('object', typeof metadata.icc);
|
||||||
|
assert.strictEqual(true, metadata.icc instanceof Buffer);
|
||||||
|
const profile = icc.parse(metadata.icc);
|
||||||
|
assert.strictEqual('object', typeof profile);
|
||||||
|
assert.strictEqual('CMYK', profile.colorSpace);
|
||||||
|
assert.strictEqual('Relative', profile.intent);
|
||||||
|
assert.strictEqual('Printer', profile.deviceClass);
|
||||||
|
});
|
||||||
|
fixtures.assertSimilar(output, fixtures.path('expected/icc-cmyk.jpg'), { threshold: 0 }, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Apply custom output ICC profile', function (done) {
|
||||||
|
const output = fixtures.path('output.hilutite.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.withMetadata({ icc: fixtures.path('hilutite.icm') })
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.path('expected/hilutite.jpg'), 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.inputJpg, 16.5);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Include metadata in output, enabled via empty object', () =>
|
it('Include metadata in output, enabled via empty object', () =>
|
||||||
sharp(fixtures.inputJpgWithExif)
|
sharp(fixtures.inputJpgWithExif)
|
||||||
.withMetadata({})
|
.withMetadata({})
|
||||||
@@ -627,5 +711,10 @@ describe('Image metadata', function () {
|
|||||||
sharp().withMetadata({ orientation: 9 });
|
sharp().withMetadata({ orientation: 9 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('Non string icc', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp().withMetadata({ icc: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,4 +55,12 @@ describe('Platform-detection', function () {
|
|||||||
assert.strictEqual('arm64v8', platform().split('-')[1]);
|
assert.strictEqual('arm64v8', platform().split('-')[1]);
|
||||||
delete process.env.npm_config_arch;
|
delete process.env.npm_config_arch;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Can ensure version ARMv7 if electron version is present', function () {
|
||||||
|
process.env.npm_config_arch = 'arm';
|
||||||
|
process.versions.electron = 'test';
|
||||||
|
assert.strictEqual('armv7', platform().split('-')[1]);
|
||||||
|
delete process.env.npm_config_arch;
|
||||||
|
delete process.versions.electron;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ describe('PNG', function () {
|
|||||||
it('Valid PNG libimagequant quality value produces image of same size or smaller', function () {
|
it('Valid PNG libimagequant quality value produces image of same size or smaller', function () {
|
||||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
sharp(inputPngBuffer).resize(10).png({ palette: true, quality: 80 }).toBuffer(),
|
sharp(inputPngBuffer).resize(10).png({ quality: 80 }).toBuffer(),
|
||||||
sharp(inputPngBuffer).resize(10).png({ palette: true, quality: 100 }).toBuffer()
|
sharp(inputPngBuffer).resize(10).png({ quality: 100 }).toBuffer()
|
||||||
]).then(function (data) {
|
]).then(function (data) {
|
||||||
assert.strictEqual(true, data[0].length <= data[1].length);
|
assert.strictEqual(true, data[0].length <= data[1].length);
|
||||||
});
|
});
|
||||||
@@ -136,15 +136,15 @@ describe('PNG', function () {
|
|||||||
|
|
||||||
it('Invalid PNG libimagequant quality value throws error', function () {
|
it('Invalid PNG libimagequant quality value throws error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().png({ palette: true, quality: 101 });
|
sharp().png({ quality: 101 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Valid PNG libimagequant colours value produces image of same size or smaller', function () {
|
it('Valid PNG libimagequant colours value produces image of same size or smaller', function () {
|
||||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
sharp(inputPngBuffer).resize(10).png({ palette: true, colours: 100 }).toBuffer(),
|
sharp(inputPngBuffer).resize(10).png({ colours: 100 }).toBuffer(),
|
||||||
sharp(inputPngBuffer).resize(10).png({ palette: true, colours: 200 }).toBuffer()
|
sharp(inputPngBuffer).resize(10).png({ colours: 200 }).toBuffer()
|
||||||
]).then(function (data) {
|
]).then(function (data) {
|
||||||
assert.strictEqual(true, data[0].length <= data[1].length);
|
assert.strictEqual(true, data[0].length <= data[1].length);
|
||||||
});
|
});
|
||||||
@@ -152,21 +152,21 @@ describe('PNG', function () {
|
|||||||
|
|
||||||
it('Invalid PNG libimagequant colours value throws error', function () {
|
it('Invalid PNG libimagequant colours value throws error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().png({ palette: true, colours: -1 });
|
sharp().png({ colours: -1 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid PNG libimagequant colors value throws error', function () {
|
it('Invalid PNG libimagequant colors value throws error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().png({ palette: true, colors: 0.1 });
|
sharp().png({ colors: 0.1 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Valid PNG libimagequant dither value produces image of same size or smaller', function () {
|
it('Valid PNG libimagequant dither value produces image of same size or smaller', function () {
|
||||||
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
const inputPngBuffer = fs.readFileSync(fixtures.inputPng);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
sharp(inputPngBuffer).resize(10).png({ palette: true, dither: 0.1 }).toBuffer(),
|
sharp(inputPngBuffer).resize(10).png({ dither: 0.1 }).toBuffer(),
|
||||||
sharp(inputPngBuffer).resize(10).png({ palette: true, dither: 0.9 }).toBuffer()
|
sharp(inputPngBuffer).resize(10).png({ dither: 0.9 }).toBuffer()
|
||||||
]).then(function (data) {
|
]).then(function (data) {
|
||||||
assert.strictEqual(true, data[0].length <= data[1].length);
|
assert.strictEqual(true, data[0].length <= data[1].length);
|
||||||
});
|
});
|
||||||
@@ -174,7 +174,7 @@ describe('PNG', function () {
|
|||||||
|
|
||||||
it('Invalid PNG libimagequant dither value throws error', function () {
|
it('Invalid PNG libimagequant dither value throws error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().png({ palette: true, dither: 'fail' });
|
sharp().png({ dither: 'fail' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.7883011147075762));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(40, r);
|
||||||
|
assert.strictEqual(40, g);
|
||||||
|
assert.strictEqual(40, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -84,6 +90,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.3409031108021736));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.3409031108021736));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 9.111356137722868));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(248, r);
|
||||||
|
assert.strictEqual(248, g);
|
||||||
|
assert.strictEqual(248, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -110,6 +122,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(false, stats.isOpaque);
|
assert.strictEqual(false, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.06778064835816622));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.06778064835816622));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 2.522916068931278));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(248, r);
|
||||||
|
assert.strictEqual(248, g);
|
||||||
|
assert.strictEqual(248, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -185,6 +203,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(false, stats.isOpaque);
|
assert.strictEqual(false, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(72, r);
|
||||||
|
assert.strictEqual(104, g);
|
||||||
|
assert.strictEqual(72, b);
|
||||||
|
|
||||||
// alpha channel
|
// alpha channel
|
||||||
assert.strictEqual(0, stats.channels[3].min);
|
assert.strictEqual(0, stats.channels[3].min);
|
||||||
@@ -212,6 +236,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.3851250782608986));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.3851250782608986));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 10.312521863719589));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(248, r);
|
||||||
|
assert.strictEqual(248, g);
|
||||||
|
assert.strictEqual(248, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -239,6 +269,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.51758075132966));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.51758075132966));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 9.959951636662941));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(40, r);
|
||||||
|
assert.strictEqual(136, g);
|
||||||
|
assert.strictEqual(200, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -298,6 +334,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 6.087309412541799));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 6.087309412541799));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 2.9250574456255682));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(120, r);
|
||||||
|
assert.strictEqual(136, g);
|
||||||
|
assert.strictEqual(88, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(35, stats.channels[0].min);
|
assert.strictEqual(35, stats.channels[0].min);
|
||||||
@@ -357,6 +399,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(false, stats.isOpaque);
|
assert.strictEqual(false, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 1));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 1));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 15.870619016486861));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(8, r);
|
||||||
|
assert.strictEqual(8, g);
|
||||||
|
assert.strictEqual(8, b);
|
||||||
|
|
||||||
// gray channel
|
// gray channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -403,6 +451,30 @@ describe('Image Stats', function () {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('Dominant colour', () =>
|
||||||
|
sharp(fixtures.inputJpgBooleanTest)
|
||||||
|
.stats()
|
||||||
|
.then(({ dominant }) => {
|
||||||
|
const { r, g, b } = dominant;
|
||||||
|
assert.strictEqual(r, 8);
|
||||||
|
assert.strictEqual(g, 136);
|
||||||
|
assert.strictEqual(b, 248);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
it('Entropy and sharpness of 1x1 input are zero', async () => {
|
||||||
|
const { entropy, sharpness } = await sharp({
|
||||||
|
create: {
|
||||||
|
width: 1,
|
||||||
|
height: 1,
|
||||||
|
channels: 3,
|
||||||
|
background: 'red'
|
||||||
|
}
|
||||||
|
}).stats();
|
||||||
|
assert.strictEqual(entropy, 0);
|
||||||
|
assert.strictEqual(sharpness, 0);
|
||||||
|
});
|
||||||
|
|
||||||
it('Stream in, Callback out', function (done) {
|
it('Stream in, Callback out', function (done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().stats(function (err, stats) {
|
const pipeline = sharp().stats(function (err, stats) {
|
||||||
@@ -410,6 +482,12 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(40, r);
|
||||||
|
assert.strictEqual(40, g);
|
||||||
|
assert.strictEqual(40, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -472,6 +550,12 @@ describe('Image Stats', function () {
|
|||||||
return pipeline.stats().then(function (stats) {
|
return pipeline.stats().then(function (stats) {
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(40, r);
|
||||||
|
assert.strictEqual(40, g);
|
||||||
|
assert.strictEqual(40, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -529,6 +613,12 @@ describe('Image Stats', function () {
|
|||||||
return sharp(fixtures.inputJpg).stats().then(function (stats) {
|
return sharp(fixtures.inputJpg).stats().then(function (stats) {
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||||
|
|
||||||
|
const { r, g, b } = stats.dominant;
|
||||||
|
assert.strictEqual(40, r);
|
||||||
|
assert.strictEqual(40, g);
|
||||||
|
assert.strictEqual(40, b);
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0].min);
|
assert.strictEqual(0, stats.channels[0].min);
|
||||||
@@ -582,6 +672,18 @@ describe('Image Stats', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Blurred image has lower sharpness than original', () => {
|
||||||
|
const original = sharp(fixtures.inputJpg).stats();
|
||||||
|
const blurred = sharp(fixtures.inputJpg).blur().toBuffer().then(blur => sharp(blur).stats());
|
||||||
|
|
||||||
|
return Promise
|
||||||
|
.all([original, blurred])
|
||||||
|
.then(([original, blurred]) => {
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(original.sharpness, 0.7883011147075476));
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(blurred.sharpness, 0.4791559805997398));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('File input with corrupt header fails gracefully', function (done) {
|
it('File input with corrupt header fails gracefully', function (done) {
|
||||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||||
.stats(function (err) {
|
.stats(function (err) {
|
||||||
|
|||||||
@@ -48,6 +48,31 @@ describe('SVG input', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Convert SVG to PNG at DPI larger than 2400', function (done) {
|
||||||
|
const size = 1024;
|
||||||
|
sharp(fixtures.inputSvgSmallViewBox).metadata(function (err, metadata) {
|
||||||
|
if (err) throw err;
|
||||||
|
const density = (size / Math.max(metadata.width, metadata.height)) * metadata.density;
|
||||||
|
sharp(fixtures.inputSvgSmallViewBox, { density })
|
||||||
|
.resize(size)
|
||||||
|
.toFormat('png')
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('png', info.format);
|
||||||
|
assert.strictEqual(size, info.width);
|
||||||
|
assert.strictEqual(size, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('circle.png'), data, function (err) {
|
||||||
|
if (err) throw err;
|
||||||
|
sharp(data).metadata(function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(9216, info.density);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Convert SVG to PNG at 14.4DPI', function (done) {
|
it('Convert SVG to PNG at 14.4DPI', function (done) {
|
||||||
sharp(fixtures.inputSvg, { density: 14.4 })
|
sharp(fixtures.inputSvg, { density: 14.4 })
|
||||||
.toFormat('png')
|
.toFormat('png')
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ describe('TIFF', function () {
|
|||||||
sharp(fixtures.inputTiff8BitDepth)
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||||
.tiff({
|
.tiff({
|
||||||
squash: false,
|
bitdepth: 8,
|
||||||
compression: 'none',
|
compression: 'none',
|
||||||
predictor: 'none'
|
predictor: 'none'
|
||||||
})
|
})
|
||||||
@@ -133,7 +133,7 @@ describe('TIFF', function () {
|
|||||||
sharp(fixtures.inputTiff8BitDepth)
|
sharp(fixtures.inputTiff8BitDepth)
|
||||||
.toColourspace('b-w') // can only squash 1 band uchar images
|
.toColourspace('b-w') // can only squash 1 band uchar images
|
||||||
.tiff({
|
.tiff({
|
||||||
squash: true,
|
bitdepth: 1,
|
||||||
compression: 'none',
|
compression: 'none',
|
||||||
predictor: 'none'
|
predictor: 'none'
|
||||||
})
|
})
|
||||||
@@ -145,10 +145,10 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid TIFF squash value throws error', function () {
|
it('Invalid TIFF bitdepth value throws error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().tiff({ squash: 'true' });
|
sharp().tiff({ bitdepth: 3 });
|
||||||
});
|
}, /Error: Expected 1, 2, 4 or 8 for bitdepth but received 3 of type number/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF setting xres and yres on file', () =>
|
it('TIFF setting xres and yres on file', () =>
|
||||||
@@ -161,9 +161,7 @@ describe('TIFF', function () {
|
|||||||
.then(() => sharp(fixtures.outputTiff)
|
.then(() => sharp(fixtures.outputTiff)
|
||||||
.metadata()
|
.metadata()
|
||||||
.then(({ density }) => {
|
.then(({ density }) => {
|
||||||
assert.strictEqual(true,
|
assert.strictEqual(25400, density);
|
||||||
density === 2540 || // libvips <= 8.8.2
|
|
||||||
density === 25400); // libvips >= 8.8.3
|
|
||||||
return promisify(rimraf)(fixtures.outputTiff);
|
return promisify(rimraf)(fixtures.outputTiff);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -179,9 +177,7 @@ describe('TIFF', function () {
|
|||||||
.then(data => sharp(data)
|
.then(data => sharp(data)
|
||||||
.metadata()
|
.metadata()
|
||||||
.then(({ density }) => {
|
.then(({ density }) => {
|
||||||
assert.strictEqual(true,
|
assert.strictEqual(25400, density);
|
||||||
density === 2540 || // libvips <= 8.8.2
|
|
||||||
density === 25400); // libvips >= 8.8.3
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -255,7 +251,7 @@ describe('TIFF', function () {
|
|||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.toColourspace('b-w')
|
.toColourspace('b-w')
|
||||||
.tiff({
|
.tiff({
|
||||||
squash: true,
|
bitdepth: 1,
|
||||||
compression: 'ccittfax4'
|
compression: 'ccittfax4'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(fixtures.outputTiff, (err, info) => {
|
||||||
|
|||||||
@@ -16,4 +16,12 @@ describe('toBuffer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('correctly process animated webp with height > 16383', (done) => {
|
||||||
|
const image = sharp(fixtures.inputWebPAnimatedBigHeight, { animated: true });
|
||||||
|
image.toBuffer().then((buff) => {
|
||||||
|
assert.strictEqual(Buffer.isBuffer(buff), true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@@ -125,4 +126,87 @@ describe('WebP', function () {
|
|||||||
sharp().webp({ reductionEffort: -1 });
|
sharp().webp({ reductionEffort: -1 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('invalid pageHeight throws', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().webp({ pageHeight: 0 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid loop throws', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().webp({ loop: -1 });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().webp({ loop: 65536 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalid delay throws', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().webp({ delay: [-1] });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
sharp().webp({ delay: [65536] });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should double the number of frames with default delay', async () => {
|
||||||
|
const original = await sharp(fixtures.inputWebPAnimated, { pages: -1 }).metadata();
|
||||||
|
const updated = await sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
|
.webp({ pageHeight: original.pageHeight / 2 })
|
||||||
|
.toBuffer()
|
||||||
|
.then(data => sharp(data, { pages: -1 }).metadata());
|
||||||
|
|
||||||
|
assert.strictEqual(updated.pages, original.pages * 2);
|
||||||
|
assert.strictEqual(updated.pageHeight, original.pageHeight / 2);
|
||||||
|
assert.deepStrictEqual(updated.delay, [...original.delay, ...Array(9).fill(120)]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should limit animation loop', async () => {
|
||||||
|
const updated = await sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
|
.webp({ loop: 3 })
|
||||||
|
.toBuffer()
|
||||||
|
.then(data => sharp(data, { pages: -1 }).metadata());
|
||||||
|
|
||||||
|
assert.strictEqual(updated.loop, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change delay between frames', async () => {
|
||||||
|
const original = await sharp(fixtures.inputWebPAnimated, { pages: -1 }).metadata();
|
||||||
|
|
||||||
|
const expectedDelay = [...Array(original.pages).fill(40)];
|
||||||
|
const updated = await sharp(fixtures.inputWebPAnimated, { pages: -1 })
|
||||||
|
.webp({ delay: expectedDelay })
|
||||||
|
.toBuffer()
|
||||||
|
.then(data => sharp(data, { pages: -1 }).metadata());
|
||||||
|
|
||||||
|
assert.deepStrictEqual(updated.delay, expectedDelay);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with streams when only animated is set', function (done) {
|
||||||
|
fs.createReadStream(fixtures.inputWebPAnimated)
|
||||||
|
.pipe(sharp({ animated: true }))
|
||||||
|
.webp({ lossless: true })
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('webp', info.format);
|
||||||
|
fixtures.assertSimilar(fixtures.inputWebPAnimated, data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with streams when only pages is set', function (done) {
|
||||||
|
fs.createReadStream(fixtures.inputWebPAnimated)
|
||||||
|
.pipe(sharp({ pages: -1 }))
|
||||||
|
.webp({ lossless: true })
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('webp', info.format);
|
||||||
|
fixtures.assertSimilar(fixtures.inputWebPAnimated, data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||