Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f23a8dc9dc | ||
|
|
d09fe6178c | ||
|
|
ae2cfcc4f3 | ||
|
|
853cc65e32 | ||
|
|
5d140d949f | ||
|
|
6d2da2b3ba | ||
|
|
165e337e44 | ||
|
|
b154cd0418 | ||
|
|
8ef1532691 | ||
|
|
771e44f2a7 | ||
|
|
8933f1128d | ||
|
|
dbac4b9a63 | ||
|
|
bdac5b5807 | ||
|
|
b0961b5213 | ||
|
|
0d7c3fc4d8 | ||
|
|
8dac256096 | ||
|
|
8320da39c3 | ||
|
|
875937e3d8 | ||
|
|
f880adbaac | ||
|
|
48c5f86adb | ||
|
|
f60f7dab12 | ||
|
|
8f690236ed | ||
|
|
430a4297aa | ||
|
|
69e3ab02c4 | ||
|
|
b87a20b881 | ||
|
|
0e6f2d16ab | ||
|
|
498b061819 | ||
|
|
5ab6f599fb | ||
|
|
8b80626035 | ||
|
|
f86ae79fdb | ||
|
|
1a4e68096f | ||
|
|
d599d1f29e | ||
|
|
73edfb3d2c | ||
|
|
ebae68d579 | ||
|
|
573836e2b8 | ||
|
|
da5deb8177 | ||
|
|
8fca89e876 | ||
|
|
d5295a2d0c | ||
|
|
c4df115948 | ||
|
|
8afcb16d8e | ||
|
|
3764d63244 | ||
|
|
c82914df30 | ||
|
|
84ba921f5b | ||
|
|
8e74668e3c | ||
|
|
707c05b5f5 | ||
|
|
9bd2cec199 | ||
|
|
358b8fe8b6 | ||
|
|
7115ae5375 | ||
|
|
13997ca653 | ||
|
|
9fa04a0b93 | ||
|
|
0894145284 | ||
|
|
927b77700d | ||
|
|
1d7a0ea99e | ||
|
|
d6aee8e5ba | ||
|
|
dfaa39fa5d | ||
|
|
8fe3b59efe | ||
|
|
47237b1f15 | ||
|
|
053e727bd5 | ||
|
|
2ce9e81d80 | ||
|
|
50848ee462 | ||
|
|
ef06d560cd | ||
|
|
2abf9f96c7 | ||
|
|
a91686b4cd | ||
|
|
1be424cd47 | ||
|
|
929ea10f76 | ||
|
|
11d1f39e3d | ||
|
|
fc233ed4ff | ||
|
|
efd2e893cf | ||
|
|
2a18b9a8f7 | ||
|
|
6aa214181b | ||
|
|
7067beda99 | ||
|
|
e0f0baf164 | ||
|
|
1fec132dee | ||
|
|
ba521fccb4 | ||
|
|
965a97105e | ||
|
|
3c88c84998 | ||
|
|
d0f66c3734 | ||
|
|
ebc2a741f6 | ||
|
|
d46512af1c | ||
|
|
b4d72bd544 | ||
|
|
382d476271 | ||
|
|
80c240b54a | ||
|
|
21f99d88ab | ||
|
|
d5873a00d5 | ||
|
|
99076edc89 | ||
|
|
7b6c80327e | ||
|
|
57946ed672 | ||
|
|
aad16ac50d | ||
|
|
bbe897e607 | ||
|
|
eca0e66e23 | ||
|
|
3511723914 | ||
|
|
6a1c7b7588 |
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
src/libvips/* linguist-vendored
|
||||||
7
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
build
|
build
|
||||||
node_modules
|
node_modules
|
||||||
coverage
|
/coverage
|
||||||
test/bench/node_modules
|
test/bench/node_modules
|
||||||
test/fixtures/output*
|
test/fixtures/output*
|
||||||
test/leak/libvips.supp
|
test/leak/libvips.supp
|
||||||
@@ -9,8 +9,7 @@ test/saliency/Image*
|
|||||||
test/saliency/[Uu]serData*
|
test/saliency/[Uu]serData*
|
||||||
!test/saliency/userData.js
|
!test/saliency/userData.js
|
||||||
vendor
|
vendor
|
||||||
packaging/libvips*
|
.gitattributes
|
||||||
packaging/*.log
|
|
||||||
!packaging/build
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.nyc_output
|
.nyc_output
|
||||||
|
package-lock.json
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ build
|
|||||||
node_modules
|
node_modules
|
||||||
coverage
|
coverage
|
||||||
.editorconfig
|
.editorconfig
|
||||||
|
.gitattributes
|
||||||
.gitignore
|
.gitignore
|
||||||
test
|
test
|
||||||
.travis.yml
|
.travis.yml
|
||||||
appveyor.yml
|
appveyor.yml
|
||||||
circle.yml
|
|
||||||
mkdocs.yml
|
mkdocs.yml
|
||||||
vendor
|
vendor
|
||||||
packaging
|
.prebuildrc
|
||||||
preinstall.sh
|
|
||||||
.nyc_output
|
.nyc_output
|
||||||
|
CONTRIBUTING.md
|
||||||
|
|||||||
4
.prebuildrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"include-regex": "(sharp\\.node|libvips-cpp\\.dll)",
|
||||||
|
"strip": true
|
||||||
|
}
|
||||||
13
.travis.yml
@@ -13,15 +13,22 @@ matrix:
|
|||||||
dist: trusty
|
dist: trusty
|
||||||
sudo: false
|
sudo: false
|
||||||
node_js: "8"
|
node_js: "8"
|
||||||
|
- os: linux
|
||||||
|
dist: trusty
|
||||||
|
sudo: false
|
||||||
|
node_js: "10"
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8
|
osx_image: xcode8.3
|
||||||
node_js: "4"
|
node_js: "4"
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8
|
osx_image: xcode8.3
|
||||||
node_js: "6"
|
node_js: "6"
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8
|
osx_image: xcode8.3
|
||||||
node_js: "8"
|
node_js: "8"
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode8.3
|
||||||
|
node_js: "10"
|
||||||
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
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ New bugs are assigned a `triage` label whilst under investigation.
|
|||||||
|
|
||||||
If a [similar request](https://github.com/lovell/sharp/labels/enhancement) exists, it's probably fastest to add a comment to it about your requirement.
|
If a [similar request](https://github.com/lovell/sharp/labels/enhancement) exists, it's probably fastest to add a comment to it about your requirement.
|
||||||
|
|
||||||
Implementation is usually straightforward if _libvips_ [already supports](http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/ch03.html) the feature you need.
|
Implementation is usually straightforward if _libvips_ [already supports](https://jcupitt.github.io/libvips/API/current/) the feature you need.
|
||||||
|
|
||||||
## Submit a Pull Request to fix a bug
|
## Submit a Pull Request to fix a bug
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ Any change that modifies the existing public API should be added to the relevant
|
|||||||
|
|
||||||
| Release | WIP branch |
|
| Release | WIP branch |
|
||||||
| ------: | :--------- |
|
| ------: | :--------- |
|
||||||
| v0.18.0 | ridge |
|
| v0.21.0 | teeth |
|
||||||
| v0.19.0 | suit |
|
| v0.22.0 | uptake |
|
||||||
|
|
||||||
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>`.
|
||||||
|
|
||||||
@@ -89,15 +89,6 @@ Requires [Valgrind](http://valgrind.org/).
|
|||||||
npm run test-leak
|
npm run test-leak
|
||||||
```
|
```
|
||||||
|
|
||||||
### Packaging tests
|
|
||||||
|
|
||||||
Tests the installation on a number of Linux-based operating systems.
|
|
||||||
Requires docker.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run test-packaging
|
|
||||||
```
|
|
||||||
|
|
||||||
## Finally
|
## Finally
|
||||||
|
|
||||||
Please feel free to ask any questions via a
|
Please feel free to ask any questions via a
|
||||||
|
|||||||
25
README.md
@@ -4,6 +4,10 @@
|
|||||||
npm install sharp
|
npm install sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn add sharp
|
||||||
|
```
|
||||||
|
|
||||||
The typical use case for this high speed Node.js module
|
The typical use case for this high speed Node.js module
|
||||||
is to convert large images in common formats to
|
is to convert large images in common formats to
|
||||||
smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.
|
||||||
@@ -17,13 +21,14 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|||||||
As well as image resizing, operations such as
|
As well as image resizing, operations such as
|
||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
OS X, Windows (x64), Linux (x64, ARM) systems do not require
|
Most modern 64-bit OS X, Windows and Linux (glibc) systems running
|
||||||
the installation of any external runtime dependencies.
|
Node versions 4, 6, 8 and 10
|
||||||
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import sharp from 'sharp';
|
const sharp = require('sharp');
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -33,8 +38,6 @@ sharp(inputBuffer)
|
|||||||
// A Promises/A+ promise is returned when callback is not provided.
|
// A Promises/A+ promise is returned when callback is not provided.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
.rotate()
|
.rotate()
|
||||||
@@ -64,11 +67,11 @@ readableStream
|
|||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
Visit [sharp.dimens.io](http://sharp.dimens.io/) for complete
|
Visit [sharp.pixelplumbing.com](http://sharp.pixelplumbing.com/) for complete
|
||||||
[installation instructions](http://sharp.dimens.io/page/install),
|
[installation instructions](http://sharp.pixelplumbing.com/page/install),
|
||||||
[API documentation](http://sharp.dimens.io/page/api),
|
[API documentation](http://sharp.pixelplumbing.com/page/api),
|
||||||
[benchmark tests](http://sharp.dimens.io/page/performance) and
|
[benchmark tests](http://sharp.pixelplumbing.com/page/performance) and
|
||||||
[changelog](http://sharp.dimens.io/page/changelog).
|
[changelog](http://sharp.pixelplumbing.com/page/changelog).
|
||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
@@ -77,7 +80,7 @@ covers reporting bugs, requesting features and submitting code changes.
|
|||||||
|
|
||||||
### Licence
|
### Licence
|
||||||
|
|
||||||
Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
Copyright 2013, 2014, 2015, 2016, 2017, 2018 Lovell Fuller and contributors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ environment:
|
|||||||
matrix:
|
matrix:
|
||||||
- nodejs_version: "4"
|
- nodejs_version: "4"
|
||||||
- nodejs_version: "6"
|
- nodejs_version: "6"
|
||||||
- nodejs_version: "7"
|
- nodejs_version: "8"
|
||||||
|
- nodejs_version: "10"
|
||||||
install:
|
install:
|
||||||
- ps: Install-Product node $env:nodejs_version x64
|
- ps: Install-Product node $env:nodejs_version x64
|
||||||
- npm install -g npm@latest
|
- npm install -g npm@5
|
||||||
- npm install
|
- npm install
|
||||||
test_script:
|
test_script:
|
||||||
- npm test
|
- npm test
|
||||||
|
|||||||
100
binding.gyp
@@ -5,9 +5,6 @@
|
|||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
||||||
'type': 'shared_library',
|
'type': 'shared_library',
|
||||||
'variables': {
|
|
||||||
'download_vips': '<!(node -e "require(\'./binding\').download_vips()")'
|
|
||||||
},
|
|
||||||
'defines': [
|
'defines': [
|
||||||
'VIPS_CPLUSPLUS_EXPORTS',
|
'VIPS_CPLUSPLUS_EXPORTS',
|
||||||
'_ALLOW_KEYWORD_MACROS'
|
'_ALLOW_KEYWORD_MACROS'
|
||||||
@@ -49,43 +46,22 @@
|
|||||||
'dependencies': [
|
'dependencies': [
|
||||||
'libvips-cpp'
|
'libvips-cpp'
|
||||||
],
|
],
|
||||||
# Nested variables "pattern" borrowed from http://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi
|
|
||||||
'variables': {
|
'variables': {
|
||||||
'variables': {
|
|
||||||
'variables': {
|
|
||||||
'conditions': [
|
|
||||||
['OS != "win"', {
|
|
||||||
# Build the PKG_CONFIG_PATH environment variable with all possible combinations
|
|
||||||
'pkg_config_path': '<!(which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR || true):$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig'
|
|
||||||
}, {
|
|
||||||
'pkg_config_path': ''
|
|
||||||
}]
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'conditions': [
|
|
||||||
['OS != "win"', {
|
|
||||||
# Which version, if any, of libvips is available globally via pkg-config?
|
|
||||||
'global_vips_version': '<!(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --modversion vips-cpp 2>/dev/null || true)'
|
|
||||||
}, {
|
|
||||||
'global_vips_version': ''
|
|
||||||
}]
|
|
||||||
],
|
|
||||||
'pkg_config_path%': '<(pkg_config_path)'
|
|
||||||
},
|
|
||||||
'pkg_config_path%': '<(pkg_config_path)',
|
|
||||||
'runtime_link%': 'shared',
|
'runtime_link%': 'shared',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS != "win"', {
|
['OS != "win"', {
|
||||||
# Does the globally available version of libvips, if any, meet the minimum version requirement?
|
'pkg_config_path': '<!(node -e "console.log(require(\'./lib/libvips\').pkgConfigPath())")',
|
||||||
'use_global_vips': '<!(GLOBAL_VIPS_VERSION="<(global_vips_version)" node -e "require(\'./binding\').use_global_vips()")'
|
'use_global_libvips': '<!(node -e "console.log(Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString())")'
|
||||||
}, {
|
}, {
|
||||||
'use_global_vips': ''
|
'pkg_config_path': '',
|
||||||
|
'use_global_libvips': ''
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'sources': [
|
'sources': [
|
||||||
'src/common.cc',
|
'src/common.cc',
|
||||||
'src/metadata.cc',
|
'src/metadata.cc',
|
||||||
|
'src/stats.cc',
|
||||||
'src/operations.cc',
|
'src/operations.cc',
|
||||||
'src/pipeline.cc',
|
'src/pipeline.cc',
|
||||||
'src/sharp.cc',
|
'src/sharp.cc',
|
||||||
@@ -95,7 +71,7 @@
|
|||||||
'<!(node -e "require(\'nan\')")'
|
'<!(node -e "require(\'nan\')")'
|
||||||
],
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['use_global_vips == "true"', {
|
['use_global_libvips == "true"', {
|
||||||
# Use pkg-config for include and lib
|
# Use pkg-config for include and lib
|
||||||
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
|
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
@@ -112,7 +88,7 @@
|
|||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
# Attempt to download pre-built libvips and install locally within node_modules
|
# Use pre-built libvips stored locally within node_modules
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'vendor/include',
|
'vendor/include',
|
||||||
'vendor/include/glib-2.0',
|
'vendor/include/glib-2.0',
|
||||||
@@ -130,9 +106,6 @@
|
|||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
['OS == "mac"', {
|
['OS == "mac"', {
|
||||||
'variables': {
|
|
||||||
'download_vips': '<!(node -e "require(\'./binding\').download_vips()")'
|
|
||||||
},
|
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'../vendor/lib/libvips-cpp.42.dylib',
|
'../vendor/lib/libvips-cpp.42.dylib',
|
||||||
'../vendor/lib/libvips.42.dylib',
|
'../vendor/lib/libvips.42.dylib',
|
||||||
@@ -143,9 +116,6 @@
|
|||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
['OS == "linux"', {
|
['OS == "linux"', {
|
||||||
'variables': {
|
|
||||||
'download_vips': '<!(node -e "require(\'./binding\').download_vips()")'
|
|
||||||
},
|
|
||||||
'defines': [
|
'defines': [
|
||||||
'_GLIBCXX_USE_CXX11_ABI=0'
|
'_GLIBCXX_USE_CXX11_ABI=0'
|
||||||
],
|
],
|
||||||
@@ -218,61 +188,5 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, {
|
|
||||||
'target_name': 'win_copy_dlls',
|
|
||||||
'type': 'none',
|
|
||||||
'dependencies': [
|
|
||||||
'sharp'
|
|
||||||
],
|
|
||||||
'conditions': [
|
|
||||||
['OS == "win"', {
|
|
||||||
# Windows lacks support for rpath
|
|
||||||
'copies': [{
|
|
||||||
'destination': 'build/Release',
|
|
||||||
'files': [
|
|
||||||
'vendor/lib/GNU.Gettext.dll',
|
|
||||||
'vendor/lib/libasprintf-0.dll',
|
|
||||||
'vendor/lib/libcairo-2.dll',
|
|
||||||
'vendor/lib/libcairo-gobject-2.dll',
|
|
||||||
'vendor/lib/libcairo-script-interpreter-2.dll',
|
|
||||||
'vendor/lib/libcharset-1.dll',
|
|
||||||
'vendor/lib/libcroco-0.6-3.dll',
|
|
||||||
'vendor/lib/libexif-12.dll',
|
|
||||||
'vendor/lib/libexpat-1.dll',
|
|
||||||
'vendor/lib/libffi-6.dll',
|
|
||||||
'vendor/lib/libfftw3-3.dll',
|
|
||||||
'vendor/lib/libfontconfig-1.dll',
|
|
||||||
'vendor/lib/libfreetype-6.dll',
|
|
||||||
'vendor/lib/libgcc_s_seh-1.dll',
|
|
||||||
'vendor/lib/libgdk_pixbuf-2.0-0.dll',
|
|
||||||
'vendor/lib/libgif-7.dll',
|
|
||||||
'vendor/lib/libgio-2.0-0.dll',
|
|
||||||
'vendor/lib/libglib-2.0-0.dll',
|
|
||||||
'vendor/lib/libgmodule-2.0-0.dll',
|
|
||||||
'vendor/lib/libgobject-2.0-0.dll',
|
|
||||||
'vendor/lib/libgsf-1-114.dll',
|
|
||||||
'vendor/lib/libgthread-2.0-0.dll',
|
|
||||||
'vendor/lib/libiconv-2.dll',
|
|
||||||
'vendor/lib/libintl-8.dll',
|
|
||||||
'vendor/lib/libjpeg-62.dll',
|
|
||||||
'vendor/lib/liblcms2-2.dll',
|
|
||||||
'vendor/lib/libpango-1.0-0.dll',
|
|
||||||
'vendor/lib/libpangocairo-1.0-0.dll',
|
|
||||||
'vendor/lib/libpangowin32-1.0-0.dll',
|
|
||||||
'vendor/lib/libpixman-1-0.dll',
|
|
||||||
'vendor/lib/libpng16-16.dll',
|
|
||||||
'vendor/lib/libquadmath-0.dll',
|
|
||||||
'vendor/lib/librsvg-2-2.dll',
|
|
||||||
'vendor/lib/libssp-0.dll',
|
|
||||||
'vendor/lib/libstdc++-6.dll',
|
|
||||||
'vendor/lib/libtiff-5.dll',
|
|
||||||
'vendor/lib/libvips-42.dll',
|
|
||||||
'vendor/lib/libwebp-7.dll',
|
|
||||||
'vendor/lib/libxml2-2.dll',
|
|
||||||
'vendor/lib/zlib1.dll'
|
|
||||||
]
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
]
|
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
129
binding.js
@@ -1,129 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const os = require('os');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const caw = require('caw');
|
|
||||||
const simpleGet = require('simple-get');
|
|
||||||
const semver = require('semver');
|
|
||||||
const tar = require('tar');
|
|
||||||
const detectLibc = require('detect-libc');
|
|
||||||
|
|
||||||
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || 'https://dl.bintray.com/lovell/sharp/';
|
|
||||||
|
|
||||||
// Use NPM-provided environment variable where available, falling back to require-based method for Electron
|
|
||||||
const minimumLibvipsVersion = process.env.npm_package_config_libvips || require('./package.json').config.libvips;
|
|
||||||
|
|
||||||
const platform = process.env.npm_config_platform || process.platform;
|
|
||||||
|
|
||||||
const arch = process.env.npm_config_arch || process.arch;
|
|
||||||
|
|
||||||
// -- Helpers
|
|
||||||
|
|
||||||
// Does this file exist?
|
|
||||||
const isFile = function (file) {
|
|
||||||
try {
|
|
||||||
return fs.statSync(file).isFile();
|
|
||||||
} catch (err) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
const unpack = function (tarPath, done) {
|
|
||||||
const vendorPath = path.join(__dirname, 'vendor');
|
|
||||||
fs.mkdirSync(vendorPath);
|
|
||||||
tar
|
|
||||||
.extract({
|
|
||||||
file: tarPath,
|
|
||||||
cwd: vendorPath,
|
|
||||||
strict: true
|
|
||||||
})
|
|
||||||
.then(done)
|
|
||||||
.catch(error);
|
|
||||||
};
|
|
||||||
|
|
||||||
const platformId = function () {
|
|
||||||
const platformId = [platform];
|
|
||||||
if (arch === 'arm' || arch === 'armhf' || arch === 'arm64') {
|
|
||||||
const armVersion = (arch === 'arm64') ? '8' : process.env.npm_config_armv || process.config.variables.arm_version || '6';
|
|
||||||
platformId.push('armv' + armVersion);
|
|
||||||
} else {
|
|
||||||
platformId.push(arch);
|
|
||||||
}
|
|
||||||
return platformId.join('-');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Error
|
|
||||||
const error = function (msg) {
|
|
||||||
if (msg instanceof Error) {
|
|
||||||
msg = msg.message;
|
|
||||||
}
|
|
||||||
process.stderr.write('ERROR: ' + msg + '\n');
|
|
||||||
process.exit(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
// -- Binary downloaders
|
|
||||||
|
|
||||||
module.exports.download_vips = function () {
|
|
||||||
// Has vips been installed locally?
|
|
||||||
const vipsHeaderPath = path.join(__dirname, 'vendor', 'include', 'vips', 'vips.h');
|
|
||||||
if (!isFile(vipsHeaderPath)) {
|
|
||||||
// Ensure Intel 64-bit or ARM
|
|
||||||
if (arch === 'ia32') {
|
|
||||||
error('Intel Architecture 32-bit systems require manual installation of libvips - please see http://sharp.dimens.io/page/install');
|
|
||||||
}
|
|
||||||
// Ensure glibc Linux
|
|
||||||
if (detectLibc.isNonGlibcLinux) {
|
|
||||||
error(`Use with ${detectLibc.family} libc requires manual installation of libvips - please see http://sharp.dimens.io/page/install`);
|
|
||||||
}
|
|
||||||
// Ensure glibc >= 2.13
|
|
||||||
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && semver.lt(`${detectLibc.version}.0`, '2.13.0')) {
|
|
||||||
error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips - please see http://sharp.dimens.io/page/install`);
|
|
||||||
}
|
|
||||||
// Arch/platform-specific .tar.gz
|
|
||||||
const tarFilename = ['libvips', minimumLibvipsVersion, platformId()].join('-') + '.tar.gz';
|
|
||||||
const tarPathLocal = path.join(__dirname, 'packaging', tarFilename);
|
|
||||||
if (isFile(tarPathLocal)) {
|
|
||||||
unpack(tarPathLocal);
|
|
||||||
} else {
|
|
||||||
// Download to per-process temporary file
|
|
||||||
const tarPathTemp = path.join(os.tmpdir(), process.pid + '-' + tarFilename);
|
|
||||||
const tmpFile = fs.createWriteStream(tarPathTemp).on('finish', function () {
|
|
||||||
unpack(tarPathTemp, function () {
|
|
||||||
// Attempt to remove temporary file
|
|
||||||
try {
|
|
||||||
fs.unlinkSync(tarPathTemp);
|
|
||||||
} catch (err) {}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const url = distBaseUrl + tarFilename;
|
|
||||||
const simpleGetOpt = {
|
|
||||||
url: url,
|
|
||||||
agent: caw(null, {
|
|
||||||
protocol: 'https'
|
|
||||||
})
|
|
||||||
};
|
|
||||||
simpleGet(simpleGetOpt, function (err, response) {
|
|
||||||
if (err) {
|
|
||||||
error('Download of ' + url + ' failed: ' + err.message);
|
|
||||||
}
|
|
||||||
if (response.statusCode !== 200) {
|
|
||||||
error(url + ' status code ' + response.statusCode);
|
|
||||||
}
|
|
||||||
response.pipe(tmpFile);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.use_global_vips = function () {
|
|
||||||
const globalVipsVersion = process.env.GLOBAL_VIPS_VERSION;
|
|
||||||
if (globalVipsVersion) {
|
|
||||||
const useGlobalVips = semver.gte(
|
|
||||||
globalVipsVersion,
|
|
||||||
minimumLibvipsVersion
|
|
||||||
);
|
|
||||||
process.stdout.write(useGlobalVips ? 'true' : 'false');
|
|
||||||
} else {
|
|
||||||
process.stdout.write('false');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
machine:
|
|
||||||
node:
|
|
||||||
version: v4.8.4
|
|
||||||
services:
|
|
||||||
- docker
|
|
||||||
test:
|
|
||||||
override:
|
|
||||||
- ./packaging/test-linux-x64.sh
|
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [extractChannel](#extractchannel)
|
- [extractChannel][1]
|
||||||
- [joinChannel](#joinchannel)
|
- [joinChannel][2]
|
||||||
- [bandbool](#bandbool)
|
- [bandbool][3]
|
||||||
|
|
||||||
## extractChannel
|
## extractChannel
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ Extract a single channel from a multi-channel image.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `channel` **([Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
|
- `channel` **([Number][4] \| [String][5])** zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid channel
|
- Throws **[Error][6]** Invalid channel
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -44,11 +44,11 @@ For raw pixel input, the `options` object should contain a `raw` attribute, whic
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `images` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html))> | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Buffer](https://nodejs.org/api/buffer.html))** one or more images (file paths, Buffers).
|
- `images` **([Array][7]<([String][5] \| [Buffer][8])> | [String][5] \| [Buffer][8])** one or more images (file paths, Buffers).
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** image options, see `sharp()` constructor.
|
- `options` **[Object][9]** image options, see `sharp()` constructor.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][6]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ Perform a bitwise boolean operation on all input image channels (bands) to produ
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `boolOp` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
- `boolOp` **[String][5]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -72,6 +72,24 @@ sharp('3-channel-rgb-input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][6]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #extractchannel
|
||||||
|
|
||||||
|
[2]: #joinchannel
|
||||||
|
|
||||||
|
[3]: #bandbool
|
||||||
|
|
||||||
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
|
[8]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [background](#background)
|
- [background][1]
|
||||||
- [greyscale](#greyscale)
|
- [tint][2]
|
||||||
- [grayscale](#grayscale)
|
- [greyscale][3]
|
||||||
- [toColourspace](#tocolourspace)
|
- [grayscale][4]
|
||||||
- [toColorspace](#tocolorspace)
|
- [toColourspace][5]
|
||||||
|
- [toColorspace][6]
|
||||||
|
|
||||||
## background
|
## background
|
||||||
|
|
||||||
@@ -19,10 +20,24 @@ The alpha value is a float between `0` (transparent) and `1` (opaque).
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `rgba` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
- `rgba` **([String][7] \| [Object][8])** parsed by the [color][9] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameter
|
- Throws **[Error][10]** Invalid parameter
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## tint
|
||||||
|
|
||||||
|
Tint the image using the provided chroma while preserving the image luminance.
|
||||||
|
An alpha channel may be present and will be unchanged by the operation.
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `rgb` **([String][7] \| [Object][8])** parsed by the [color][9] module to extract chroma values.
|
||||||
|
|
||||||
|
|
||||||
|
- Throws **[Error][10]** Invalid parameter
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -37,7 +52,7 @@ An alpha channel may be present, and will be unchanged by the operation.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `greyscale` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `greyscale` **[Boolean][11]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -47,7 +62,7 @@ Alternative spelling of `greyscale`.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `grayscale` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `grayscale` **[Boolean][11]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -58,10 +73,10 @@ By default output image will be web-friendly sRGB, with additional channels inte
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `colourspace` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568)
|
- `colourspace` **[String][7]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][12]
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][10]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -71,9 +86,33 @@ Alternative spelling of `toColourspace`.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `colorspace` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** output colorspace.
|
- `colorspace` **[String][7]?** output colorspace.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][10]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #background
|
||||||
|
|
||||||
|
[2]: #tint
|
||||||
|
|
||||||
|
[3]: #greyscale
|
||||||
|
|
||||||
|
[4]: #grayscale
|
||||||
|
|
||||||
|
[5]: #tocolourspace
|
||||||
|
|
||||||
|
[6]: #tocolorspace
|
||||||
|
|
||||||
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[9]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[12]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [overlayWith](#overlaywith)
|
- [overlayWith][1]
|
||||||
|
|
||||||
## overlayWith
|
## overlayWith
|
||||||
|
|
||||||
@@ -15,23 +15,23 @@ If the overlay image contains an alpha channel then composition with premultipli
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `overlay` **([Buffer](https://nodejs.org/api/buffer.html) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** Buffer containing image data or String containing the path to an image file.
|
- `overlay` **([Buffer][2] \| [String][3])** Buffer containing image data or String containing the path to an image file.
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `options` **[Object][4]?**
|
||||||
- `options.gravity` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** gravity at which to place the overlay. (optional, default `'centre'`)
|
- `options.gravity` **[String][3]** gravity at which to place the overlay. (optional, default `'centre'`)
|
||||||
- `options.top` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** the pixel offset from the top edge.
|
- `options.top` **[Number][5]?** the pixel offset from the top edge.
|
||||||
- `options.left` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** the pixel offset from the left edge.
|
- `options.left` **[Number][5]?** the pixel offset from the left edge.
|
||||||
- `options.tile` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
- `options.tile` **[Boolean][6]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
||||||
- `options.cutout` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** set to true to apply only the alpha channel of the overlay image to the input image, giving the appearance of one image being cut out of another. (optional, default `false`)
|
- `options.cutout` **[Boolean][6]** set to true to apply only the alpha channel of the overlay image to the input image, giving the appearance of one image being cut out of another. (optional, default `false`)
|
||||||
- `options.density` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** integral number representing the DPI for vector overlay image. (optional, default `72`)
|
- `options.density` **[Number][5]** integral number representing the DPI for vector overlay image. (optional, default `72`)
|
||||||
- `options.raw` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** describes overlay when using raw pixel data.
|
- `options.raw` **[Object][4]?** describes overlay when using raw pixel data.
|
||||||
- `options.raw.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.width` **[Number][5]?**
|
||||||
- `options.raw.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.height` **[Number][5]?**
|
||||||
- `options.raw.channels` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.channels` **[Number][5]?**
|
||||||
- `options.create` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** describes a blank overlay to be created.
|
- `options.create` **[Object][4]?** describes a blank overlay to be created.
|
||||||
- `options.create.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.create.width` **[Number][5]?**
|
||||||
- `options.create.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.create.height` **[Number][5]?**
|
||||||
- `options.create.channels` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** 3-4
|
- `options.create.channels` **[Number][5]?** 3-4
|
||||||
- `options.create.background` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))?** parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
- `options.create.background` **([String][3] \| [Object][4])?** parsed by the [color][7] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -54,6 +54,22 @@ sharp('input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][8]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #overlaywith
|
||||||
|
|
||||||
|
[2]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[7]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|||||||
@@ -2,30 +2,34 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [Sharp](#sharp)
|
- [Sharp][1]
|
||||||
- [format](#format)
|
- [format][2]
|
||||||
- [versions](#versions)
|
- [versions][3]
|
||||||
- [queue](#queue)
|
- [queue][4]
|
||||||
|
|
||||||
## Sharp
|
## Sharp
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `input` **([Buffer](https://nodejs.org/api/buffer.html) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))?** if present, can be
|
- `input` **([Buffer][5] \| [String][6])?** 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 path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
a String containing the 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** if present, is an Object with optional attributes.
|
- `options` **[Object][7]?** if present, is an Object with optional attributes.
|
||||||
- `options.density` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** integral number representing the DPI for vector images. (optional, default `72`)
|
- `options.failOnError` **[Boolean][8]** by default apply a "best effort"
|
||||||
- `options.raw` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
to decode images, even if the data is corrupt or invalid. Set this flag to true
|
||||||
- `options.raw.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
if you'd rather halt processing and raise an error when loading invalid images. (optional, default `false`)
|
||||||
- `options.raw.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.density` **[Number][9]** integral number representing the DPI for vector images. (optional, default `72`)
|
||||||
- `options.raw.channels` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** 1-4
|
- `options.page` **[Number][9]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
||||||
- `options.create` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** describes a new image to be created.
|
- `options.raw` **[Object][7]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
- `options.create.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.width` **[Number][9]?**
|
||||||
- `options.create.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.height` **[Number][9]?**
|
||||||
- `options.create.channels` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** 3-4
|
- `options.raw.channels` **[Number][9]?** 1-4
|
||||||
- `options.create.background` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))?** parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
- `options.create` **[Object][7]?** describes a new image to be created.
|
||||||
|
- `options.create.width` **[Number][9]?**
|
||||||
|
- `options.create.height` **[Number][9]?**
|
||||||
|
- `options.create.channels` **[Number][9]?** 3-4
|
||||||
|
- `options.create.background` **([String][6] \| [Object][7])?** parsed by the [color][10] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -66,9 +70,9 @@ sharp({
|
|||||||
.then( ... );
|
.then( ... );
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][11]** Invalid parameters
|
||||||
|
|
||||||
Returns **[Sharp](#sharp)**
|
Returns **[Sharp][12]**
|
||||||
|
|
||||||
### format
|
### format
|
||||||
|
|
||||||
@@ -80,7 +84,7 @@ An Object containing nested boolean values representing the available input and
|
|||||||
console.log(sharp.format);
|
console.log(sharp.format);
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
Returns **[Object][7]**
|
||||||
|
|
||||||
### versions
|
### versions
|
||||||
|
|
||||||
@@ -106,3 +110,27 @@ sharp.queue.on('change', function(queueLength) {
|
|||||||
console.log('Queue contains ' + queueLength + ' task(s)');
|
console.log('Queue contains ' + queueLength + ' task(s)');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[1]: #sharp
|
||||||
|
|
||||||
|
[2]: #format
|
||||||
|
|
||||||
|
[3]: #versions
|
||||||
|
|
||||||
|
[4]: #queue
|
||||||
|
|
||||||
|
[5]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[10]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[12]: #sharp
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [clone](#clone)
|
- [clone][1]
|
||||||
- [metadata](#metadata)
|
- [metadata][2]
|
||||||
- [limitInputPixels](#limitinputpixels)
|
- [stats][3]
|
||||||
- [sequentialRead](#sequentialread)
|
- [limitInputPixels][4]
|
||||||
|
- [sequentialRead][5]
|
||||||
|
|
||||||
## clone
|
## clone
|
||||||
|
|
||||||
@@ -32,21 +33,23 @@ Fast access to (uncached) image metadata without decoding any compressed image d
|
|||||||
A Promises/A+ promise is returned when `callback` is not provided.
|
A Promises/A+ promise is returned when `callback` is not provided.
|
||||||
|
|
||||||
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||||
- `width`: Number of pixels wide
|
- `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
|
||||||
- `height`: Number of pixels high
|
- `height`: Number of pixels high (EXIF orientation is not taken into consideration)
|
||||||
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636)
|
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][6]
|
||||||
- `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
- `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||||
- `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672)
|
- `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][7]
|
||||||
- `density`: Number of pixels per inch (DPI), if present
|
- `density`: Number of pixels per inch (DPI), if present
|
||||||
- `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
|
||||||
- `exif`: Buffer containing raw EXIF data, if present
|
- `exif`: Buffer containing raw EXIF data, if present
|
||||||
- `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
- `icc`: Buffer containing raw [ICC][8] profile data, if present
|
||||||
|
- `iptc`: Buffer containing raw IPTC data, if present
|
||||||
|
- `xmp`: Buffer containing raw XMP data, if present
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** called with the arguments `(err, metadata)`
|
- `callback` **[Function][9]?** called with the arguments `(err, metadata)`
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -65,7 +68,42 @@ image
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **([Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)> | Sharp)**
|
Returns **([Promise][10]<[Object][11]> | Sharp)**
|
||||||
|
|
||||||
|
## stats
|
||||||
|
|
||||||
|
Access to pixel-derived image statistics for every channel in the image.
|
||||||
|
A Promise is returned when `callback` is not provided.
|
||||||
|
|
||||||
|
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||||
|
- `min` (minimum value in the channel)
|
||||||
|
- `max` (maximum value in the channel)
|
||||||
|
- `sum` (sum of all values in a channel)
|
||||||
|
- `squaresSum` (sum of squared values in a channel)
|
||||||
|
- `mean` (mean of the values in a channel)
|
||||||
|
- `stdev` (standard deviation for the values in a channel)
|
||||||
|
- `minX` (x-coordinate of one of the pixel where the minimum lies)
|
||||||
|
- `minY` (y-coordinate of one of the pixel where the minimum lies)
|
||||||
|
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||||
|
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||||
|
- `isOpaque`: Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `callback` **[Function][9]?** called with the arguments `(err, stats)`
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const image = sharp(inputJpg);
|
||||||
|
image
|
||||||
|
.stats()
|
||||||
|
.then(function(stats) {
|
||||||
|
// stats contains the channel-wise statistics array and the isOpaque value
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **[Promise][10]<[Object][11]>**
|
||||||
|
|
||||||
## limitInputPixels
|
## limitInputPixels
|
||||||
|
|
||||||
@@ -75,10 +113,10 @@ The default limit is 268402689 (0x3FFF _ 0x3FFF) pixels.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `limit` **([Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** an integral Number of pixels, zero or false to remove limit, true to use default limit.
|
- `limit` **([Number][12] \| [Boolean][13])** an integral Number of pixels, zero or false to remove limit, true to use default limit.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid limit
|
- Throws **[Error][14]** Invalid limit
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -87,8 +125,38 @@ Returns **Sharp**
|
|||||||
An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`.
|
An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`.
|
||||||
This will reduce memory usage and can improve performance on some systems.
|
This will reduce memory usage and can improve performance on some systems.
|
||||||
|
|
||||||
|
The default behaviour _before_ function call is `false`, meaning the libvips access method is not sequential.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `sequentialRead` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `sequentialRead` **[Boolean][13]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #clone
|
||||||
|
|
||||||
|
[2]: #metadata
|
||||||
|
|
||||||
|
[3]: #stats
|
||||||
|
|
||||||
|
[4]: #limitinputpixels
|
||||||
|
|
||||||
|
[5]: #sequentialread
|
||||||
|
|
||||||
|
[6]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636
|
||||||
|
|
||||||
|
[7]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672
|
||||||
|
|
||||||
|
[8]: https://www.npmjs.com/package/icc
|
||||||
|
|
||||||
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
||||||
|
|
||||||
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|||||||
@@ -2,22 +2,24 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [rotate](#rotate)
|
- [rotate][1]
|
||||||
- [extract](#extract)
|
- [extract][2]
|
||||||
- [flip](#flip)
|
- [flip][3]
|
||||||
- [flop](#flop)
|
- [flop][4]
|
||||||
- [sharpen](#sharpen)
|
- [sharpen][5]
|
||||||
- [blur](#blur)
|
- [median][6]
|
||||||
- [extend](#extend)
|
- [blur][7]
|
||||||
- [flatten](#flatten)
|
- [extend][8]
|
||||||
- [trim](#trim)
|
- [flatten][9]
|
||||||
- [gamma](#gamma)
|
- [trim][10]
|
||||||
- [negate](#negate)
|
- [gamma][11]
|
||||||
- [normalise](#normalise)
|
- [negate][12]
|
||||||
- [normalize](#normalize)
|
- [normalise][13]
|
||||||
- [convolve](#convolve)
|
- [normalize][14]
|
||||||
- [threshold](#threshold)
|
- [convolve][15]
|
||||||
- [boolean](#boolean)
|
- [threshold][16]
|
||||||
|
- [boolean][17]
|
||||||
|
- [linear][18]
|
||||||
|
|
||||||
## rotate
|
## rotate
|
||||||
|
|
||||||
@@ -37,7 +39,7 @@ for example `rotate(x).extract(y)` will produce a different result to `extract(y
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `angle` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle of rotation, must be a multiple of 90. (optional, default `auto`)
|
- `angle` **[Number][19]** angle of rotation, must be a multiple of 90. (optional, default `auto`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ const pipeline = sharp()
|
|||||||
readableStream.pipe(pipeline);
|
readableStream.pipe(pipeline);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -67,11 +69,11 @@ Extract a region of the image.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
- `options` **[Object][21]**
|
||||||
- `options.left` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** zero-indexed offset from left edge
|
- `options.left` **[Number][19]** zero-indexed offset from left edge
|
||||||
- `options.top` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** zero-indexed offset from top edge
|
- `options.top` **[Number][19]** zero-indexed offset from top edge
|
||||||
- `options.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** dimension of extracted image
|
- `options.width` **[Number][19]** dimension of extracted image
|
||||||
- `options.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** dimension of extracted image
|
- `options.height` **[Number][19]** dimension of extracted image
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -93,7 +95,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -104,7 +106,7 @@ The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `flip` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `flip` **[Boolean][22]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -115,7 +117,7 @@ The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `flop` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `flop` **[Boolean][22]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -128,12 +130,26 @@ Separate control over the level of sharpening in "flat" and "jagged" areas is av
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `sigma` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
- `sigma` **[Number][19]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
- `flat` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
|
- `flat` **[Number][19]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
|
||||||
- `jagged` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
- `jagged` **[Number][19]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## median
|
||||||
|
|
||||||
|
Apply median filter.
|
||||||
|
When used without parameters the default window is 3x3.
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `size` **[Number][19]** square mask size: size x size (optional, default `3`)
|
||||||
|
|
||||||
|
|
||||||
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -145,10 +161,10 @@ When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `sigma` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
- `sigma` **[Number][19]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -159,11 +175,11 @@ This operation will always occur after resizing and extraction, if any.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `extend` **([Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** single pixel count to add to all edges or an Object with per-edge counts
|
- `extend` **([Number][19] \| [Object][21])** single pixel count to add to all edges or an Object with per-edge counts
|
||||||
- `extend.top` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `extend.top` **[Number][19]?**
|
||||||
- `extend.left` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `extend.left` **[Number][19]?**
|
||||||
- `extend.bottom` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `extend.bottom` **[Number][19]?**
|
||||||
- `extend.right` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `extend.right` **[Number][19]?**
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -177,7 +193,7 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -187,7 +203,7 @@ Merge alpha transparency channel, if any, with `background`.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `flatten` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `flatten` **[Boolean][22]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -197,10 +213,10 @@ Trim "boring" pixels from all edges that contain values within a percentage simi
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `tolerance` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** value between 1 and 99 representing the percentage similarity. (optional, default `10`)
|
- `tolerance` **[Number][19]** value between 1 and 99 representing the percentage similarity. (optional, default `10`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -214,10 +230,10 @@ when applying a gamma correction.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `gamma` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** value between 1.0 and 3.0. (optional, default `2.2`)
|
- `gamma` **[Number][19]** value between 1.0 and 3.0. (optional, default `2.2`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -227,7 +243,7 @@ Produce the "negative" of the image.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `negate` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `negate` **[Boolean][22]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -237,7 +253,7 @@ Enhance output image contrast by stretching its luminance to cover the full dyna
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `normalise` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `normalise` **[Boolean][22]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -247,7 +263,7 @@ Alternative spelling of normalise.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `normalize` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `normalize` **[Boolean][22]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -257,12 +273,12 @@ Convolve the image with the specified kernel.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `kernel` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
- `kernel` **[Object][21]**
|
||||||
- `kernel.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** width of the kernel in pixels.
|
- `kernel.width` **[Number][19]** width of the kernel in pixels.
|
||||||
- `kernel.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** width of the kernel in pixels.
|
- `kernel.height` **[Number][19]** width of the kernel in pixels.
|
||||||
- `kernel.kernel` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** Array of length `width*height` containing the kernel values.
|
- `kernel.kernel` **[Array][23]<[Number][19]>** Array of length `width*height` containing the kernel values.
|
||||||
- `kernel.scale` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the scale of the kernel in pixels. (optional, default `sum`)
|
- `kernel.scale` **[Number][19]** the scale of the kernel in pixels. (optional, default `sum`)
|
||||||
- `kernel.offset` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the offset of the kernel in pixels. (optional, default `0`)
|
- `kernel.offset` **[Number][19]** the offset of the kernel in pixels. (optional, default `0`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -280,7 +296,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -290,13 +306,13 @@ Any pixel value greather than or equal to the threshold value will be set to 255
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `threshold` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
- `threshold` **[Number][19]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `options` **[Object][21]?**
|
||||||
- `options.greyscale` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** convert to single channel greyscale. (optional, default `true`)
|
- `options.greyscale` **[Boolean][22]** convert to single channel greyscale. (optional, default `true`)
|
||||||
- `options.grayscale` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** alternative spelling for greyscale. (optional, default `true`)
|
- `options.grayscale` **[Boolean][22]** alternative spelling for greyscale. (optional, default `true`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -309,15 +325,79 @@ the selected bitwise boolean `operation` between the corresponding pixels of the
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `operand` **([Buffer](https://nodejs.org/api/buffer.html) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** Buffer containing image data or String containing the path to an image file.
|
- `operand` **([Buffer][24] \| [String][25])** Buffer containing image data or String containing the path to an image file.
|
||||||
- `operator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
- `operator` **[String][25]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `options` **[Object][21]?**
|
||||||
- `options.raw` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** describes operand when using raw pixel data.
|
- `options.raw` **[Object][21]?** describes operand when using raw pixel data.
|
||||||
- `options.raw.width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.width` **[Number][19]?**
|
||||||
- `options.raw.height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.height` **[Number][19]?**
|
||||||
- `options.raw.channels` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `options.raw.channels` **[Number][19]?**
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## linear
|
||||||
|
|
||||||
|
Apply the linear formula a \* input + b to the image (levels adjustment)
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `a` **[Number][19]** multiplier (optional, default `1.0`)
|
||||||
|
- `b` **[Number][19]** offset (optional, default `0.0`)
|
||||||
|
|
||||||
|
|
||||||
|
- Throws **[Error][20]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #rotate
|
||||||
|
|
||||||
|
[2]: #extract
|
||||||
|
|
||||||
|
[3]: #flip
|
||||||
|
|
||||||
|
[4]: #flop
|
||||||
|
|
||||||
|
[5]: #sharpen
|
||||||
|
|
||||||
|
[6]: #median
|
||||||
|
|
||||||
|
[7]: #blur
|
||||||
|
|
||||||
|
[8]: #extend
|
||||||
|
|
||||||
|
[9]: #flatten
|
||||||
|
|
||||||
|
[10]: #trim
|
||||||
|
|
||||||
|
[11]: #gamma
|
||||||
|
|
||||||
|
[12]: #negate
|
||||||
|
|
||||||
|
[13]: #normalise
|
||||||
|
|
||||||
|
[14]: #normalize
|
||||||
|
|
||||||
|
[15]: #convolve
|
||||||
|
|
||||||
|
[16]: #threshold
|
||||||
|
|
||||||
|
[17]: #boolean
|
||||||
|
|
||||||
|
[18]: #linear
|
||||||
|
|
||||||
|
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
|
[24]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [toFile](#tofile)
|
- [toFile][1]
|
||||||
- [toBuffer](#tobuffer)
|
- [toBuffer][2]
|
||||||
- [withMetadata](#withmetadata)
|
- [withMetadata][3]
|
||||||
- [jpeg](#jpeg)
|
- [jpeg][4]
|
||||||
- [png](#png)
|
- [png][5]
|
||||||
- [webp](#webp)
|
- [webp][6]
|
||||||
- [tiff](#tiff)
|
- [tiff][7]
|
||||||
- [raw](#raw)
|
- [raw][8]
|
||||||
- [toFormat](#toformat)
|
- [toFormat][9]
|
||||||
- [tile](#tile)
|
- [tile][10]
|
||||||
|
|
||||||
## toFile
|
## toFile
|
||||||
|
|
||||||
@@ -21,19 +21,33 @@ If an explicit output format is not selected, it will be inferred from the exten
|
|||||||
with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
|
with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
|
||||||
Note that raw pixel data is only supported for buffer output.
|
Note that raw pixel data is only supported for buffer output.
|
||||||
|
|
||||||
A Promises/A+ promise is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `fileOut` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the path to write the image data to.
|
- `fileOut` **[String][11]** the path to write the image data to.
|
||||||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** called on completion with two arguments `(err, info)`.
|
- `callback` **[Function][12]?** called on completion with two arguments `(err, info)`.
|
||||||
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toFile('output.png', (err, info) => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** when no callback is provided
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toFile('output.png')
|
||||||
|
.then(info => { ... })
|
||||||
|
.catch(err => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **[Promise][14]<[Object][15]>** when no callback is provided
|
||||||
|
|
||||||
## toBuffer
|
## toBuffer
|
||||||
|
|
||||||
@@ -47,15 +61,38 @@ By default, the format will match the input image, except GIF and SVG input whic
|
|||||||
- `data` is the output image data.
|
- `data` is the output image data.
|
||||||
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
A Promise is returned when `callback` is not provided.
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
|
||||||
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `options` **[Object][15]?**
|
||||||
- `options.resolveWithObject` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
- `options.resolveWithObject` **[Boolean][16]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?**
|
- `callback` **[Function][12]?**
|
||||||
|
|
||||||
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** when no callback is provided
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toBuffer((err, data, info) => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toBuffer()
|
||||||
|
.then(data => { ... })
|
||||||
|
.catch(err => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(({ data, info }) => { ... })
|
||||||
|
.catch(err => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **[Promise][14]<[Buffer][17]>** when no callback is provided
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
|
|
||||||
@@ -65,11 +102,19 @@ This will also convert to and add a web-friendly sRGB ICC profile.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `withMetadata` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `withMetadata` **[Object][15]?**
|
||||||
- `withMetadata.orientation` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
- `withMetadata.orientation` **[Number][18]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
```javascript
|
||||||
|
sharp('input.jpg')
|
||||||
|
.withMetadata()
|
||||||
|
.toFile('output-with-metadata.jpg')
|
||||||
|
.then(info => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -79,18 +124,29 @@ Use these JPEG options for output image.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** output options
|
- `options` **[Object][15]?** output options
|
||||||
- `options.quality` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.progressive` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.chromaSubsampling` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`)
|
- `options.chromaSubsampling` **[String][11]** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`)
|
||||||
- `options.trellisQuantisation` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** apply trellis quantisation, requires mozjpeg (optional, default `false`)
|
- `options.trellisQuantisation` **[Boolean][16]** apply trellis quantisation, requires mozjpeg (optional, default `false`)
|
||||||
- `options.overshootDeringing` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** apply overshoot deringing, requires mozjpeg (optional, default `false`)
|
- `options.overshootDeringing` **[Boolean][16]** apply overshoot deringing, requires mozjpeg (optional, default `false`)
|
||||||
- `options.optimiseScans` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`)
|
- `options.optimiseScans` **[Boolean][16]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`)
|
||||||
- `options.optimizeScans` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** alternative spelling of optimiseScans (optional, default `false`)
|
- `options.optimizeScans` **[Boolean][16]** alternative spelling of optimiseScans (optional, default `false`)
|
||||||
- `options.force` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][16]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid options
|
```javascript
|
||||||
|
// Convert any input to very high quality JPEG output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.jpeg({
|
||||||
|
quality: 100,
|
||||||
|
chromaSubsampling: '4:4:4'
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -98,16 +154,27 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these PNG options for output image.
|
Use these PNG options for output image.
|
||||||
|
|
||||||
|
PNG output is always full colour at 8 or 16 bits per pixel.
|
||||||
|
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `options` **[Object][15]?**
|
||||||
- `options.progressive` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.compressionLevel` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** zlib compression level (optional, default `6`)
|
- `options.compressionLevel` **[Number][18]** zlib compression level, 0-9 (optional, default `9`)
|
||||||
- `options.adaptiveFiltering` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use adaptive row filtering (optional, default `true`)
|
- `options.adaptiveFiltering` **[Boolean][16]** use adaptive row filtering (optional, default `false`)
|
||||||
- `options.force` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][16]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid options
|
```javascript
|
||||||
|
// Convert any input to PNG output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.png()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -117,15 +184,23 @@ Use these WebP options for output image.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** output options
|
- `options` **[Object][15]?** output options
|
||||||
- `options.quality` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.alphaQuality` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** quality of alpha layer, integer 0-100 (optional, default `100`)
|
- `options.alphaQuality` **[Number][18]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
||||||
- `options.lossless` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use lossless compression mode (optional, default `false`)
|
- `options.lossless` **[Boolean][16]** use lossless compression mode (optional, default `false`)
|
||||||
- `options.nearLossless` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use near_lossless compression mode (optional, default `false`)
|
- `options.nearLossless` **[Boolean][16]** use near_lossless compression mode (optional, default `false`)
|
||||||
- `options.force` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][16]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid options
|
```javascript
|
||||||
|
// Convert any input to lossless WebP output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.webp({ lossless: true })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -135,17 +210,29 @@ Use these TIFF options for output image.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** output options
|
- `options` **[Object][15]?** output options
|
||||||
- `options.quality` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.force` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][16]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
||||||
- `options.compression` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** compression options: lzw, deflate, jpeg (optional, default `'jpeg'`)
|
- `options.compression` **[Boolean][16]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
||||||
- `options.predictor` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** compression predictor options: none, horizontal, float (optional, default `'none'`)
|
- `options.predictor` **[Boolean][16]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
||||||
- `options.xres` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** horizontal resolution in pixels/mm (optional, default `1.0`)
|
- `options.xres` **[Number][18]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
||||||
- `options.yres` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** vertical resolution in pixels/mm (optional, default `1.0`)
|
- `options.yres` **[Number][18]** vertical resolution in pixels/mm (optional, default `1.0`)
|
||||||
- `options.squash` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** squash 8-bit images down to 1 bit (optional, default `false`)
|
- `options.squash` **[Boolean][16]** squash 8-bit images down to 1 bit (optional, default `false`)
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid options
|
```javascript
|
||||||
|
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
|
sharp('input.svg')
|
||||||
|
.tiff({
|
||||||
|
compression: 'lzw',
|
||||||
|
squash: true
|
||||||
|
})
|
||||||
|
.toFile('1-bpp-output.tiff')
|
||||||
|
.then(info => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -153,6 +240,15 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Force output to be raw, uncompressed uint8 pixel data.
|
Force output to be raw, uncompressed uint8 pixel data.
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Extract raw RGB pixel data from JPEG input
|
||||||
|
const { data, info } = await sharp('input.jpg')
|
||||||
|
.raw()
|
||||||
|
.toBuffer({ resolveWithObject: true });
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## toFormat
|
## toFormat
|
||||||
@@ -161,11 +257,19 @@ Force output to a given format.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `format` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** as a String or an Object with an 'id' attribute
|
- `format` **([String][11] \| [Object][15])** as a String or an Object with an 'id' attribute
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** output options
|
- `options` **[Object][15]** output options
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** unsupported format or options
|
```javascript
|
||||||
|
// Convert any input to PNG output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.toFormat('png')
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][13]** unsupported format or options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -177,11 +281,12 @@ Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed arc
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `tile` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `tile` **[Object][15]?**
|
||||||
- `tile.size` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
- `tile.size` **[Number][18]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
||||||
- `tile.overlap` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
- `tile.overlap` **[Number][18]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
- `tile.container` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
- `tile.angle` **[Number][18]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
||||||
- `tile.layout` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
- `tile.container` **[String][11]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
|
- `tile.layout` **[String][11]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -197,6 +302,42 @@ sharp('input.tiff')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #tofile
|
||||||
|
|
||||||
|
[2]: #tobuffer
|
||||||
|
|
||||||
|
[3]: #withmetadata
|
||||||
|
|
||||||
|
[4]: #jpeg
|
||||||
|
|
||||||
|
[5]: #png
|
||||||
|
|
||||||
|
[6]: #webp
|
||||||
|
|
||||||
|
[7]: #tiff
|
||||||
|
|
||||||
|
[8]: #raw
|
||||||
|
|
||||||
|
[9]: #toformat
|
||||||
|
|
||||||
|
[10]: #tile
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
||||||
|
|
||||||
|
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
|
|
||||||
|
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[17]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|||||||
@@ -2,64 +2,52 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [resize](#resize)
|
- [resize][1]
|
||||||
- [crop](#crop)
|
- [crop][2]
|
||||||
- [embed](#embed)
|
- [embed][3]
|
||||||
- [max](#max)
|
- [max][4]
|
||||||
- [min](#min)
|
- [min][5]
|
||||||
- [ignoreAspectRatio](#ignoreaspectratio)
|
- [ignoreAspectRatio][6]
|
||||||
- [withoutEnlargement](#withoutenlargement)
|
- [withoutEnlargement][7]
|
||||||
|
|
||||||
## resize
|
## resize
|
||||||
|
|
||||||
Resize image to `width` x `height`.
|
Resize image to `width` x `height`.
|
||||||
By default, the resized image is centre cropped to the exact size specified.
|
By default, the resized image is centre cropped to the exact size specified.
|
||||||
|
|
||||||
Possible reduction kernels are:
|
Possible kernels are:
|
||||||
|
|
||||||
- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
- `nearest`: Use [nearest neighbour interpolation][8].
|
||||||
- `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
- `cubic`: Use a [Catmull-Rom spline][9].
|
||||||
- `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
- `lanczos2`: Use a [Lanczos kernel][10] with `a=2`.
|
||||||
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
|
|
||||||
Possible enlargement interpolators are:
|
|
||||||
|
|
||||||
- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
|
||||||
- `bilinear`: Use [bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation), faster than bicubic but with less smooth results.
|
|
||||||
- `vertexSplitQuadraticBasisSpline`: Use the smoother [VSQBS interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48) to prevent "staircasing" when enlarging.
|
|
||||||
- `bicubic`: Use [bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default).
|
|
||||||
- `locallyBoundedBicubic`: Use [LBB interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/lbb.cpp#L100), which prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2.
|
|
||||||
- `nohalo`: Use [Nohalo interpolation](http://eprints.soton.ac.uk/268086/), which prevents acutance but typically reduces performance by a factor of 3.
|
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `width` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
- `width` **[Number][11]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
||||||
- `height` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
- `height` **[Number][11]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
||||||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
|
- `options` **[Object][12]?**
|
||||||
- `options.kernel` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
- `options.kernel` **[String][13]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
||||||
- `options.interpolator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the interpolator to use for image enlargement. (optional, default `'bicubic'`)
|
- `options.fastShrinkOnLoad` **[Boolean][14]** take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default `true`)
|
||||||
- `options.centreSampling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use \*magick centre sampling convention instead of corner sampling. (optional, default `false`)
|
|
||||||
- `options.centerSampling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** alternative spelling of centreSampling. (optional, default `false`)
|
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(inputBuffer)
|
sharp(inputBuffer)
|
||||||
.resize(200, 300, {
|
.resize(200, 300, {
|
||||||
kernel: sharp.kernel.lanczos2,
|
kernel: sharp.kernel.nearest
|
||||||
interpolator: sharp.interpolator.nohalo
|
|
||||||
})
|
})
|
||||||
.background('white')
|
.background('white')
|
||||||
.embed()
|
.embed()
|
||||||
.toFile('output.tiff')
|
.toFile('output.tiff')
|
||||||
.then(function() {
|
.then(function() {
|
||||||
// output.tiff is a 200 pixels wide and 300 pixels high image
|
// output.tiff is a 200 pixels wide and 300 pixels high image
|
||||||
// containing a lanczos2/nohalo scaled version, embedded on a white canvas,
|
// containing a nearest-neighbour scaled version, embedded on a white canvas,
|
||||||
// of the image data in inputBuffer
|
// of the image data in inputBuffer
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][15]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -73,12 +61,12 @@ Possible attributes of the optional `sharp.gravity` are `north`, `northeast`, `e
|
|||||||
The experimental strategy-based approach resizes so one dimension is at its target length
|
The experimental strategy-based approach resizes so one dimension is at its target length
|
||||||
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
||||||
|
|
||||||
- `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
- `entropy`: focus on the region with the highest [Shannon entropy][16].
|
||||||
- `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
- `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `crop` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A member of `sharp.gravity` to crop to an edge/corner or `sharp.strategy` to crop dynamically. (optional, default `'centre'`)
|
- `crop` **[String][13]** A member of `sharp.gravity` to crop to an edge/corner or `sharp.strategy` to crop dynamically. (optional, default `'centre'`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -94,7 +82,7 @@ const transformer = sharp()
|
|||||||
readableStream.pipe(transformer).pipe(writableStream);
|
readableStream.pipe(transformer).pipe(writableStream);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Invalid parameters
|
- Throws **[Error][15]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -106,6 +94,10 @@ then embed on a background of the exact `width` and `height` specified.
|
|||||||
If the background contains an alpha value then WebP and PNG format output images will
|
If the background contains an alpha value then WebP and PNG format output images will
|
||||||
contain an alpha channel, even when the input image does not.
|
contain an alpha channel, even when the input image does not.
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
- `embed` **[String][13]** A member of `sharp.gravity` to embed to an edge/corner. (optional, default `'centre'`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -123,6 +115,8 @@ sharp('input.gif')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][15]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## max
|
## max
|
||||||
@@ -169,9 +163,44 @@ Returns **Sharp**
|
|||||||
Do not enlarge the output image if the input image width _or_ height are already less than the required dimensions.
|
Do not enlarge the output image if the input image width _or_ height are already less than the required dimensions.
|
||||||
This is equivalent to GraphicsMagick's `>` geometry option:
|
This is equivalent to GraphicsMagick's `>` geometry option:
|
||||||
"_change the dimensions of the image only if its width or height exceeds the geometry specification_".
|
"_change the dimensions of the image only if its width or height exceeds the geometry specification_".
|
||||||
|
Use with `max()` to preserve the image's aspect ratio.
|
||||||
|
|
||||||
|
The default behaviour _before_ function call is `false`, meaning the image will be enlarged.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `withoutEnlargement` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `true`)
|
- `withoutEnlargement` **[Boolean][14]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
[1]: #resize
|
||||||
|
|
||||||
|
[2]: #crop
|
||||||
|
|
||||||
|
[3]: #embed
|
||||||
|
|
||||||
|
[4]: #max
|
||||||
|
|
||||||
|
[5]: #min
|
||||||
|
|
||||||
|
[6]: #ignoreaspectratio
|
||||||
|
|
||||||
|
[7]: #withoutenlargement
|
||||||
|
|
||||||
|
[8]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
|
||||||
|
|
||||||
|
[9]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
||||||
|
|
||||||
|
[10]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
|
||||||
|
|
||||||
|
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
|
[16]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [cache](#cache)
|
- [cache][1]
|
||||||
- [concurrency](#concurrency)
|
- [concurrency][2]
|
||||||
- [counters](#counters)
|
- [counters][3]
|
||||||
- [simd](#simd)
|
- [simd][4]
|
||||||
|
|
||||||
## cache
|
## cache
|
||||||
|
|
||||||
@@ -16,10 +16,10 @@ useful for determining how much working memory is required for a particular task
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `options` **([Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default `true`)
|
- `options` **([Object][5] \| [Boolean][6])** Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default `true`)
|
||||||
- `options.memory` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the maximum memory in MB to use for this cache (optional, default `50`)
|
- `options.memory` **[Number][7]** is the maximum memory in MB to use for this cache (optional, default `50`)
|
||||||
- `options.files` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the maximum number of files to hold open (optional, default `20`)
|
- `options.files` **[Number][7]** is the maximum number of files to hold open (optional, default `20`)
|
||||||
- `options.items` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the maximum number of operations to cache (optional, default `100`)
|
- `options.items` **[Number][7]** is the maximum number of operations to cache (optional, default `100`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ sharp.cache( { files: 0 } );
|
|||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
Returns **[Object][5]**
|
||||||
|
|
||||||
## concurrency
|
## concurrency
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ This method always returns the current concurrency.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `concurrency` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
- `concurrency` **[Number][7]?**
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ sharp.concurrency(2); // 2
|
|||||||
sharp.concurrency(0); // 4
|
sharp.concurrency(0); // 4
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** concurrency
|
Returns **[Number][7]** concurrency
|
||||||
|
|
||||||
## counters
|
## counters
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ Provides access to internal task counters.
|
|||||||
const counters = sharp.counters(); // { queue: 2, process: 4 }
|
const counters = sharp.counters(); // { queue: 2, process: 4 }
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
Returns **[Object][5]**
|
||||||
|
|
||||||
## simd
|
## simd
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ Versions of liborc prior to 0.4.25 are known to segfault under heavy load.
|
|||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `simd` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `false`)
|
- `simd` **[Boolean][6]** (optional, default `false`)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
@@ -103,4 +103,18 @@ const simd = sharp.simd(true);
|
|||||||
// attempts to enable the use of SIMD, returning true if available
|
// attempts to enable the use of SIMD, returning true if available
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
|
Returns **[Boolean][6]**
|
||||||
|
|
||||||
|
[1]: #cache
|
||||||
|
|
||||||
|
[2]: #concurrency
|
||||||
|
|
||||||
|
[3]: #counters
|
||||||
|
|
||||||
|
[4]: #simd
|
||||||
|
|
||||||
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|||||||
@@ -1,9 +1,117 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### v0.20 - "*prebuild*"
|
||||||
|
|
||||||
|
Requires libvips v8.6.1.
|
||||||
|
|
||||||
|
#### v0.20.2 - 28<sup>th</sup> April 2018
|
||||||
|
|
||||||
|
* Add tint operation to set image chroma.
|
||||||
|
[#825](https://github.com/lovell/sharp/pull/825)
|
||||||
|
[@rikh42](https://github.com/rikh42)
|
||||||
|
|
||||||
|
* Add environment variable to ignore globally-installed libvips.
|
||||||
|
[#1165](https://github.com/lovell/sharp/pull/1165)
|
||||||
|
[@oncletom](https://github.com/oncletom)
|
||||||
|
|
||||||
|
* Add support for page selection with multi-page input (GIF/TIFF).
|
||||||
|
[#1204](https://github.com/lovell/sharp/pull/1204)
|
||||||
|
[@woolite64](https://github.com/woolite64)
|
||||||
|
|
||||||
|
* Add support for Group4 (CCITTFAX4) compression with TIFF output.
|
||||||
|
[#1208](https://github.com/lovell/sharp/pull/1208)
|
||||||
|
[@woolite64](https://github.com/woolite64)
|
||||||
|
|
||||||
|
#### v0.20.1 - 17<sup>th</sup> March 2018
|
||||||
|
|
||||||
|
* Improve installation experience when a globally-installed libvips below the minimum required version is found.
|
||||||
|
[#1148](https://github.com/lovell/sharp/issues/1148)
|
||||||
|
|
||||||
|
* Prevent smartcrop error when cumulative rounding is below target size.
|
||||||
|
[#1154](https://github.com/lovell/sharp/issues/1154)
|
||||||
|
[@ralrom](https://github.com/ralrom)
|
||||||
|
|
||||||
|
* Expose libvips' median filter operation.
|
||||||
|
[#1161](https://github.com/lovell/sharp/pull/1161)
|
||||||
|
[@BiancoA](https://github.com/BiancoA)
|
||||||
|
|
||||||
|
#### v0.20.0 - 5<sup>th</sup> March 2018
|
||||||
|
|
||||||
|
* Add support for prebuilt sharp binaries on common platforms.
|
||||||
|
[#186](https://github.com/lovell/sharp/issues/186)
|
||||||
|
|
||||||
|
### v0.19 - "*suit*"
|
||||||
|
|
||||||
|
Requires libvips v8.6.1.
|
||||||
|
|
||||||
|
#### v0.19.1 - 24<sup>th</sup> February 2018
|
||||||
|
|
||||||
|
* Expose libvips' linear transform feature.
|
||||||
|
[#1024](https://github.com/lovell/sharp/pull/1024)
|
||||||
|
[@3epnm](https://github.com/3epnm)
|
||||||
|
|
||||||
|
* Expose angle option for tile-based output.
|
||||||
|
[#1121](https://github.com/lovell/sharp/pull/1121)
|
||||||
|
[@BiancoA](https://github.com/BiancoA)
|
||||||
|
|
||||||
|
* Prevent crop operation when image already at or below target dimensions.
|
||||||
|
[#1134](https://github.com/lovell/sharp/issues/1134)
|
||||||
|
[@pieh](https://github.com/pieh)
|
||||||
|
|
||||||
|
#### v0.19.0 - 11<sup>th</sup> January 2018
|
||||||
|
|
||||||
|
* Expose offset coordinates of strategy-based crop.
|
||||||
|
[#868](https://github.com/lovell/sharp/issues/868)
|
||||||
|
[@mirohristov-com](https://github.com/mirohristov-com)
|
||||||
|
|
||||||
|
* PNG output now defaults to adaptiveFiltering=false, compressionLevel=9
|
||||||
|
[#872](https://github.com/lovell/sharp/issues/872)
|
||||||
|
[@wmertens](https://github.com/wmertens)
|
||||||
|
|
||||||
|
* Add stats feature for pixel-derived image statistics.
|
||||||
|
[#915](https://github.com/lovell/sharp/pull/915)
|
||||||
|
[@rnanwani](https://github.com/rnanwani)
|
||||||
|
|
||||||
|
* Add failOnError option to fail-fast on bad input image data.
|
||||||
|
[#976](https://github.com/lovell/sharp/pull/976)
|
||||||
|
[@mceachen](https://github.com/mceachen)
|
||||||
|
|
||||||
|
* Resize: switch to libvips' implementation, make fastShrinkOnLoad optional, remove interpolator and centreSampling options.
|
||||||
|
[#977](https://github.com/lovell/sharp/pull/977)
|
||||||
|
[@jardakotesovec](https://github.com/jardakotesovec)
|
||||||
|
|
||||||
|
* Attach finish event listener to a clone only for Stream-based input.
|
||||||
|
[#995](https://github.com/lovell/sharp/issues/995)
|
||||||
|
[@whmountains](https://github.com/whmountains)
|
||||||
|
|
||||||
|
* Add tilecache before smartcrop to avoid over-computation of previous operations.
|
||||||
|
[#1028](https://github.com/lovell/sharp/issues/1028)
|
||||||
|
[@coffeebite](https://github.com/coffeebite)
|
||||||
|
|
||||||
|
* Prevent toFile extension taking precedence over requested format.
|
||||||
|
[#1037](https://github.com/lovell/sharp/issues/1037)
|
||||||
|
[@tomgallagher](https://github.com/tomgallagher)
|
||||||
|
|
||||||
|
* Add support for gravity option to existing embed feature.
|
||||||
|
[#1038](https://github.com/lovell/sharp/pull/1038)
|
||||||
|
[@AzureByte](https://github.com/AzureByte)
|
||||||
|
|
||||||
|
* Expose IPTC and XMP metadata when available.
|
||||||
|
[#1079](https://github.com/lovell/sharp/pull/1079)
|
||||||
|
[@oaleynik](https://github.com/oaleynik)
|
||||||
|
|
||||||
|
* TIFF output: switch default predictor from 'none' to 'horizontal' to match libvips' behaviour.
|
||||||
|
|
||||||
### v0.18 - "*ridge*"
|
### v0.18 - "*ridge*"
|
||||||
|
|
||||||
Requires libvips v8.5.5.
|
Requires libvips v8.5.5.
|
||||||
|
|
||||||
|
#### v0.18.4 - 18<sup>th</sup> September 2017
|
||||||
|
|
||||||
|
* Ensure input Buffer really is marked as Persistent, prevents mark-sweep GC.
|
||||||
|
[#950](https://github.com/lovell/sharp/issues/950)
|
||||||
|
[@lfdoherty](https://github.com/lfdoherty)
|
||||||
|
|
||||||
#### v0.18.3 - 13<sup>th</sup> September 2017
|
#### v0.18.3 - 13<sup>th</sup> September 2017
|
||||||
|
|
||||||
* Skip shrink-on-load when trimming.
|
* Skip shrink-on-load when trimming.
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ 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.
|
||||||
|
|
||||||
OS X, Windows (x64), Linux (x64, ARM) systems do not require
|
Most 64-bit OS X, Windows and Linux (glibc) systems running
|
||||||
the installation of any external runtime dependencies.
|
Node versions 4, 6, 8 and 10
|
||||||
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ are held in memory and processed at a time,
|
|||||||
taking full advantage of multiple CPU cores and L1/L2/L3 cache.
|
taking full advantage of multiple CPU cores and L1/L2/L3 cache.
|
||||||
|
|
||||||
Everything remains non-blocking thanks to _libuv_,
|
Everything remains non-blocking thanks to _libuv_,
|
||||||
no child processes are spawned and Promises/A+ are supported.
|
no child processes are spawned and Promises/async/await are supported.
|
||||||
|
|
||||||
### Optimal
|
### Optimal
|
||||||
|
|
||||||
@@ -55,9 +56,9 @@ without having to use separate command line tools like
|
|||||||
[jpegoptim](https://github.com/tjko/jpegoptim) and
|
[jpegoptim](https://github.com/tjko/jpegoptim) and
|
||||||
[jpegtran](http://jpegclub.org/jpegtran/).
|
[jpegtran](http://jpegclub.org/jpegtran/).
|
||||||
|
|
||||||
PNG filtering can be disabled,
|
PNG filtering is disabled by default,
|
||||||
which for diagrams and line art often produces the same result
|
which for diagrams and line art often produces the same result
|
||||||
as [pngcrush](http://pmt.sourceforge.net/pngcrush/).
|
as [pngcrush](https://pmt.sourceforge.io/pngcrush/).
|
||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
@@ -102,12 +103,21 @@ the help and code contributions of the following people:
|
|||||||
* [Yves Bos](https://github.com/YvesBos)
|
* [Yves Bos](https://github.com/YvesBos)
|
||||||
* [Nicolas Coden](https://github.com/ncoden)
|
* [Nicolas Coden](https://github.com/ncoden)
|
||||||
* [Matt Parrish](https://github.com/pbomb)
|
* [Matt Parrish](https://github.com/pbomb)
|
||||||
|
* [Matthew McEachen](https://github.com/mceachen)
|
||||||
|
* [Jarda Kotěšovec](https://github.com/jardakotesovec)
|
||||||
|
* [Kenric D'Souza](https://github.com/AzureByte)
|
||||||
|
* [Oleh Aleinyk](https://github.com/oaleynik)
|
||||||
|
* [Marcel Bretschneider](https://github.com/3epnm)
|
||||||
|
* [Andrea Bianco](https://github.com/BiancoA)
|
||||||
|
* [Rik Heywood](https://github.com/rikh42)
|
||||||
|
* [Thomas Parisot](https://github.com/oncletom)
|
||||||
|
* [Nathan Graves](https://github.com/woolite64)
|
||||||
|
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
### Licence
|
### Licence
|
||||||
|
|
||||||
Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
Copyright 2013, 2014, 2015, 2016, 2017, 2018 Lovell Fuller and contributors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -8,37 +8,53 @@ npm install sharp
|
|||||||
yarn add sharp
|
yarn add sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
### Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* Node v4.5.0+
|
* Node v4.5.0+
|
||||||
|
|
||||||
|
### Building from source
|
||||||
|
|
||||||
|
Pre-compiled binaries for sharp are provided for use with
|
||||||
|
Node versions 4, 6, 8 and 9 on
|
||||||
|
64-bit Windows, OS X and Linux platforms.
|
||||||
|
|
||||||
|
Sharp will be built from source at install time when:
|
||||||
|
|
||||||
|
* a globally-installed libvips is detected,
|
||||||
|
* pre-compiled binaries do not exist for the current platform and Node version, or
|
||||||
|
* when the `npm install --build-from-source` flag is used.
|
||||||
|
|
||||||
|
Building from source requires:
|
||||||
|
|
||||||
* C++11 compatible compiler such as gcc 4.8+, clang 3.0+ or MSVC 2013+
|
* C++11 compatible compiler such as gcc 4.8+, clang 3.0+ or MSVC 2013+
|
||||||
* [node-gyp](https://github.com/TooTallNate/node-gyp#installation) and its dependencies (includes Python)
|
* [node-gyp](https://github.com/TooTallNate/node-gyp#installation) and its dependencies (includes Python)
|
||||||
|
|
||||||
|
## libvips
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
[](https://travis-ci.org/lovell/sharp)
|
[](https://travis-ci.org/lovell/sharp)
|
||||||
[](https://circleci.com/gh/lovell/sharp)
|
|
||||||
|
|
||||||
libvips and its dependencies are fetched and stored within `node_modules/sharp/vendor` during `npm install`.
|
libvips and its dependencies are fetched and stored within `node_modules/sharp/vendor` during `npm install`.
|
||||||
This involves an automated HTTPS download of approximately 7MB.
|
This involves an automated HTTPS download of approximately 7MB.
|
||||||
|
|
||||||
Most recent Linux-based operating systems with glibc running on x64 and ARMv6+ CPUs should "just work", e.g.:
|
Most recent Linux-based operating systems with glibc running on x64 and ARMv6+ CPUs should "just work", e.g.:
|
||||||
|
|
||||||
* Debian 7, 8
|
* Debian 7+
|
||||||
* Ubuntu 12.04, 14.04, 16.04
|
* Ubuntu 14.04+
|
||||||
* Centos 7
|
* Centos 7+
|
||||||
* Fedora
|
* Fedora
|
||||||
* openSUSE 13.2
|
* openSUSE 13.2+
|
||||||
* Archlinux
|
* Archlinux
|
||||||
* Raspbian Jessie
|
* Raspbian Jessie
|
||||||
* Amazon Linux 2016.03, 2016.09
|
* Amazon Linux
|
||||||
* Solus
|
* Solus
|
||||||
|
|
||||||
To use a globally-installed version of libvips instead of the provided binaries,
|
To use a globally-installed version of libvips instead of the provided binaries,
|
||||||
make sure it is at least the version listed under `config.libvips` in the `package.json` file
|
make sure it is at least the version listed under `config.libvips` in the `package.json` file
|
||||||
and that it can be located using `pkg-config --modversion vips-cpp`.
|
and that it can be located using `pkg-config --modversion vips-cpp`.
|
||||||
|
|
||||||
If you are using non-stadard paths (anything other than `/usr` or `/usr/local`),
|
If you are using non-standard paths (anything other than `/usr` or `/usr/local`),
|
||||||
you might need to set `PKG_CONFIG_PATH` during `npm install`
|
you might need to set `PKG_CONFIG_PATH` during `npm install`
|
||||||
and `LD_LIBRARY_PATH` at runtime.
|
and `LD_LIBRARY_PATH` at runtime.
|
||||||
|
|
||||||
@@ -64,7 +80,7 @@ via `sharp.cache(false)` to avoid a stack overflow.
|
|||||||
|
|
||||||
### Mac OS
|
### Mac OS
|
||||||
|
|
||||||
[](https://travis-ci.org/lovell/sharp)
|
[](https://travis-ci.org/lovell/sharp)
|
||||||
|
|
||||||
libvips and its dependencies are fetched and stored within `node_modules/sharp/vendor` during `npm install`.
|
libvips and its dependencies are fetched and stored within `node_modules/sharp/vendor` during `npm install`.
|
||||||
This involves an automated HTTPS download of approximately 7MB.
|
This involves an automated HTTPS download of approximately 7MB.
|
||||||
@@ -78,14 +94,19 @@ that it can be located using `pkg-config --modversion vips-cpp`.
|
|||||||
[](https://ci.appveyor.com/project/lovell/sharp)
|
[](https://ci.appveyor.com/project/lovell/sharp)
|
||||||
|
|
||||||
libvips and its dependencies are fetched and stored within `node_modules\sharp\vendor` during `npm install`.
|
libvips and its dependencies are fetched and stored within `node_modules\sharp\vendor` during `npm install`.
|
||||||
This involves an automated HTTPS download of approximately 11MB.
|
This involves an automated HTTPS download of approximately 12MB.
|
||||||
|
|
||||||
Only 64-bit (x64) `node.exe` is supported.
|
Only 64-bit (x64) `node.exe` is supported.
|
||||||
|
|
||||||
### FreeBSD
|
### FreeBSD
|
||||||
|
|
||||||
libvips must be installed before `npm install` is run.
|
libvips must be installed before `npm install` is run.
|
||||||
This can be achieved via [FreshPorts](https://www.freshports.org/graphics/vips/):
|
|
||||||
|
This can be achieved via package or ports:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pkg install -y pkgconf vips
|
||||||
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd /usr/ports/graphics/vips/ && make install clean
|
cd /usr/ports/graphics/vips/ && make install clean
|
||||||
@@ -127,36 +148,28 @@ docker pull tailor/docker-libvips
|
|||||||
|
|
||||||
### AWS Lambda
|
### AWS Lambda
|
||||||
|
|
||||||
In order to use sharp on AWS Lambda, you need to [create a deployment package](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html). Because sharp
|
A [deployment package](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html) for the
|
||||||
downloads and links libraries for the current platform during `npm install` you have to
|
[Lambda Execution Environment](http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html)
|
||||||
do this on a system similar to the [Lambda Execution Environment](http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html). The easiest ways to do this, is to setup a
|
can be built using Docker.
|
||||||
small t2.micro instance using the AMI ID listed in the previous link, ssh into it as ec2-user
|
|
||||||
and follow the instructions below.
|
|
||||||
|
|
||||||
Install dependencies:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
curl -s https://rpm.nodesource.com/setup_4.x | sudo bash -
|
rm -rf node_modules/sharp
|
||||||
sudo yum install -y gcc-c++ nodejs
|
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs6.10 npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Copy your code and package.json to the instance using `scp` and create a deployment package:
|
Set the Lambda runtime to Node.js 6.10.
|
||||||
|
|
||||||
```sh
|
To get the best performance select the largest memory available. A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
||||||
cd sharp-lambda-example
|
|
||||||
npm install
|
|
||||||
zip -ur9 ../sharp-lambda-example.zip index.js node_modules
|
|
||||||
```
|
|
||||||
|
|
||||||
You can now download your deployment ZIP using `scp` and upload it to Lambda. Be sure to set your Lambda runtime to Node.js 4.3.
|
|
||||||
|
|
||||||
**Performance Tip:** To get the best performance on Lambda choose the largest memory available because this also gives you the most cpu time (a 1536 MB function is 12x faster than a 128 MB function).
|
|
||||||
|
|
||||||
### Build tools
|
### Build tools
|
||||||
|
|
||||||
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
||||||
* [grunt-sharp](https://www.npmjs.com/package/grunt-sharp)
|
* [grunt-sharp](https://www.npmjs.com/package/grunt-sharp)
|
||||||
|
|
||||||
|
### Coding tools
|
||||||
|
|
||||||
|
* [Sharp TypeScript Types](https://www.npmjs.com/package/@types/sharp)
|
||||||
|
|
||||||
### CLI tools
|
### CLI tools
|
||||||
|
|
||||||
* [sharp-cli](https://www.npmjs.com/package/sharp-cli)
|
* [sharp-cli](https://www.npmjs.com/package/sharp-cli)
|
||||||
@@ -198,13 +211,20 @@ to the directory containing the `policy.xml` file.
|
|||||||
|
|
||||||
### Pre-compiled libvips binaries
|
### Pre-compiled libvips binaries
|
||||||
|
|
||||||
If a global installation of libvips that meets the
|
This module will attempt to download a pre-compiled bundle of libvips
|
||||||
minimum version requirement cannot be found,
|
and its dependencies on Linux and Windows machines under either of these
|
||||||
this module will attempt to download a pre-compiled bundle of libvips
|
conditions:
|
||||||
and its dependencies on Linux and Windows machines.
|
|
||||||
|
1. If a global installation of libvips that meets the
|
||||||
|
minimum version requirement cannot be found;
|
||||||
|
1. If `SHARP_IGNORE_GLOBAL_LIBVIPS` environment variable is set.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install sharp
|
||||||
|
```
|
||||||
|
|
||||||
Should you need to manually download and inspect these files,
|
Should you need to manually download and inspect these files,
|
||||||
you can do so via https://dl.bintray.com/lovell/sharp/
|
you can do so via https://github.com/lovell/sharp-libvips/releases
|
||||||
|
|
||||||
Should you wish to install these from your own location,
|
Should you wish to install these from your own location,
|
||||||
set the `SHARP_DIST_BASE_URL` environment variable, e.g.
|
set the `SHARP_DIST_BASE_URL` environment variable, e.g.
|
||||||
|
|||||||
@@ -2,19 +2,20 @@
|
|||||||
|
|
||||||
### Test environment
|
### Test environment
|
||||||
|
|
||||||
* AWS EC2 eu-central-1 [c4.xlarge](http://aws.amazon.com/ec2/instance-types/#c4) (4x E5-2666 v3 @ 2.90GHz)
|
* AWS EC2 eu-west-1 [c5.large](https://aws.amazon.com/ec2/instance-types/c5/) (2x Xeon Platinum 8124M CPU @ 3.00GHz)
|
||||||
* Ubuntu 16.04.1 LTS (HVM, SSD, 20161115, ami-82cf0aed)
|
* Ubuntu 17.10 (hvm:ebs-ssd, 20180102, ami-0741d47e)
|
||||||
* Node.js v6.9.1
|
* Node.js v8.9.4
|
||||||
|
|
||||||
### The contenders
|
### The contenders
|
||||||
|
|
||||||
* [jimp](https://www.npmjs.com/package/jimp) v0.2.27 - Image processing in pure JavaScript. Bilinear interpolation only.
|
* [jimp](https://www.npmjs.com/package/jimp) v0.2.28 - Image processing in pure JavaScript. Bilinear interpolation only.
|
||||||
* [lwip](https://www.npmjs.com/package/lwip) v0.0.9 - Wrapper around CImg. Compiles outdated, insecure dependencies from source.
|
* [pajk-lwip](https://www.npmjs.com/package/pajk-lwip) v0.2.0 (fork) - Wrapper around CImg that compiles dependencies from source.
|
||||||
* [mapnik](https://www.npmjs.org/package/mapnik) v3.5.14 - Whilst primarily a map renderer, Mapnik contains bitmap image utilities.
|
* [mapnik](https://www.npmjs.org/package/mapnik) v3.6.2 - Whilst primarily a map renderer, Mapnik contains bitmap image utilities.
|
||||||
* [imagemagick-native](https://www.npmjs.com/package/imagemagick-native) v1.9.3 - Wrapper around libmagick++, supports Buffers only.
|
* [imagemagick-native](https://www.npmjs.com/package/imagemagick-native) v1.9.3 - Wrapper around libmagick++, supports Buffers only.
|
||||||
* [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.0 - 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.17.0 / libvips v8.4.2 - Caching within libvips disabled to ensure a fair comparison.
|
* [images](https://www.npmjs.com/package/images) v3.0.1 - Compiles dependencies from source. Provides bicubic interpolation.
|
||||||
|
* sharp v0.19.0 / libvips v8.6.1 - Caching within libvips disabled to ensure a fair comparison.
|
||||||
|
|
||||||
### The task
|
### The task
|
||||||
|
|
||||||
@@ -26,18 +27,19 @@ then compress to JPEG at a "quality" setting of 80.
|
|||||||
|
|
||||||
| Module | Input | Output | Ops/sec | Speed-up |
|
| Module | Input | Output | Ops/sec | Speed-up |
|
||||||
| :----------------- | :----- | :----- | ------: | -------: |
|
| :----------------- | :----- | :----- | ------: | -------: |
|
||||||
| jimp (bilinear) | buffer | buffer | 1.06 | 1.0 |
|
| jimp (bilinear) | buffer | buffer | 1.14 | 1.0 |
|
||||||
| lwip | buffer | buffer | 1.87 | 1.8 |
|
| lwip | buffer | buffer | 1.86 | 1.6 |
|
||||||
| mapnik | buffer | buffer | 2.91 | 2.7 |
|
| mapnik | buffer | buffer | 3.34 | 2.9 |
|
||||||
| imagemagick-native | buffer | buffer | 4.03 | 3.8 |
|
| imagemagick-native | buffer | buffer | 4.13 | 3.6 |
|
||||||
| imagemagick | file | file | 7.10 | 6.7 |
|
| gm | buffer | buffer | 4.21 | 3.7 |
|
||||||
| gm | buffer | buffer | 7.08 | 6.7 |
|
| gm | file | file | 4.27 | 3.7 |
|
||||||
| gm | file | file | 7.10 | 6.7 |
|
| imagemagick | file | file | 4.67 | 4.1 |
|
||||||
| sharp | stream | stream | 27.61 | 26.0 |
|
| images (bicubic) | file | file | 6.22 | 5.5 |
|
||||||
| sharp | file | file | 28.41 | 26.8 |
|
| sharp | stream | stream | 24.43 | 21.4 |
|
||||||
| sharp | buffer | file | 28.71 | 27.1 |
|
| sharp | file | file | 25.97 | 22.7 |
|
||||||
| sharp | file | buffer | 28.60 | 27.0 |
|
| sharp | file | buffer | 26.00 | 22.8 |
|
||||||
| sharp | buffer | buffer | 29.08 | 27.4 |
|
| sharp | buffer | file | 26.33 | 23.0 |
|
||||||
|
| sharp | buffer | buffer | 26.43 | 23.1 |
|
||||||
|
|
||||||
Greater libvips performance can be expected with caching enabled (default)
|
Greater libvips performance can be expected with caching enabled (default)
|
||||||
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
||||||
@@ -46,19 +48,20 @@ The I/O limits of the relevant (de)compression library will generally determine
|
|||||||
|
|
||||||
### Benchmark test prerequisites
|
### Benchmark test prerequisites
|
||||||
|
|
||||||
Requires both _ImageMagick_ and _GraphicsMagick_:
|
Requires _ImageMagick_, _GraphicsMagick_ and _Mapnik_:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
brew install imagemagick
|
brew install imagemagick
|
||||||
brew install graphicsmagick
|
brew install graphicsmagick
|
||||||
|
brew install mapnik
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo apt-get install imagemagick libmagick++-dev graphicsmagick
|
sudo apt-get install imagemagick libmagick++-dev graphicsmagick mapnik-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo yum install ImageMagick-devel ImageMagick-c++-devel GraphicsMagick
|
sudo yum install ImageMagick-devel ImageMagick-c++-devel GraphicsMagick mapnik-devel
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running the benchmark test
|
### Running the benchmark test
|
||||||
|
|||||||
34
install/dll-copy.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const copyFileSync = require('fs-copy-file-sync');
|
||||||
|
const npmLog = require('npmlog');
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const buildDir = path.join(__dirname, '..', 'build');
|
||||||
|
const buildReleaseDir = path.join(buildDir, 'Release');
|
||||||
|
npmLog.info('sharp', `Creating ${buildReleaseDir}`);
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(buildDir);
|
||||||
|
fs.mkdirSync(buildReleaseDir);
|
||||||
|
} catch (err) {}
|
||||||
|
const vendorLibDir = path.join(__dirname, '..', 'vendor', 'lib');
|
||||||
|
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
||||||
|
try {
|
||||||
|
fs
|
||||||
|
.readdirSync(vendorLibDir)
|
||||||
|
.filter(function (filename) {
|
||||||
|
return /\.dll$/.test(filename);
|
||||||
|
})
|
||||||
|
.forEach(function (filename) {
|
||||||
|
copyFileSync(
|
||||||
|
path.join(vendorLibDir, filename),
|
||||||
|
path.join(buildReleaseDir, filename)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
npmLog.error('sharp', err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
install/libvips.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const detectLibc = require('detect-libc');
|
||||||
|
const npmLog = require('npmlog');
|
||||||
|
const semver = require('semver');
|
||||||
|
const simpleGet = require('simple-get');
|
||||||
|
const tar = require('tar');
|
||||||
|
|
||||||
|
const agent = require('../lib/agent');
|
||||||
|
const libvips = require('../lib/libvips');
|
||||||
|
const platform = require('../lib/platform');
|
||||||
|
|
||||||
|
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||||
|
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||||
|
if (useGlobalLibvips) {
|
||||||
|
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
||||||
|
npmLog.info('sharp', `Detected globally-installed libvips v${globalLibvipsVersion}`);
|
||||||
|
npmLog.info('sharp', 'Building from source via node-gyp');
|
||||||
|
process.exit(1);
|
||||||
|
} else if (libvips.hasVendoredLibvips()) {
|
||||||
|
npmLog.info('sharp', `Using existing vendored libvips v${minimumLibvipsVersion}`);
|
||||||
|
} else {
|
||||||
|
// Is this arch/platform supported?
|
||||||
|
const arch = process.env.npm_config_arch || process.arch;
|
||||||
|
if (platform() === 'win32-ia32') {
|
||||||
|
throw new Error('Windows x86 (32-bit) node.exe is not supported');
|
||||||
|
}
|
||||||
|
if (arch === 'ia32') {
|
||||||
|
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}\n`);
|
||||||
|
}
|
||||||
|
if (detectLibc.isNonGlibcLinux) {
|
||||||
|
throw new Error(`Use with ${detectLibc.family} libc requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
|
}
|
||||||
|
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && semver.lt(`${detectLibc.version}.0`, '2.13.0')) {
|
||||||
|
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
|
}
|
||||||
|
// Download to per-process temporary file
|
||||||
|
const tarFilename = ['libvips', minimumLibvipsVersion, platform()].join('-') + '.tar.gz';
|
||||||
|
const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`);
|
||||||
|
const tmpFile = fs.createWriteStream(tarPathTemp);
|
||||||
|
const url = distBaseUrl + tarFilename;
|
||||||
|
npmLog.info('sharp', `Downloading ${url}`);
|
||||||
|
simpleGet({ url: url, agent: agent() }, function (err, response) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
throw new Error(`Status ${response.statusCode}`);
|
||||||
|
}
|
||||||
|
response.pipe(tmpFile);
|
||||||
|
});
|
||||||
|
tmpFile.on('close', function () {
|
||||||
|
const vendorPath = path.join(__dirname, '..', 'vendor');
|
||||||
|
fs.mkdirSync(vendorPath);
|
||||||
|
tar
|
||||||
|
.extract({
|
||||||
|
file: tarPathTemp,
|
||||||
|
cwd: vendorPath,
|
||||||
|
strict: true
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(tarPathTemp);
|
||||||
|
} catch (err) {}
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
npmLog.error('sharp', err.message);
|
||||||
|
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
37
lib/agent.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const url = require('url');
|
||||||
|
const tunnelAgent = require('tunnel-agent');
|
||||||
|
|
||||||
|
const is = require('./is');
|
||||||
|
|
||||||
|
const proxies = [
|
||||||
|
'HTTPS_PROXY',
|
||||||
|
'https_proxy',
|
||||||
|
'HTTP_PROXY',
|
||||||
|
'http_proxy',
|
||||||
|
'npm_config_https_proxy',
|
||||||
|
'npm_config_proxy'
|
||||||
|
];
|
||||||
|
|
||||||
|
function env (key) {
|
||||||
|
return process.env[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = function () {
|
||||||
|
try {
|
||||||
|
const proxy = url.parse(proxies.map(env).find(is.string));
|
||||||
|
const tunnel = proxy.protocol === 'https:'
|
||||||
|
? tunnelAgent.httpsOverHttps
|
||||||
|
: tunnelAgent.httpsOverHttp;
|
||||||
|
return tunnel({
|
||||||
|
proxy: {
|
||||||
|
port: Number(proxy.port),
|
||||||
|
host: proxy.hostname,
|
||||||
|
proxyAuth: proxy.auth
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -38,6 +38,21 @@ function background (rgba) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tint the image using the provided chroma while preserving the image luminance.
|
||||||
|
* An alpha channel may be present and will be unchanged by the operation.
|
||||||
|
*
|
||||||
|
* @param {String|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameter
|
||||||
|
*/
|
||||||
|
function tint (rgb) {
|
||||||
|
const colour = color(rgb);
|
||||||
|
this.options.tintA = colour.a();
|
||||||
|
this.options.tintB = colour.b();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to 8-bit greyscale; 256 shades of grey.
|
* Convert to 8-bit greyscale; 256 shades of grey.
|
||||||
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||||
@@ -95,6 +110,7 @@ module.exports = function (Sharp) {
|
|||||||
// Public instance functions
|
// Public instance functions
|
||||||
[
|
[
|
||||||
background,
|
background,
|
||||||
|
tint,
|
||||||
greyscale,
|
greyscale,
|
||||||
grayscale,
|
grayscale,
|
||||||
toColourspace,
|
toColourspace,
|
||||||
|
|||||||
@@ -6,8 +6,24 @@ const stream = require('stream');
|
|||||||
const events = require('events');
|
const events = require('events');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
const platform = require('./platform');
|
||||||
const sharp = require('../build/Release/sharp.node');
|
const sharp = require('../build/Release/sharp.node');
|
||||||
|
|
||||||
|
// Vendor platform
|
||||||
|
(function () {
|
||||||
|
let vendorPlatformId;
|
||||||
|
try {
|
||||||
|
vendorPlatformId = require('../vendor/platform.json');
|
||||||
|
} catch (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentPlatformId = platform();
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (currentPlatformId !== vendorPlatformId) {
|
||||||
|
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm rebuild'.`);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
// Versioning
|
// Versioning
|
||||||
let versions = {
|
let versions = {
|
||||||
vips: sharp.libvipsVersion()
|
vips: sharp.libvipsVersion()
|
||||||
@@ -21,7 +37,7 @@ let versions = {
|
|||||||
}
|
}
|
||||||
// Include versions of dependencies, if present
|
// Include versions of dependencies, if present
|
||||||
try {
|
try {
|
||||||
versions = require('../vendor/lib/versions.json');
|
versions = require('../vendor/versions.json');
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -77,7 +93,11 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
* a String containing the 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=false] - by default apply a "best effort"
|
||||||
|
* to decode images, even if the data is corrupt or invalid. Set this flag to true
|
||||||
|
* if you'd rather halt processing and raise an error when loading invalid images.
|
||||||
* @param {Number} [options.density=72] - integral number representing the DPI for vector images.
|
* @param {Number} [options.density=72] - integral number representing the DPI for vector images.
|
||||||
|
* @param {Number} [options.page=0] - page number to extract for multi-page input (GIF, TIFF)
|
||||||
* @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]
|
||||||
@@ -117,6 +137,7 @@ const Sharp = function (input, options) {
|
|||||||
height: -1,
|
height: -1,
|
||||||
canvas: 'crop',
|
canvas: 'crop',
|
||||||
crop: 0,
|
crop: 0,
|
||||||
|
embed: 0,
|
||||||
useExifOrientation: false,
|
useExifOrientation: false,
|
||||||
angle: 0,
|
angle: 0,
|
||||||
rotateBeforePreExtract: false,
|
rotateBeforePreExtract: false,
|
||||||
@@ -128,12 +149,14 @@ const Sharp = function (input, options) {
|
|||||||
extendRight: 0,
|
extendRight: 0,
|
||||||
withoutEnlargement: false,
|
withoutEnlargement: false,
|
||||||
kernel: 'lanczos3',
|
kernel: 'lanczos3',
|
||||||
interpolator: 'bicubic',
|
fastShrinkOnLoad: true,
|
||||||
centreSampling: false,
|
|
||||||
// operations
|
// operations
|
||||||
background: [0, 0, 0, 255],
|
background: [0, 0, 0, 255],
|
||||||
|
tintA: 0,
|
||||||
|
tintB: 0,
|
||||||
flatten: false,
|
flatten: false,
|
||||||
negate: false,
|
negate: false,
|
||||||
|
medianSize: 0,
|
||||||
blurSigma: 0,
|
blurSigma: 0,
|
||||||
sharpenSigma: 0,
|
sharpenSigma: 0,
|
||||||
sharpenFlat: 1,
|
sharpenFlat: 1,
|
||||||
@@ -170,20 +193,22 @@ const Sharp = function (input, options) {
|
|||||||
jpegOvershootDeringing: false,
|
jpegOvershootDeringing: false,
|
||||||
jpegOptimiseScans: false,
|
jpegOptimiseScans: false,
|
||||||
pngProgressive: false,
|
pngProgressive: false,
|
||||||
pngCompressionLevel: 6,
|
pngCompressionLevel: 9,
|
||||||
pngAdaptiveFiltering: true,
|
pngAdaptiveFiltering: false,
|
||||||
webpQuality: 80,
|
webpQuality: 80,
|
||||||
webpAlphaQuality: 100,
|
webpAlphaQuality: 100,
|
||||||
webpLossless: false,
|
webpLossless: false,
|
||||||
webpNearLossless: false,
|
webpNearLossless: false,
|
||||||
tiffQuality: 80,
|
tiffQuality: 80,
|
||||||
tiffCompression: 'jpeg',
|
tiffCompression: 'jpeg',
|
||||||
tiffPredictor: 'none',
|
tiffPredictor: 'horizontal',
|
||||||
tiffSquash: false,
|
tiffSquash: false,
|
||||||
tiffXres: 1.0,
|
tiffXres: 1.0,
|
||||||
tiffYres: 1.0,
|
tiffYres: 1.0,
|
||||||
tileSize: 256,
|
tileSize: 256,
|
||||||
tileOverlap: 0,
|
tileOverlap: 0,
|
||||||
|
linearA: 1,
|
||||||
|
linearB: 0,
|
||||||
// Function to notify of libvips warnings
|
// Function to notify of libvips warnings
|
||||||
debuglog: debuglog,
|
debuglog: debuglog,
|
||||||
// Function to notify of queue length changes
|
// Function to notify of queue length changes
|
||||||
|
|||||||
20
lib/index.js
@@ -1,17 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Sharp = require('./constructor');
|
const Sharp = require('./constructor');
|
||||||
[
|
require('./input')(Sharp);
|
||||||
'input',
|
require('./resize')(Sharp);
|
||||||
'resize',
|
require('./composite')(Sharp);
|
||||||
'composite',
|
require('./operation')(Sharp);
|
||||||
'operation',
|
require('./colour')(Sharp);
|
||||||
'colour',
|
require('./channel')(Sharp);
|
||||||
'channel',
|
require('./output')(Sharp);
|
||||||
'output',
|
require('./utility')(Sharp);
|
||||||
'utility'
|
|
||||||
].forEach(function (decorator) {
|
|
||||||
require('./' + decorator)(Sharp);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Sharp;
|
module.exports = Sharp;
|
||||||
|
|||||||
96
lib/input.js
@@ -9,7 +9,7 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||||
const inputDescriptor = {};
|
const inputDescriptor = { failOnError: false };
|
||||||
if (is.string(input)) {
|
if (is.string(input)) {
|
||||||
// filesystem
|
// filesystem
|
||||||
inputDescriptor.file = input;
|
inputDescriptor.file = input;
|
||||||
@@ -26,6 +26,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw new Error('Unsupported input ' + typeof input);
|
throw new Error('Unsupported input ' + typeof input);
|
||||||
}
|
}
|
||||||
if (is.object(inputOptions)) {
|
if (is.object(inputOptions)) {
|
||||||
|
// Fail on error
|
||||||
|
if (is.defined(inputOptions.failOnError)) {
|
||||||
|
if (is.bool(inputOptions.failOnError)) {
|
||||||
|
inputDescriptor.failOnError = inputOptions.failOnError;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid failOnError (boolean) ' + inputOptions.failOnError);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Density
|
// Density
|
||||||
if (is.defined(inputOptions.density)) {
|
if (is.defined(inputOptions.density)) {
|
||||||
if (is.integer(inputOptions.density) && is.inRange(inputOptions.density, 1, 2400)) {
|
if (is.integer(inputOptions.density) && is.inRange(inputOptions.density, 1, 2400)) {
|
||||||
@@ -49,6 +57,12 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw new Error('Expected width, height and channels for raw pixel input');
|
throw new Error('Expected width, height and channels for raw pixel input');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Page input for multi-page TIFF
|
||||||
|
if (is.defined(inputOptions.page)) {
|
||||||
|
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
||||||
|
inputDescriptor.page = inputOptions.page;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (is.defined(inputOptions.create)) {
|
if (is.defined(inputOptions.create)) {
|
||||||
if (
|
if (
|
||||||
@@ -147,12 +161,14 @@ function clone () {
|
|||||||
const clone = this.constructor.call();
|
const clone = this.constructor.call();
|
||||||
clone.options = Object.assign({}, this.options);
|
clone.options = Object.assign({}, this.options);
|
||||||
// Pass 'finish' event to clone for Stream-based input
|
// Pass 'finish' event to clone for Stream-based input
|
||||||
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', function () {
|
this.on('finish', function () {
|
||||||
// Clone inherits input data
|
// Clone inherits input data
|
||||||
that._flattenBufferIn();
|
that._flattenBufferIn();
|
||||||
clone.options.bufferIn = that.options.bufferIn;
|
clone.options.bufferIn = that.options.bufferIn;
|
||||||
clone.emit('finish');
|
clone.emit('finish');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +177,8 @@ function clone () {
|
|||||||
* A Promises/A+ promise is returned when `callback` is not provided.
|
* A Promises/A+ promise is returned when `callback` is not provided.
|
||||||
*
|
*
|
||||||
* - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
* - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||||
* - `width`: Number of pixels wide
|
* - `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
|
||||||
* - `height`: Number of pixels high
|
* - `height`: Number of pixels high (EXIF orientation is not taken into consideration)
|
||||||
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636)
|
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636)
|
||||||
* - `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
* - `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||||
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672)
|
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672)
|
||||||
@@ -172,6 +188,8 @@ function clone () {
|
|||||||
* - `orientation`: Number value of the EXIF Orientation header, if present
|
* - `orientation`: Number value of the EXIF Orientation header, if present
|
||||||
* - `exif`: Buffer containing raw EXIF data, if present
|
* - `exif`: Buffer containing raw EXIF data, if present
|
||||||
* - `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
* - `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
||||||
|
* - `iptc`: Buffer containing raw IPTC data, if present
|
||||||
|
* - `xmp`: Buffer containing raw XMP data, if present
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const image = sharp(inputJpg);
|
* const image = sharp(inputJpg);
|
||||||
@@ -230,6 +248,74 @@ function metadata (callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access to pixel-derived image statistics for every channel in the image.
|
||||||
|
* A Promise is returned when `callback` is not provided.
|
||||||
|
*
|
||||||
|
* - `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||||
|
* - `min` (minimum value in the channel)
|
||||||
|
* - `max` (maximum value in the channel)
|
||||||
|
* - `sum` (sum of all values in a channel)
|
||||||
|
* - `squaresSum` (sum of squared values in a channel)
|
||||||
|
* - `mean` (mean of the values in a channel)
|
||||||
|
* - `stdev` (standard deviation for the values in a channel)
|
||||||
|
* - `minX` (x-coordinate of one of the pixel where the minimum lies)
|
||||||
|
* - `minY` (y-coordinate of one of the pixel where the minimum lies)
|
||||||
|
* - `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||||
|
* - `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||||
|
* - `isOpaque`: Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const image = sharp(inputJpg);
|
||||||
|
* image
|
||||||
|
* .stats()
|
||||||
|
* .then(function(stats) {
|
||||||
|
* // stats contains the channel-wise statistics array and the isOpaque value
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @param {Function} [callback] - called with the arguments `(err, stats)`
|
||||||
|
* @returns {Promise<Object>}
|
||||||
|
*/
|
||||||
|
function stats (callback) {
|
||||||
|
const that = this;
|
||||||
|
if (is.fn(callback)) {
|
||||||
|
if (this._isStreamInput()) {
|
||||||
|
this.on('finish', function () {
|
||||||
|
that._flattenBufferIn();
|
||||||
|
sharp.stats(that.options, callback);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sharp.stats(this.options, callback);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
if (this._isStreamInput()) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
that.on('finish', function () {
|
||||||
|
that._flattenBufferIn();
|
||||||
|
sharp.stats(that.options, function (err, stats) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(stats);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
sharp.stats(that.options, function (err, stats) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(stats);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do not process input images where the number of pixels (width * height) exceeds this limit.
|
* Do not process input images where the number of pixels (width * height) exceeds this limit.
|
||||||
* Assumes image dimensions contained in the input metadata can be trusted.
|
* Assumes image dimensions contained in the input metadata can be trusted.
|
||||||
@@ -256,6 +342,9 @@ function limitInputPixels (limit) {
|
|||||||
/**
|
/**
|
||||||
* An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`.
|
* An advanced setting that switches the libvips access method to `VIPS_ACCESS_SEQUENTIAL`.
|
||||||
* This will reduce memory usage and can improve performance on some systems.
|
* This will reduce memory usage and can improve performance on some systems.
|
||||||
|
*
|
||||||
|
* The default behaviour *before* function call is `false`, meaning the libvips access method is not sequential.
|
||||||
|
*
|
||||||
* @param {Boolean} [sequentialRead=true]
|
* @param {Boolean} [sequentialRead=true]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
@@ -278,6 +367,7 @@ module.exports = function (Sharp) {
|
|||||||
// Public
|
// Public
|
||||||
clone,
|
clone,
|
||||||
metadata,
|
metadata,
|
||||||
|
stats,
|
||||||
limitInputPixels,
|
limitInputPixels,
|
||||||
sequentialRead
|
sequentialRead
|
||||||
].forEach(function (f) {
|
].forEach(function (f) {
|
||||||
|
|||||||
63
lib/libvips.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const spawnSync = require('child_process').spawnSync;
|
||||||
|
const semver = require('semver');
|
||||||
|
const platform = require('./platform');
|
||||||
|
|
||||||
|
const minimumLibvipsVersion = process.env.npm_package_config_libvips || require('../package.json').config.libvips;
|
||||||
|
|
||||||
|
const spawnSyncOptions = {
|
||||||
|
encoding: 'utf8',
|
||||||
|
shell: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const globalLibvipsVersion = function () {
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout || '';
|
||||||
|
return globalLibvipsVersion.trim();
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasVendoredLibvips = function () {
|
||||||
|
const currentPlatformId = platform();
|
||||||
|
try {
|
||||||
|
const vendorPlatformId = require(path.join(__dirname, '..', 'vendor', 'platform.json'));
|
||||||
|
if (currentPlatformId === vendorPlatformId) {
|
||||||
|
return true;
|
||||||
|
} 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'.`);
|
||||||
|
}
|
||||||
|
} catch (err) {}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const pkgConfigPath = function () {
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
const brewPkgConfigPath = spawnSync('which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR', spawnSyncOptions).stdout || '';
|
||||||
|
return [brewPkgConfigPath.trim(), process.env.PKG_CONFIG_PATH, '/usr/local/lib/pkgconfig', '/usr/lib/pkgconfig']
|
||||||
|
.filter(function (p) { return !!p; })
|
||||||
|
.join(':');
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const useGlobalLibvips = function () {
|
||||||
|
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
|
return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
minimumLibvipsVersion: minimumLibvipsVersion,
|
||||||
|
globalLibvipsVersion: globalLibvipsVersion,
|
||||||
|
hasVendoredLibvips: hasVendoredLibvips,
|
||||||
|
pkgConfigPath: pkgConfigPath,
|
||||||
|
useGlobalLibvips: useGlobalLibvips
|
||||||
|
};
|
||||||
@@ -156,6 +156,26 @@ function sharpen (sigma, flat, jagged) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply median filter.
|
||||||
|
* When used without parameters the default window is 3x3.
|
||||||
|
* @param {Number} [size=3] square mask size: size x size
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function median (size) {
|
||||||
|
if (!is.defined(size)) {
|
||||||
|
// No arguments: default to 3x3
|
||||||
|
this.options.medianSize = 3;
|
||||||
|
} else if (is.integer(size) && is.inRange(size, 1, 1000)) {
|
||||||
|
// Numeric argument: specific sigma
|
||||||
|
this.options.medianSize = size;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid median size ' + size);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blur the image.
|
* Blur the image.
|
||||||
* When used without parameters, performs a fast, mild blur of the output image.
|
* When used without parameters, performs a fast, mild blur of the output image.
|
||||||
@@ -406,6 +426,33 @@ function boolean (operand, operator, options) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the linear formula a * input + b to the image (levels adjustment)
|
||||||
|
* @param {Number} [a=1.0] multiplier
|
||||||
|
* @param {Number} [b=0.0] offset
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function linear (a, b) {
|
||||||
|
if (!is.defined(a)) {
|
||||||
|
this.options.linearA = 1.0;
|
||||||
|
} else if (is.number(a)) {
|
||||||
|
this.options.linearA = a;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid linear transform multiplier ' + a);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is.defined(b)) {
|
||||||
|
this.options.linearB = 0.0;
|
||||||
|
} else if (is.number(b)) {
|
||||||
|
this.options.linearB = b;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid linear transform offset ' + b);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with operation-related functions.
|
* Decorate the Sharp prototype with operation-related functions.
|
||||||
* @private
|
* @private
|
||||||
@@ -417,6 +464,7 @@ module.exports = function (Sharp) {
|
|||||||
flip,
|
flip,
|
||||||
flop,
|
flop,
|
||||||
sharpen,
|
sharpen,
|
||||||
|
median,
|
||||||
blur,
|
blur,
|
||||||
extend,
|
extend,
|
||||||
flatten,
|
flatten,
|
||||||
@@ -427,7 +475,8 @@ module.exports = function (Sharp) {
|
|||||||
normalize,
|
normalize,
|
||||||
convolve,
|
convolve,
|
||||||
threshold,
|
threshold,
|
||||||
boolean
|
boolean,
|
||||||
|
linear
|
||||||
].forEach(function (f) {
|
].forEach(function (f) {
|
||||||
Sharp.prototype[f.name] = f;
|
Sharp.prototype[f.name] = f;
|
||||||
});
|
});
|
||||||
|
|||||||
115
lib/output.js
@@ -10,12 +10,23 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
* with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
|
* with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
|
||||||
* Note that raw pixel data is only supported for buffer output.
|
* Note that raw pixel data is only supported for buffer output.
|
||||||
*
|
*
|
||||||
* A Promises/A+ promise is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toFile('output.png', (err, info) => { ... });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toFile('output.png')
|
||||||
|
* .then(info => { ... })
|
||||||
|
* .catch(err => { ... });
|
||||||
*
|
*
|
||||||
* @param {String} fileOut - the path to write the image data to.
|
* @param {String} fileOut - the path to write the image data to.
|
||||||
* @param {Function} [callback] - called on completion with two arguments `(err, info)`.
|
* @param {Function} [callback] - called on completion with two arguments `(err, info)`.
|
||||||
* `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
* `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
|
* When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
* @returns {Promise<Object>} - when no callback is provided
|
* @returns {Promise<Object>} - when no callback is provided
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -53,7 +64,25 @@ function toFile (fileOut, callback) {
|
|||||||
* - `data` is the output image data.
|
* - `data` is the output image data.
|
||||||
* - `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
* - `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
* A Promise is returned when `callback` is not provided.
|
* When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
*
|
||||||
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toBuffer((err, data, info) => { ... });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toBuffer()
|
||||||
|
* .then(data => { ... })
|
||||||
|
* .catch(err => { ... });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toBuffer({ resolveWithObject: true })
|
||||||
|
* .then(({ data, info }) => { ... })
|
||||||
|
* .catch(err => { ... });
|
||||||
*
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
* @param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
@@ -73,6 +102,13 @@ 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.
|
||||||
* The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
* The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
||||||
* 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.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp('input.jpg')
|
||||||
|
* .withMetadata()
|
||||||
|
* .toFile('output-with-metadata.jpg')
|
||||||
|
* .then(info => { ... });
|
||||||
|
*
|
||||||
* @param {Object} [withMetadata]
|
* @param {Object} [withMetadata]
|
||||||
* @param {Number} [withMetadata.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
* @param {Number} [withMetadata.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -94,6 +130,16 @@ function withMetadata (withMetadata) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these JPEG options for output image.
|
* Use these JPEG options for output image.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to very high quality JPEG output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .jpeg({
|
||||||
|
* quality: 100,
|
||||||
|
* chromaSubsampling: '4:4:4'
|
||||||
|
* })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
@@ -145,10 +191,20 @@ function jpeg (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these PNG options for output image.
|
* Use these PNG options for output image.
|
||||||
|
*
|
||||||
|
* PNG output is always full colour at 8 or 16 bits per pixel.
|
||||||
|
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to PNG output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .png()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
* @param {Number} [options.compressionLevel=6] - zlib compression level
|
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
|
||||||
* @param {Boolean} [options.adaptiveFiltering=true] - use adaptive row filtering
|
* @param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
||||||
* @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
|
||||||
@@ -174,6 +230,13 @@ function png (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these WebP options for output image.
|
* Use these WebP options for output image.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to lossless WebP output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .webp({ lossless: true })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
||||||
@@ -209,11 +272,22 @@ function webp (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these TIFF options for output image.
|
* Use these TIFF options for output image.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
|
* sharp('input.svg')
|
||||||
|
* .tiff({
|
||||||
|
* compression: 'lzw',
|
||||||
|
* squash: true
|
||||||
|
* })
|
||||||
|
* .toFile('1-bpp-output.tiff')
|
||||||
|
* .then(info => { ... });
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
||||||
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg
|
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
||||||
* @param {Boolean} [options.predictor='none'] - compression predictor options: none, horizontal, float
|
* @param {Boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
||||||
* @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.squash=false] - squash 8-bit images down to 1 bit
|
||||||
@@ -252,10 +326,10 @@ function tiff (options) {
|
|||||||
}
|
}
|
||||||
// compression
|
// compression
|
||||||
if (is.defined(options) && is.defined(options.compression)) {
|
if (is.defined(options) && is.defined(options.compression)) {
|
||||||
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'none'])) {
|
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'ccittfax4', 'none'])) {
|
||||||
this.options.tiffCompression = options.compression;
|
this.options.tiffCompression = options.compression;
|
||||||
} else {
|
} else {
|
||||||
const message = `Invalid compression option "${options.compression}". Should be one of: lzw, deflate, jpeg, none`;
|
const message = `Invalid compression option "${options.compression}". Should be one of: lzw, deflate, jpeg, ccittfax4, none`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,6 +347,13 @@ function tiff (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to be raw, uncompressed uint8 pixel data.
|
* Force output to be raw, uncompressed uint8 pixel data.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Extract raw RGB pixel data from JPEG input
|
||||||
|
* const { data, info } = await sharp('input.jpg')
|
||||||
|
* .raw()
|
||||||
|
* .toBuffer({ resolveWithObject: true });
|
||||||
|
*
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
function raw () {
|
function raw () {
|
||||||
@@ -281,6 +362,13 @@ function raw () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to a given format.
|
* Force output to a given format.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to PNG output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .toFormat('png')
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {(String|Object)} format - as a String or an Object with an 'id' attribute
|
* @param {(String|Object)} format - as a String or an Object with an 'id' attribute
|
||||||
* @param {Object} options - output options
|
* @param {Object} options - output options
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -316,6 +404,7 @@ function toFormat (format, options) {
|
|||||||
* @param {Object} [tile]
|
* @param {Object} [tile]
|
||||||
* @param {Number} [tile.size=256] tile size in pixels, a value between 1 and 8192.
|
* @param {Number} [tile.size=256] tile size in pixels, a value between 1 and 8192.
|
||||||
* @param {Number} [tile.overlap=0] tile overlap in pixels, a value between 0 and 8192.
|
* @param {Number} [tile.overlap=0] tile overlap in pixels, a value between 0 and 8192.
|
||||||
|
* @param {Number} [tile.angle=0] tile angle of rotation, must be a multiple of 90.
|
||||||
* @param {String} [tile.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
* @param {String} [tile.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
||||||
* @param {String} [tile.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
|
* @param {String} [tile.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -358,6 +447,15 @@ function tile (tile) {
|
|||||||
throw new Error('Invalid tile layout ' + tile.layout);
|
throw new Error('Invalid tile layout ' + tile.layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Angle of rotation,
|
||||||
|
if (is.defined(tile.angle)) {
|
||||||
|
if (is.integer(tile.angle) && !(tile.angle % 90)) {
|
||||||
|
this.options.tileAngle = tile.angle;
|
||||||
|
} else {
|
||||||
|
throw new Error('Unsupported angle: angle must be a positive/negative multiple of 90 ' + tile.angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Format
|
// Format
|
||||||
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
||||||
@@ -365,6 +463,7 @@ function tile (tile) {
|
|||||||
} else if (this.options.formatOut !== 'input') {
|
} else if (this.options.formatOut !== 'input') {
|
||||||
throw new Error('Invalid tile format ' + this.options.formatOut);
|
throw new Error('Invalid tile format ' + this.options.formatOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._updateFormatOut('dz');
|
return this._updateFormatOut('dz');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
lib/platform.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function () {
|
||||||
|
const arch = process.env.npm_config_arch || process.arch;
|
||||||
|
const platform = process.env.npm_config_platform || process.platform;
|
||||||
|
|
||||||
|
const platformId = [platform];
|
||||||
|
if (arch === 'arm' || arch === 'armhf' || arch === 'arm64') {
|
||||||
|
const armVersion = (arch === 'arm64') ? '8' : process.env.npm_config_armv || process.config.variables.arm_version || '6';
|
||||||
|
platformId.push(`armv${armVersion}`);
|
||||||
|
} else {
|
||||||
|
platformId.push(arch);
|
||||||
|
}
|
||||||
|
return platformId.join('-');
|
||||||
|
};
|
||||||
@@ -42,52 +42,27 @@ const kernel = {
|
|||||||
lanczos3: 'lanczos3'
|
lanczos3: 'lanczos3'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Enlargement interpolators.
|
|
||||||
* @member
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const interpolator = {
|
|
||||||
nearest: 'nearest',
|
|
||||||
bilinear: 'bilinear',
|
|
||||||
bicubic: 'bicubic',
|
|
||||||
nohalo: 'nohalo',
|
|
||||||
lbb: 'lbb',
|
|
||||||
locallyBoundedBicubic: 'lbb',
|
|
||||||
vsqbs: 'vsqbs',
|
|
||||||
vertexSplitQuadraticBasisSpline: 'vsqbs'
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resize image to `width` x `height`.
|
* Resize image to `width` x `height`.
|
||||||
* By default, the resized image is centre cropped to the exact size specified.
|
* By default, the resized image is centre cropped to the exact size specified.
|
||||||
*
|
*
|
||||||
* Possible reduction kernels are:
|
* Possible kernels are:
|
||||||
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||||
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||||
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||||
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
*
|
*
|
||||||
* Possible enlargement interpolators are:
|
|
||||||
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
|
||||||
* - `bilinear`: Use [bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation), faster than bicubic but with less smooth results.
|
|
||||||
* - `vertexSplitQuadraticBasisSpline`: Use the smoother [VSQBS interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/vsqbs.cpp#L48) to prevent "staircasing" when enlarging.
|
|
||||||
* - `bicubic`: Use [bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default).
|
|
||||||
* - `locallyBoundedBicubic`: Use [LBB interpolation](https://github.com/jcupitt/libvips/blob/master/libvips/resample/lbb.cpp#L100), which prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2.
|
|
||||||
* - `nohalo`: Use [Nohalo interpolation](http://eprints.soton.ac.uk/268086/), which prevents acutance but typically reduces performance by a factor of 3.
|
|
||||||
*
|
|
||||||
* @example
|
* @example
|
||||||
* sharp(inputBuffer)
|
* sharp(inputBuffer)
|
||||||
* .resize(200, 300, {
|
* .resize(200, 300, {
|
||||||
* kernel: sharp.kernel.lanczos2,
|
* kernel: sharp.kernel.nearest
|
||||||
* interpolator: sharp.interpolator.nohalo
|
|
||||||
* })
|
* })
|
||||||
* .background('white')
|
* .background('white')
|
||||||
* .embed()
|
* .embed()
|
||||||
* .toFile('output.tiff')
|
* .toFile('output.tiff')
|
||||||
* .then(function() {
|
* .then(function() {
|
||||||
* // output.tiff is a 200 pixels wide and 300 pixels high image
|
* // output.tiff is a 200 pixels wide and 300 pixels high image
|
||||||
* // containing a lanczos2/nohalo scaled version, embedded on a white canvas,
|
* // containing a nearest-neighbour scaled version, embedded on a white canvas,
|
||||||
* // of the image data in inputBuffer
|
* // of the image data in inputBuffer
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
@@ -95,9 +70,7 @@ const interpolator = {
|
|||||||
* @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
* @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {String} [options.kernel='lanczos3'] - the kernel to use for image reduction.
|
* @param {String} [options.kernel='lanczos3'] - the kernel to use for image reduction.
|
||||||
* @param {String} [options.interpolator='bicubic'] - the interpolator to use for image enlargement.
|
* @param {Boolean} [options.fastShrinkOnLoad=true] - take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images.
|
||||||
* @param {Boolean} [options.centreSampling=false] - use *magick centre sampling convention instead of corner sampling.
|
|
||||||
* @param {Boolean} [options.centerSampling=false] - alternative spelling of centreSampling.
|
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -129,18 +102,9 @@ function resize (width, height, options) {
|
|||||||
throw is.invalidParameterError('kernel', 'valid kernel name', options.kernel);
|
throw is.invalidParameterError('kernel', 'valid kernel name', options.kernel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Interpolator
|
// Shrink on load
|
||||||
if (is.defined(options.interpolator)) {
|
if (is.defined(options.fastShrinkOnLoad)) {
|
||||||
if (is.string(interpolator[options.interpolator])) {
|
this._setBooleanOption('fastShrinkOnLoad', options.fastShrinkOnLoad);
|
||||||
this.options.interpolator = interpolator[options.interpolator];
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('interpolator', 'valid interpolator name', options.interpolator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Centre sampling
|
|
||||||
options.centreSampling = is.bool(options.centerSampling) ? options.centerSampling : options.centreSampling;
|
|
||||||
if (is.defined(options.centreSampling)) {
|
|
||||||
this._setBooleanOption('centreSampling', options.centreSampling);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -215,11 +179,26 @@ function crop (crop) {
|
|||||||
* // outputBuffer contains WebP image data of a 200 pixels wide and 300 pixels high
|
* // outputBuffer contains WebP image data of a 200 pixels wide and 300 pixels high
|
||||||
* // containing a scaled version, embedded on a transparent canvas, of input.gif
|
* // containing a scaled version, embedded on a transparent canvas, of input.gif
|
||||||
* });
|
* });
|
||||||
*
|
* @param {String} [embed='centre'] - A member of `sharp.gravity` to embed to an edge/corner.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function embed () {
|
function embed (embed) {
|
||||||
this.options.canvas = 'embed';
|
this.options.canvas = 'embed';
|
||||||
|
|
||||||
|
if (!is.defined(embed)) {
|
||||||
|
// Default
|
||||||
|
this.options.embed = gravity.center;
|
||||||
|
} else if (is.integer(embed) && is.inRange(embed, 0, 8)) {
|
||||||
|
// Gravity (numeric)
|
||||||
|
this.options.embed = embed;
|
||||||
|
} else if (is.string(embed) && is.integer(gravity[embed])) {
|
||||||
|
// Gravity (string)
|
||||||
|
this.options.embed = gravity[embed];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('embed', 'valid embed id/name', embed);
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,6 +253,10 @@ function ignoreAspectRatio () {
|
|||||||
* Do not enlarge the output image if the input image width *or* height are already less than the required dimensions.
|
* Do not enlarge the output image if the input image width *or* height are already less than the required dimensions.
|
||||||
* This is equivalent to GraphicsMagick's `>` geometry option:
|
* This is equivalent to GraphicsMagick's `>` geometry option:
|
||||||
* "*change the dimensions of the image only if its width or height exceeds the geometry specification*".
|
* "*change the dimensions of the image only if its width or height exceeds the geometry specification*".
|
||||||
|
* Use with `max()` to preserve the image's aspect ratio.
|
||||||
|
*
|
||||||
|
* The default behaviour *before* function call is `false`, meaning the image will be enlarged.
|
||||||
|
*
|
||||||
* @param {Boolean} [withoutEnlargement=true]
|
* @param {Boolean} [withoutEnlargement=true]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
@@ -302,5 +285,4 @@ module.exports = function (Sharp) {
|
|||||||
Sharp.gravity = gravity;
|
Sharp.gravity = gravity;
|
||||||
Sharp.strategy = strategy;
|
Sharp.strategy = strategy;
|
||||||
Sharp.kernel = kernel;
|
Sharp.kernel = kernel;
|
||||||
Sharp.interpolator = interpolator;
|
|
||||||
};
|
};
|
||||||
|
|||||||
60
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.18.3",
|
"version": "0.20.2",
|
||||||
"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": [
|
||||||
@@ -38,13 +38,24 @@
|
|||||||
"YvesBos <yves_bos@outlook.com>",
|
"YvesBos <yves_bos@outlook.com>",
|
||||||
"Guy Maliar <guy@tailorbrands.com>",
|
"Guy Maliar <guy@tailorbrands.com>",
|
||||||
"Nicolas Coden <nicolas@ncoden.fr>",
|
"Nicolas Coden <nicolas@ncoden.fr>",
|
||||||
"Matt Parrish <matt.r.parrish@gmail.com>"
|
"Matt Parrish <matt.r.parrish@gmail.com>",
|
||||||
|
"Marcel Bretschneider <marcel.bretschneider@gmail.com>",
|
||||||
|
"Matthew McEachen <matthew+github@mceachen.org>",
|
||||||
|
"Jarda Kotěšovec <jarda.kotesovec@gmail.com>",
|
||||||
|
"Kenric D'Souza <kenric.dsouza@gmail.com>",
|
||||||
|
"Oleh Aleinyk <oleg.aleynik@gmail.com>",
|
||||||
|
"Marcel Bretschneider <marcel.bretschneider@gmail.com>",
|
||||||
|
"Andrea Bianco <andrea.bianco@unibas.ch>",
|
||||||
|
"Rik Heywood <rik@rik.org>",
|
||||||
|
"Thomas Parisot <hi@oncletom.io>",
|
||||||
|
"Nathan Graves <nathanrgraves+github@gmail.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
||||||
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
|
||||||
"test": "semistandard && cc && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
"test": "semistandard && cc && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js && prebuild-ci",
|
||||||
|
"coverage": "./test/coverage/report.sh",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"test-packaging": "./packaging/test-linux-x64.sh",
|
|
||||||
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
||||||
},
|
},
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
@@ -64,33 +75,39 @@
|
|||||||
"resize",
|
"resize",
|
||||||
"thumbnail",
|
"thumbnail",
|
||||||
"crop",
|
"crop",
|
||||||
|
"embed",
|
||||||
"libvips",
|
"libvips",
|
||||||
"vips"
|
"vips"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"caw": "^2.0.0",
|
"color": "^3.0.0",
|
||||||
"color": "^2.0.0",
|
"detect-libc": "^1.0.3",
|
||||||
"detect-libc": "^0.2.0",
|
"nan": "^2.10.0",
|
||||||
"nan": "^2.6.2",
|
"fs-copy-file-sync": "^1.0.1",
|
||||||
"semver": "^5.3.0",
|
"npmlog": "^4.1.2",
|
||||||
"simple-get": "^2.7.0",
|
"prebuild-install": "^2.5.3",
|
||||||
"tar": "^3.1.5"
|
"semver": "^5.5.0",
|
||||||
|
"simple-get": "^2.8.1",
|
||||||
|
"tar": "^4.4.1",
|
||||||
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.5.0",
|
"async": "^2.6.0",
|
||||||
"cc": "^1.0.1",
|
"cc": "^1.0.2",
|
||||||
"documentation": "^4.0.0-rc.1",
|
"decompress-zip": "^0.3.1",
|
||||||
|
"documentation": "^6.3.2",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"mocha": "^3.4.2",
|
"mocha": "^5.1.1",
|
||||||
"nyc": "^11.0.3",
|
"nyc": "^11.7.1",
|
||||||
"rimraf": "^2.6.1",
|
"prebuild": "^7.4.0",
|
||||||
"semistandard": "^11.0.0",
|
"prebuild-ci": "^2.2.3",
|
||||||
"unzip": "^0.1.11"
|
"rimraf": "^2.6.2",
|
||||||
|
"semistandard": "^12.0.1"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"config": {
|
"config": {
|
||||||
"libvips": "8.5.5"
|
"libvips": "8.6.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=4.5.0"
|
"node": ">=4.5.0"
|
||||||
@@ -105,7 +122,8 @@
|
|||||||
"filter": [
|
"filter": [
|
||||||
"build/c++11",
|
"build/c++11",
|
||||||
"build/include",
|
"build/include",
|
||||||
"runtime/indentation_namespace"
|
"runtime/indentation_namespace",
|
||||||
|
"runtime/references"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
# Packaging scripts
|
|
||||||
|
|
||||||
libvips and its dependencies are provided as pre-compiled shared libraries
|
|
||||||
for the most common operating systems and CPU architectures.
|
|
||||||
|
|
||||||
During `npm install`, these binaries are fetched as tarballs from
|
|
||||||
[Bintray](https://dl.bintray.com/lovell/sharp/) via HTTPS
|
|
||||||
and stored locally within `node_modules/sharp`.
|
|
||||||
|
|
||||||
## Using a custom tarball
|
|
||||||
|
|
||||||
A custom tarball stored on the local filesystem can be used instead.
|
|
||||||
Place it in the following location, where `x.y.z` is the libvips version,
|
|
||||||
`platform` is the value of `process.platform` and
|
|
||||||
`arch` is the value of `process.arch` (plus the version number for ARM).
|
|
||||||
|
|
||||||
`node_modules/sharp/packaging/libvips-x.y.z-platform-arch.tar.gz`
|
|
||||||
|
|
||||||
For example, for libvips v8.3.3 on an ARMv6 Linux machine, use:
|
|
||||||
|
|
||||||
`node_modules/sharp/packaging/libvips-8.3.3-linux-armv6.tar.gz`
|
|
||||||
|
|
||||||
Remove any `sharp/lib` and `sharp/include` directories
|
|
||||||
before running `npm install` again.
|
|
||||||
|
|
||||||
## Creating a tarball
|
|
||||||
|
|
||||||
Most people will not need to do this; proceed with caution.
|
|
||||||
|
|
||||||
The `packaging` directory contains the top-level [build script](build.sh).
|
|
||||||
|
|
||||||
### Linux
|
|
||||||
|
|
||||||
One [build script](build/lin.sh) is used to (cross-)compile
|
|
||||||
the same shared libraries within multiple containers.
|
|
||||||
|
|
||||||
* [x64](linux-x64/Dockerfile)
|
|
||||||
* [ARMv6](linux-armv6/Dockerfile)
|
|
||||||
* [ARMv7-A](linux-armv7/Dockerfile)
|
|
||||||
* [ARMv8-A](linux-armv8/Dockerfile)
|
|
||||||
|
|
||||||
The QEMU user mode emulation binaries are required to build for
|
|
||||||
the ARMv6 platform as the Debian armhf cross-compiler erroneously
|
|
||||||
generates unsupported Thumb 2 instructions.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
sudo apt-get install qemu-user-static
|
|
||||||
```
|
|
||||||
|
|
||||||
### Windows
|
|
||||||
|
|
||||||
The output of libvips' [build-win64](https://github.com/jcupitt/build-win64)
|
|
||||||
"web" target is [post-processed](build/win.sh) within a [container](win32-x64/Dockerfile).
|
|
||||||
|
|
||||||
### OS X
|
|
||||||
|
|
||||||
See [package-libvips-darwin](https://github.com/lovell/package-libvips-darwin).
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo
|
|
||||||
echo "Usage: $0 VERSION [PLATFORM]"
|
|
||||||
echo "Build shared libraries for libvips and its dependencies via containers"
|
|
||||||
echo
|
|
||||||
echo "Please specify the libvips VERSION, e.g. 8.3.3"
|
|
||||||
echo
|
|
||||||
echo "Optionally build for only one PLATFORM, defaults to building for all"
|
|
||||||
echo "Possible values for PLATFORM are: win32-x64, linux-x64, linux-armv6,"
|
|
||||||
echo "linux-armv7, linux-armv8"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
VERSION_VIPS="$1"
|
|
||||||
PLATFORM="${2:-all}"
|
|
||||||
|
|
||||||
# Is docker available?
|
|
||||||
if ! type docker >/dev/null; then
|
|
||||||
echo "Please install docker"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update base images
|
|
||||||
for baseimage in debian:wheezy debian:jessie debian:stretch socialdefect/raspbian-jessie-core; do
|
|
||||||
docker pull $baseimage
|
|
||||||
done
|
|
||||||
|
|
||||||
# Windows (x64)
|
|
||||||
if [ $PLATFORM = "all" ] || [ $PLATFORM = "win32-x64" ]; then
|
|
||||||
echo "Building win32-x64..."
|
|
||||||
docker build -t vips-dev-win32-x64 win32-x64
|
|
||||||
docker run --rm -e "VERSION_VIPS=${VERSION_VIPS}" -v $PWD:/packaging vips-dev-win32-x64 sh -c "/packaging/build/win.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Linux (x64, ARMv6, ARMv7, ARMv8)
|
|
||||||
for flavour in linux-x64 linux-armv6 linux-armv7 linux-armv8; do
|
|
||||||
if [ $PLATFORM = "all" ] || [ $PLATFORM = $flavour ]; then
|
|
||||||
echo "Building $flavour..."
|
|
||||||
docker build -t vips-dev-$flavour $flavour
|
|
||||||
docker run --rm -e "VERSION_VIPS=${VERSION_VIPS}" -v $PWD:/packaging vips-dev-$flavour sh -c "/packaging/build/lin.sh"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Display checksums
|
|
||||||
sha256sum *.tar.gz
|
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Working directories
|
|
||||||
DEPS=/deps
|
|
||||||
TARGET=/target
|
|
||||||
mkdir ${DEPS}
|
|
||||||
mkdir ${TARGET}
|
|
||||||
|
|
||||||
# Common build paths and flags
|
|
||||||
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${TARGET}/lib/pkgconfig"
|
|
||||||
export PATH="${PATH}:${TARGET}/bin"
|
|
||||||
export CPPFLAGS="-I${TARGET}/include"
|
|
||||||
export LDFLAGS="-L${TARGET}/lib"
|
|
||||||
export CFLAGS="${FLAGS}"
|
|
||||||
export CXXFLAGS="${FLAGS}"
|
|
||||||
|
|
||||||
# Dependency version numbers
|
|
||||||
VERSION_ZLIB=1.2.11
|
|
||||||
VERSION_FFI=3.2.1
|
|
||||||
VERSION_GLIB=2.53.1
|
|
||||||
VERSION_XML2=2.9.4
|
|
||||||
VERSION_GSF=1.14.41
|
|
||||||
VERSION_EXIF=0.6.21
|
|
||||||
VERSION_LCMS2=2.8
|
|
||||||
VERSION_JPEG=1.5.1
|
|
||||||
VERSION_PNG16=1.6.29
|
|
||||||
VERSION_WEBP=0.6.0
|
|
||||||
VERSION_TIFF=4.0.7
|
|
||||||
VERSION_ORC=0.4.26
|
|
||||||
VERSION_GDKPIXBUF=2.36.6
|
|
||||||
VERSION_FREETYPE=2.8
|
|
||||||
VERSION_EXPAT=2.2.0
|
|
||||||
VERSION_FONTCONFIG=2.12.1
|
|
||||||
VERSION_HARFBUZZ=1.4.6
|
|
||||||
VERSION_PIXMAN=0.34.0
|
|
||||||
VERSION_CAIRO=1.14.8
|
|
||||||
VERSION_PANGO=1.40.5
|
|
||||||
VERSION_CROCO=0.6.12
|
|
||||||
VERSION_SVG=2.40.17
|
|
||||||
VERSION_GIF=5.1.4
|
|
||||||
|
|
||||||
# Least out-of-sync Sourceforge mirror
|
|
||||||
SOURCEFORGE_MIRROR=netix
|
|
||||||
|
|
||||||
mkdir ${DEPS}/zlib
|
|
||||||
curl -Ls http://zlib.net/zlib-${VERSION_ZLIB}.tar.xz | tar xJC ${DEPS}/zlib --strip-components=1
|
|
||||||
cd ${DEPS}/zlib
|
|
||||||
./configure --prefix=${TARGET} --uname=linux
|
|
||||||
make install
|
|
||||||
rm ${TARGET}/lib/libz.a
|
|
||||||
|
|
||||||
mkdir ${DEPS}/ffi
|
|
||||||
curl -Ls ftp://sourceware.org/pub/libffi/libffi-${VERSION_FFI}.tar.gz | tar xzC ${DEPS}/ffi --strip-components=1
|
|
||||||
cd ${DEPS}/ffi
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-builddir
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/glib
|
|
||||||
curl -Ls https://download.gnome.org/sources/glib/2.53/glib-${VERSION_GLIB}.tar.xz | tar xJC ${DEPS}/glib --strip-components=1
|
|
||||||
cd ${DEPS}/glib
|
|
||||||
echo glib_cv_stack_grows=no >>glib.cache
|
|
||||||
echo glib_cv_uscore=no >>glib.cache
|
|
||||||
./configure --cache-file=glib.cache --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--with-pcre=internal --disable-libmount
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/xml2
|
|
||||||
curl -Ls http://xmlsoft.org/sources/libxml2-${VERSION_XML2}.tar.gz | tar xzC ${DEPS}/xml2 --strip-components=1
|
|
||||||
cd ${DEPS}/xml2
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--without-python --without-debug --without-docbook --without-ftp --without-html --without-legacy \
|
|
||||||
--without-pattern --without-push --without-regexps --without-schemas --without-schematron --with-zlib=${TARGET}
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/gsf
|
|
||||||
curl -Ls https://download.gnome.org/sources/libgsf/1.14/libgsf-${VERSION_GSF}.tar.xz | tar xJC ${DEPS}/gsf --strip-components=1
|
|
||||||
cd ${DEPS}/gsf
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/exif
|
|
||||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/libexif/libexif/${VERSION_EXIF}/libexif-${VERSION_EXIF}.tar.bz2 | tar xjC ${DEPS}/exif --strip-components=1
|
|
||||||
cd ${DEPS}/exif
|
|
||||||
autoreconf -fiv
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/lcms2
|
|
||||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/lcms/lcms/${VERSION_LCMS2}/lcms2-${VERSION_LCMS2}.tar.gz | tar xzC ${DEPS}/lcms2 --strip-components=1
|
|
||||||
cd ${DEPS}/lcms2
|
|
||||||
# Apply patches for lcms2 vulnerabilities reported since v2.8
|
|
||||||
VERSION_LCMS2_GIT_MASTER_SHA=$(curl -Ls https://api.github.com/repos/mm2/Little-CMS/git/refs/heads/master | jq -r '.object.sha' | head -c7)
|
|
||||||
curl -Ls https://github.com/mm2/Little-CMS/compare/lcms2.8...master.patch | patch -p1 -t || true
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/jpeg
|
|
||||||
curl -Ls https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION_JPEG}.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1
|
|
||||||
cd ${DEPS}/jpeg
|
|
||||||
autoreconf -fiv
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-jpeg8 --without-turbojpeg
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/png16
|
|
||||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/libpng/libpng16/${VERSION_PNG16}/libpng-${VERSION_PNG16}.tar.xz | tar xJC ${DEPS}/png16 --strip-components=1
|
|
||||||
cd ${DEPS}/png16
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/webp
|
|
||||||
curl -Ls http://downloads.webmproject.org/releases/webp/libwebp-${VERSION_WEBP}.tar.gz | tar xzC ${DEPS}/webp --strip-components=1
|
|
||||||
cd ${DEPS}/webp
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--disable-neon --enable-libwebpmux
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/tiff
|
|
||||||
curl -Ls http://download.osgeo.org/libtiff/tiff-${VERSION_TIFF}.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1
|
|
||||||
cd ${DEPS}/tiff
|
|
||||||
# Apply patches for libtiff vulnerabilities reported since v4.0.7
|
|
||||||
VERSION_TIFF_GIT_MASTER_SHA=$(curl -Ls https://api.github.com/repos/vadz/libtiff/git/refs/heads/master | jq -r '.object.sha' | head -c7)
|
|
||||||
curl -Ls https://github.com/vadz/libtiff/compare/Release-v4-0-7...master.patch | patch -p1 -t || true
|
|
||||||
if [ -n "${CHOST}" ]; then autoreconf -fiv; fi
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-mdi --disable-pixarlog --disable-cxx
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/orc
|
|
||||||
curl -Ls http://gstreamer.freedesktop.org/data/src/orc/orc-${VERSION_ORC}.tar.xz | tar xJC ${DEPS}/orc --strip-components=1
|
|
||||||
cd ${DEPS}/orc
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
cd ${TARGET}/lib
|
|
||||||
rm -rf liborc-test-*
|
|
||||||
|
|
||||||
mkdir ${DEPS}/gdkpixbuf
|
|
||||||
curl -Ls https://download.gnome.org/sources/gdk-pixbuf/2.36/gdk-pixbuf-${VERSION_GDKPIXBUF}.tar.xz | tar xJC ${DEPS}/gdkpixbuf --strip-components=1
|
|
||||||
cd ${DEPS}/gdkpixbuf
|
|
||||||
touch gdk-pixbuf/loaders.cache
|
|
||||||
LD_LIBRARY_PATH=${TARGET}/lib \
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--disable-introspection --disable-modules --disable-gio-sniffing \
|
|
||||||
--without-libtiff --without-gdiplus --with-included-loaders=png,jpeg
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/freetype
|
|
||||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/freetype/freetype2/${VERSION_FREETYPE}/freetype-${VERSION_FREETYPE}.tar.gz | tar xzC ${DEPS}/freetype --strip-components=1
|
|
||||||
cd ${DEPS}/freetype
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static
|
|
||||||
make install
|
|
||||||
|
|
||||||
mkdir ${DEPS}/expat
|
|
||||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/expat/expat/${VERSION_EXPAT}/expat-${VERSION_EXPAT}.tar.bz2 | tar xjC ${DEPS}/expat --strip-components=1
|
|
||||||
cd ${DEPS}/expat
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static
|
|
||||||
make install
|
|
||||||
|
|
||||||
mkdir ${DEPS}/fontconfig
|
|
||||||
curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1
|
|
||||||
cd ${DEPS}/fontconfig
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--with-expat-includes=${TARGET}/include --with-expat-lib=${TARGET}/lib --sysconfdir=/etc
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/harfbuzz
|
|
||||||
curl -Ls https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-${VERSION_HARFBUZZ}.tar.bz2 | tar xjC ${DEPS}/harfbuzz --strip-components=1
|
|
||||||
cd ${DEPS}/harfbuzz
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/pixman
|
|
||||||
curl -Ls http://cairographics.org/releases/pixman-${VERSION_PIXMAN}.tar.gz | tar xzC ${DEPS}/pixman --strip-components=1
|
|
||||||
cd ${DEPS}/pixman
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-libpng --disable-arm-iwmmxt
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/cairo
|
|
||||||
curl -Ls http://cairographics.org/releases/cairo-${VERSION_CAIRO}.tar.xz | tar xJC ${DEPS}/cairo --strip-components=1
|
|
||||||
cd ${DEPS}/cairo
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--disable-xlib --disable-xcb --disable-quartz --disable-win32 --disable-egl --disable-glx --disable-wgl \
|
|
||||||
--disable-script --disable-ps --disable-gobject --disable-trace --disable-interpreter
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/pango
|
|
||||||
curl -Ls https://download.gnome.org/sources/pango/1.40/pango-${VERSION_PANGO}.tar.xz | tar xJC ${DEPS}/pango --strip-components=1
|
|
||||||
cd ${DEPS}/pango
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/croco
|
|
||||||
curl -Ls https://download.gnome.org/sources/libcroco/0.6/libcroco-${VERSION_CROCO}.tar.xz | tar xJC ${DEPS}/croco --strip-components=1
|
|
||||||
cd ${DEPS}/croco
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/svg
|
|
||||||
curl -Ls https://download.gnome.org/sources/librsvg/2.40/librsvg-${VERSION_SVG}.tar.xz | tar xJC ${DEPS}/svg --strip-components=1
|
|
||||||
cd ${DEPS}/svg
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-introspection --disable-tools --disable-pixbuf-loader
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/gif
|
|
||||||
curl -Ls http://${SOURCEFORGE_MIRROR}.dl.sourceforge.net/project/giflib/giflib-${VERSION_GIF}.tar.gz | tar xzC ${DEPS}/gif --strip-components=1
|
|
||||||
cd ${DEPS}/gif
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
mkdir ${DEPS}/vips
|
|
||||||
curl -Ls https://github.com/jcupitt/libvips/releases/download/v${VERSION_VIPS}/vips-${VERSION_VIPS}.tar.gz | tar xzC ${DEPS}/vips --strip-components=1
|
|
||||||
cd ${DEPS}/vips
|
|
||||||
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \
|
|
||||||
--disable-debug --disable-introspection --without-python --without-fftw \
|
|
||||||
--without-magick --without-pangoft2 --without-ppm --without-analyze --without-radiance \
|
|
||||||
--with-zip-includes=${TARGET}/include --with-zip-libraries=${TARGET}/lib \
|
|
||||||
--with-jpeg-includes=${TARGET}/include --with-jpeg-libraries=${TARGET}/lib
|
|
||||||
make install-strip
|
|
||||||
|
|
||||||
# Remove the old C++ bindings
|
|
||||||
cd ${TARGET}/include
|
|
||||||
rm -rf vips/vipsc++.h vips/vipscpp.h
|
|
||||||
cd ${TARGET}/lib
|
|
||||||
rm -rf pkgconfig .libs *.la libvipsCC*
|
|
||||||
|
|
||||||
# Create JSON file of version numbers
|
|
||||||
cd ${TARGET}
|
|
||||||
echo "{\n\
|
|
||||||
\"cairo\": \"${VERSION_CAIRO}\",\n\
|
|
||||||
\"croco\": \"${VERSION_CROCO}\",\n\
|
|
||||||
\"exif\": \"${VERSION_EXIF}\",\n\
|
|
||||||
\"expat\": \"${VERSION_EXPAT}\",\n\
|
|
||||||
\"ffi\": \"${VERSION_FFI}\",\n\
|
|
||||||
\"fontconfig\": \"${VERSION_FONTCONFIG}\",\n\
|
|
||||||
\"freetype\": \"${VERSION_FREETYPE}\",\n\
|
|
||||||
\"gdkpixbuf\": \"${VERSION_GDKPIXBUF}\",\n\
|
|
||||||
\"gif\": \"${VERSION_GIF}\",\n\
|
|
||||||
\"glib\": \"${VERSION_GLIB}\",\n\
|
|
||||||
\"gsf\": \"${VERSION_GSF}\",\n\
|
|
||||||
\"harfbuzz\": \"${VERSION_HARFBUZZ}\",\n\
|
|
||||||
\"jpeg\": \"${VERSION_JPEG}\",\n\
|
|
||||||
\"lcms\": \"${VERSION_LCMS2}-${VERSION_LCMS2_GIT_MASTER_SHA}\",\n\
|
|
||||||
\"orc\": \"${VERSION_ORC}\",\n\
|
|
||||||
\"pango\": \"${VERSION_PANGO}\",\n\
|
|
||||||
\"pixman\": \"${VERSION_PIXMAN}\",\n\
|
|
||||||
\"png\": \"${VERSION_PNG16}\",\n\
|
|
||||||
\"svg\": \"${VERSION_SVG}\",\n\
|
|
||||||
\"tiff\": \"${VERSION_TIFF}-${VERSION_TIFF_GIT_MASTER_SHA}\",\n\
|
|
||||||
\"vips\": \"${VERSION_VIPS}\",\n\
|
|
||||||
\"webp\": \"${VERSION_WEBP}\",\n\
|
|
||||||
\"xml\": \"${VERSION_XML2}\",\n\
|
|
||||||
\"zlib\": \"${VERSION_ZLIB}\"\n\
|
|
||||||
}" >lib/versions.json
|
|
||||||
|
|
||||||
# Create .tar.gz
|
|
||||||
tar czf /packaging/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz include lib
|
|
||||||
advdef --recompress --shrink-insane /packaging/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Fetch and unzip
|
|
||||||
mkdir /vips
|
|
||||||
cd /vips
|
|
||||||
curl -L -O https://github.com/lovell/build-win64/releases/download/v${VERSION_VIPS}/vips-dev-w64-web-${VERSION_VIPS}.zip
|
|
||||||
unzip vips-dev-w64-web-${VERSION_VIPS}.zip
|
|
||||||
|
|
||||||
# Clean and zip
|
|
||||||
cd /vips/vips-dev-8.5
|
|
||||||
rm bin/libvipsCC-42.dll bin/libvips-cpp-42.dll bin/libgsf-win32-1-114.dll
|
|
||||||
cp bin/*.dll lib/
|
|
||||||
cp -r lib64/* lib/
|
|
||||||
|
|
||||||
echo "Creating tarball"
|
|
||||||
tar czf /packaging/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz include lib/glib-2.0 lib/libvips.lib lib/libglib-2.0.lib lib/libgobject-2.0.lib lib/*.dll
|
|
||||||
echo "Shrinking tarball"
|
|
||||||
advdef --recompress --shrink-insane /packaging/libvips-${VERSION_VIPS}-${PLATFORM}.tar.gz
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
FROM socialdefect/raspbian-jessie-core
|
|
||||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
|
||||||
|
|
||||||
# Create Rasbian-based container suitable for compiling Linux ARMv6 binaries
|
|
||||||
# Requires the QEMU user mode emulation binaries on the host machine
|
|
||||||
|
|
||||||
# Build dependencies
|
|
||||||
RUN \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y build-essential curl autoconf libtool nasm gtk-doc-tools texinfo advancecomp libglib2.0-dev jq
|
|
||||||
|
|
||||||
# Compiler settings
|
|
||||||
ENV \
|
|
||||||
PLATFORM=linux-armv6 \
|
|
||||||
FLAGS="-Os"
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
FROM debian:jessie
|
|
||||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
|
||||||
|
|
||||||
# Create Debian-based container suitable for cross-compiling Linux ARMv7-A binaries
|
|
||||||
|
|
||||||
# Build dependencies
|
|
||||||
RUN \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y curl && \
|
|
||||||
echo "deb http://emdebian.org/tools/debian/ jessie main" | tee /etc/apt/sources.list.d/crosstools.list && \
|
|
||||||
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add - && \
|
|
||||||
dpkg --add-architecture armhf && \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y crossbuild-essential-armhf autoconf libtool nasm gtk-doc-tools texinfo advancecomp libglib2.0-dev jq
|
|
||||||
|
|
||||||
# Compiler settings
|
|
||||||
ENV \
|
|
||||||
PLATFORM=linux-armv7 \
|
|
||||||
CHOST=arm-linux-gnueabihf \
|
|
||||||
FLAGS="-marm -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -Os"
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
FROM debian:stretch
|
|
||||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
|
||||||
|
|
||||||
# Create Debian-based container suitable for cross-compiling Linux ARMv8-A binaries
|
|
||||||
|
|
||||||
# Build dependencies
|
|
||||||
RUN \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y curl && \
|
|
||||||
dpkg --add-architecture arm64 && \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y crossbuild-essential-arm64 autoconf libtool nasm gtk-doc-tools texinfo advancecomp libglib2.0-dev jq gettext intltool autopoint
|
|
||||||
|
|
||||||
# Compiler settings
|
|
||||||
ENV \
|
|
||||||
PLATFORM=linux-armv8 \
|
|
||||||
CHOST=aarch64-linux-gnu \
|
|
||||||
FLAGS="-march=armv8-a -Os -D_GLIBCXX_USE_CXX11_ABI=0"
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
FROM debian:wheezy
|
|
||||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
|
||||||
|
|
||||||
# Create Debian-based container suitable for building Linux x64 binaries
|
|
||||||
|
|
||||||
# Build dependencies
|
|
||||||
RUN \
|
|
||||||
echo "deb http://ftp.debian.org/debian wheezy-backports main" | tee /etc/apt/sources.list.d/wheezy-backports.list && \
|
|
||||||
apt-get update && \
|
|
||||||
apt-get install -y build-essential autoconf libtool nasm gtk-doc-tools texinfo advancecomp && \
|
|
||||||
apt-get -t wheezy-backports install -y jq
|
|
||||||
|
|
||||||
# Compiler settings
|
|
||||||
ENV \
|
|
||||||
PLATFORM="linux-x64" \
|
|
||||||
FLAGS="-O3"
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo "Usage: $0 IP"
|
|
||||||
echo "Test sharp on ARM using Docker, where IP is"
|
|
||||||
echo "the address of a Raspberry Pi running HypriotOS"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
IP="$1"
|
|
||||||
|
|
||||||
echo "Verifying connectivity to $IP"
|
|
||||||
if ! ping -c 1 $IP; then
|
|
||||||
echo "Could not connect to $IP"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! type sshpass >/dev/null; then
|
|
||||||
echo "Please install sshpass"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
export SSHPASS=hypriot
|
|
||||||
|
|
||||||
echo "Copying sharp source to device"
|
|
||||||
sshpass -e scp -o PreferredAuthentications=password -r ../../sharp pirate@${IP}:/home/pirate/sharp
|
|
||||||
|
|
||||||
echo "Compile and test within container"
|
|
||||||
sshpass -e ssh -o PreferredAuthentications=password -t pirate@${IP} "docker run --rm -v \${PWD}/sharp:/s hypriot/rpi-node:6 sh -c 'cd /s && npm install --unsafe-perm && npm test'"
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Verify docker is available
|
|
||||||
if ! type docker >/dev/null; then
|
|
||||||
echo "Please install docker"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
test="npm run clean; npm install --unsafe-perm; npm test"
|
|
||||||
|
|
||||||
# Debian 7, 8
|
|
||||||
# Ubuntu 14.04, 16.04
|
|
||||||
for dist in debian:jessie debian:stretch ubuntu:trusty ubuntu:xenial; do
|
|
||||||
echo "Testing $dist..."
|
|
||||||
docker pull $dist
|
|
||||||
if docker run -i -t --rm -v $PWD:/v $dist >packaging/$dist.log 2>&1 sh -c "cd /v; ./packaging/test/debian.sh; $test";
|
|
||||||
then echo "$dist OK"
|
|
||||||
else echo "$dist fail" && cat packaging/$dist.log
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Centos 7
|
|
||||||
echo "Testing centos7..."
|
|
||||||
docker pull centos:7
|
|
||||||
if docker run -i -t --rm -v $PWD:/v centos:7 >packaging/centos7.log 2>&1 sh -c "cd /v; ./packaging/test/centos.sh; $test";
|
|
||||||
then echo "centos7 OK"
|
|
||||||
else echo "centos7 fail" && cat packaging/centos7.log
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Archlinux latest
|
|
||||||
echo "Testing archlinux..."
|
|
||||||
docker pull pritunl/archlinux:latest
|
|
||||||
if docker run -i -t --rm -v $PWD:/v pritunl/archlinux:latest >packaging/archlinux.log 2>&1 sh -c "cd /v; ./packaging/test/archlinux.sh; $test";
|
|
||||||
then echo "archlinux OK"
|
|
||||||
else echo "archlinux fail" && cat packaging/archlinux.log
|
|
||||||
fi
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Install Node.js on Archlinux
|
|
||||||
pacman -Sy --noconfirm gcc make python2 nodejs npm | cat
|
|
||||||
ln -s /usr/bin/python2 /usr/bin/python
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
curl -sL https://rpm.nodesource.com/setup_6.x | bash -
|
|
||||||
yum install -y gcc-c++ make nodejs
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y build-essential python pkg-config curl
|
|
||||||
curl -sL https://deb.nodesource.com/setup_6.x | bash -
|
|
||||||
apt-get install -y nodejs
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
FROM debian:stretch
|
|
||||||
MAINTAINER Lovell Fuller <npm@lovell.info>
|
|
||||||
|
|
||||||
# Create Debian-based container suitable for post-processing Windows x64 binaries
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y curl zip advancecomp
|
|
||||||
|
|
||||||
ENV PLATFORM=win32-x64
|
|
||||||
@@ -40,7 +40,7 @@ namespace sharp {
|
|||||||
|
|
||||||
// Create an InputDescriptor instance from a v8::Object describing an input image
|
// Create an InputDescriptor instance from a v8::Object describing an input image
|
||||||
InputDescriptor* CreateInputDescriptor(
|
InputDescriptor* CreateInputDescriptor(
|
||||||
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> buffersToPersist
|
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> &buffersToPersist
|
||||||
) {
|
) {
|
||||||
Nan::HandleScope();
|
Nan::HandleScope();
|
||||||
InputDescriptor *descriptor = new InputDescriptor;
|
InputDescriptor *descriptor = new InputDescriptor;
|
||||||
@@ -52,6 +52,7 @@ namespace sharp {
|
|||||||
descriptor->buffer = node::Buffer::Data(buffer);
|
descriptor->buffer = node::Buffer::Data(buffer);
|
||||||
buffersToPersist.push_back(buffer);
|
buffersToPersist.push_back(buffer);
|
||||||
}
|
}
|
||||||
|
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
|
||||||
// Density for vector-based input
|
// Density for vector-based input
|
||||||
if (HasAttr(input, "density")) {
|
if (HasAttr(input, "density")) {
|
||||||
descriptor->density = AttrTo<uint32_t>(input, "density");
|
descriptor->density = AttrTo<uint32_t>(input, "density");
|
||||||
@@ -62,6 +63,10 @@ namespace sharp {
|
|||||||
descriptor->rawWidth = AttrTo<uint32_t>(input, "rawWidth");
|
descriptor->rawWidth = AttrTo<uint32_t>(input, "rawWidth");
|
||||||
descriptor->rawHeight = AttrTo<uint32_t>(input, "rawHeight");
|
descriptor->rawHeight = AttrTo<uint32_t>(input, "rawHeight");
|
||||||
}
|
}
|
||||||
|
// Page input for multi-page TIFF
|
||||||
|
if (HasAttr(input, "page")) {
|
||||||
|
descriptor->page = AttrTo<uint32_t>(input, "page");
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (HasAttr(input, "createChannels")) {
|
if (HasAttr(input, "createChannels")) {
|
||||||
descriptor->createChannels = AttrTo<uint32_t>(input, "createChannels");
|
descriptor->createChannels = AttrTo<uint32_t>(input, "createChannels");
|
||||||
@@ -219,13 +224,18 @@ namespace sharp {
|
|||||||
imageType = DetermineImageType(descriptor->buffer, descriptor->bufferLength);
|
imageType = DetermineImageType(descriptor->buffer, descriptor->bufferLength);
|
||||||
if (imageType != ImageType::UNKNOWN) {
|
if (imageType != ImageType::UNKNOWN) {
|
||||||
try {
|
try {
|
||||||
vips::VOption *option = VImage::option()->set("access", accessMethod);
|
vips::VOption *option = VImage::option()
|
||||||
|
->set("access", accessMethod)
|
||||||
|
->set("fail", descriptor->failOnError);
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||||
option->set("dpi", static_cast<double>(descriptor->density));
|
option->set("dpi", static_cast<double>(descriptor->density));
|
||||||
}
|
}
|
||||||
if (imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::MAGICK) {
|
||||||
option->set("density", std::to_string(descriptor->density).data());
|
option->set("density", std::to_string(descriptor->density).data());
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::TIFF) {
|
||||||
|
option->set("page", descriptor->page);
|
||||||
|
}
|
||||||
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) {
|
||||||
SetDensity(image, descriptor->density);
|
SetDensity(image, descriptor->density);
|
||||||
@@ -256,13 +266,18 @@ namespace sharp {
|
|||||||
imageType = DetermineImageType(descriptor->file.data());
|
imageType = DetermineImageType(descriptor->file.data());
|
||||||
if (imageType != ImageType::UNKNOWN) {
|
if (imageType != ImageType::UNKNOWN) {
|
||||||
try {
|
try {
|
||||||
vips::VOption *option = VImage::option()->set("access", accessMethod);
|
vips::VOption *option = VImage::option()
|
||||||
|
->set("access", accessMethod)
|
||||||
|
->set("fail", descriptor->failOnError);
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||||
option->set("dpi", static_cast<double>(descriptor->density));
|
option->set("dpi", static_cast<double>(descriptor->density));
|
||||||
}
|
}
|
||||||
if (imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::MAGICK) {
|
||||||
option->set("density", std::to_string(descriptor->density).data());
|
option->set("density", std::to_string(descriptor->density).data());
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::TIFF) {
|
||||||
|
option->set("page", descriptor->page);
|
||||||
|
}
|
||||||
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) {
|
||||||
SetDensity(image, descriptor->density);
|
SetDensity(image, descriptor->density);
|
||||||
@@ -404,7 +419,62 @@ namespace sharp {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Calculate the (left, top) coordinates of the output image
|
Calculate the (left, top) coordinates of the output image
|
||||||
within the input image, applying the given gravity.
|
within the input image, applying the given gravity during an embed.
|
||||||
|
|
||||||
|
@Azurebyte: We are basically swapping the inWidth and outWidth, inHeight and outHeight from the CalculateCrop function.
|
||||||
|
*/
|
||||||
|
std::tuple<int, int> CalculateEmbedPosition(int const inWidth, int const inHeight,
|
||||||
|
int const outWidth, int const outHeight, int const gravity) {
|
||||||
|
|
||||||
|
int left = 0;
|
||||||
|
int top = 0;
|
||||||
|
switch (gravity) {
|
||||||
|
case 1:
|
||||||
|
// North
|
||||||
|
left = (outWidth - inWidth) / 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// East
|
||||||
|
left = outWidth - inWidth;
|
||||||
|
top = (outHeight - inHeight) / 2;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// South
|
||||||
|
left = (outWidth - inWidth) / 2;
|
||||||
|
top = outHeight - inHeight;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// West
|
||||||
|
top = (outHeight - inHeight) / 2;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
// Northeast
|
||||||
|
left = outWidth - inWidth;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
// Southeast
|
||||||
|
left = outWidth - inWidth;
|
||||||
|
top = outHeight - inHeight;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
// Southwest
|
||||||
|
top = outHeight - inHeight;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
// Northwest
|
||||||
|
// Which is the default is 0,0 so we do not assign anything here.
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Centre
|
||||||
|
left = (outWidth - inWidth) / 2;
|
||||||
|
top = (outHeight - inHeight) / 2;
|
||||||
|
}
|
||||||
|
return std::make_tuple(left, top);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Calculate the (left, top) coordinates of the output image
|
||||||
|
within the input image, applying the given gravity during a crop.
|
||||||
*/
|
*/
|
||||||
std::tuple<int, int> CalculateCrop(int const inWidth, int const inHeight,
|
std::tuple<int, int> CalculateCrop(int const inWidth, int const inHeight,
|
||||||
int const outWidth, int const outHeight, int const gravity) {
|
int const outWidth, int const outHeight, int const gravity) {
|
||||||
|
|||||||
21
src/common.h
@@ -25,17 +25,17 @@
|
|||||||
|
|
||||||
// Verify platform and compiler compatibility
|
// Verify platform and compiler compatibility
|
||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 5))
|
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 6))
|
||||||
#error libvips version 8.5.x required - see sharp.dimens.io/page/install
|
#error libvips version 8.6.1+ is required - see sharp.pixelplumbing.com/page/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)))
|
||||||
#error GCC version 4.6+ is required for C++11 features - see sharp.dimens.io/page/install#prerequisites
|
#error GCC version 4.6+ is required for C++11 features - see sharp.pixelplumbing.com/page/install#prerequisites
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(__clang__) && defined(__has_feature))
|
#if (defined(__clang__) && defined(__has_feature))
|
||||||
#if (!__has_feature(cxx_range_for))
|
#if (!__has_feature(cxx_range_for))
|
||||||
#error clang version 3.0+ is required for C++11 features - see sharp.dimens.io/page/install#prerequisites
|
#error clang version 3.0+ is required for C++11 features - see sharp.pixelplumbing.com/page/install#prerequisites
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -47,11 +47,13 @@ namespace sharp {
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::string file;
|
std::string file;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
bool failOnError;
|
||||||
size_t bufferLength;
|
size_t bufferLength;
|
||||||
int density;
|
int density;
|
||||||
int rawChannels;
|
int rawChannels;
|
||||||
int rawWidth;
|
int rawWidth;
|
||||||
int rawHeight;
|
int rawHeight;
|
||||||
|
int page;
|
||||||
int createChannels;
|
int createChannels;
|
||||||
int createWidth;
|
int createWidth;
|
||||||
int createHeight;
|
int createHeight;
|
||||||
@@ -59,11 +61,13 @@ namespace sharp {
|
|||||||
|
|
||||||
InputDescriptor():
|
InputDescriptor():
|
||||||
buffer(nullptr),
|
buffer(nullptr),
|
||||||
|
failOnError(FALSE),
|
||||||
bufferLength(0),
|
bufferLength(0),
|
||||||
density(72),
|
density(72),
|
||||||
rawChannels(0),
|
rawChannels(0),
|
||||||
rawWidth(0),
|
rawWidth(0),
|
||||||
rawHeight(0),
|
rawHeight(0),
|
||||||
|
page(0),
|
||||||
createChannels(0),
|
createChannels(0),
|
||||||
createWidth(0),
|
createWidth(0),
|
||||||
createHeight(0) {
|
createHeight(0) {
|
||||||
@@ -89,7 +93,7 @@ namespace sharp {
|
|||||||
|
|
||||||
// Create an InputDescriptor instance from a v8::Object describing an input image
|
// Create an InputDescriptor instance from a v8::Object describing an input image
|
||||||
InputDescriptor* CreateInputDescriptor(
|
InputDescriptor* CreateInputDescriptor(
|
||||||
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> buffersToPersist);
|
v8::Handle<v8::Object> input, std::vector<v8::Local<v8::Object>> &buffersToPersist);
|
||||||
|
|
||||||
enum class ImageType {
|
enum class ImageType {
|
||||||
JPEG,
|
JPEG,
|
||||||
@@ -204,6 +208,13 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
std::string VipsWarningPop();
|
std::string VipsWarningPop();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Calculate the (left, top) coordinates of the output image
|
||||||
|
within the input image, applying the given gravity during an embed.
|
||||||
|
*/
|
||||||
|
std::tuple<int, int> CalculateEmbedPosition(int const inWidth, int const inHeight,
|
||||||
|
int const outWidth, int const outHeight, int const gravity);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Calculate the (left, top) coordinates of the output image
|
Calculate the (left, top) coordinates of the output image
|
||||||
within the input image, applying the given gravity.
|
within the input image, applying the given gravity.
|
||||||
|
|||||||
@@ -205,6 +205,30 @@ VOption::set( const char *name, std::vector<double> value )
|
|||||||
return( this );
|
return( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// input int array
|
||||||
|
VOption *
|
||||||
|
VOption::set( const char *name, std::vector<int> value )
|
||||||
|
{
|
||||||
|
Pair *pair = new Pair( name );
|
||||||
|
|
||||||
|
int *array;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
pair->input = true;
|
||||||
|
|
||||||
|
g_value_init( &pair->value, VIPS_TYPE_ARRAY_INT );
|
||||||
|
vips_value_set_array_int( &pair->value, NULL,
|
||||||
|
static_cast< int >( value.size() ) );
|
||||||
|
array = vips_value_get_array_int( &pair->value, NULL );
|
||||||
|
|
||||||
|
for( i = 0; i < value.size(); i++ )
|
||||||
|
array[i] = value[i];
|
||||||
|
|
||||||
|
options.push_back( pair );
|
||||||
|
|
||||||
|
return( this );
|
||||||
|
}
|
||||||
|
|
||||||
// input image array
|
// input image array
|
||||||
VOption *
|
VOption *
|
||||||
VOption::set( const char *name, std::vector<VImage> value )
|
VOption::set( const char *name, std::vector<VImage> value )
|
||||||
@@ -465,7 +489,6 @@ VImage::call_option_string( const char *operation_name,
|
|||||||
operation_name );
|
operation_name );
|
||||||
|
|
||||||
if( !(operation = vips_operation_new( operation_name )) ) {
|
if( !(operation = vips_operation_new( operation_name )) ) {
|
||||||
if( options )
|
|
||||||
delete options;
|
delete options;
|
||||||
throw( VError() );
|
throw( VError() );
|
||||||
}
|
}
|
||||||
@@ -565,34 +588,6 @@ VImage::new_from_buffer( void *buf, size_t len, const char *option_string,
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
VImage
|
|
||||||
VImage::new_from_image( std::vector<double> pixel )
|
|
||||||
{
|
|
||||||
VImage onepx = VImage::black( 1, 1,
|
|
||||||
VImage::option()->set( "bands", bands() ) );
|
|
||||||
|
|
||||||
onepx = (onepx + pixel).cast( format() );
|
|
||||||
|
|
||||||
VImage big = onepx.embed( 0, 0, width(), height(),
|
|
||||||
VImage::option()->set( "extend", VIPS_EXTEND_COPY ) );
|
|
||||||
|
|
||||||
big = big.copy(
|
|
||||||
VImage::option()->
|
|
||||||
set( "interpretation", interpretation() )->
|
|
||||||
set( "xres", xres() )->
|
|
||||||
set( "yres", yres() )->
|
|
||||||
set( "xoffset", xres() )->
|
|
||||||
set( "yoffset", yres() ) );
|
|
||||||
|
|
||||||
return( big );
|
|
||||||
}
|
|
||||||
|
|
||||||
VImage
|
|
||||||
VImage::new_from_image( double pixel )
|
|
||||||
{
|
|
||||||
return( new_from_image( to_vectorv( 1, pixel ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
VImage
|
VImage
|
||||||
VImage::new_matrix( int width, int height )
|
VImage::new_matrix( int width, int height )
|
||||||
{
|
{
|
||||||
@@ -699,6 +694,17 @@ VImage::bandjoin( VImage other, VOption *options )
|
|||||||
return( bandjoin( vec, options ) );
|
return( bandjoin( vec, options ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage
|
||||||
|
VImage::composite( VImage other, VipsBlendMode mode, VOption *options )
|
||||||
|
{
|
||||||
|
VImage v[2] = { *this, other };
|
||||||
|
std::vector<VImage> ivec( v, v + VIPS_NUMBER( v ) );
|
||||||
|
int m[1] = { static_cast<int>( mode ) };
|
||||||
|
std::vector<int> mvec( m, m + VIPS_NUMBER( m ) );
|
||||||
|
|
||||||
|
return( composite( ivec, mvec, options ) );
|
||||||
|
}
|
||||||
|
|
||||||
std::complex<double>
|
std::complex<double>
|
||||||
VImage::minpos( VOption *options )
|
VImage::minpos( VOption *options )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// bodies for vips operations
|
// bodies for vips operations
|
||||||
// Mon 13 Mar 13:22:17 GMT 2017
|
// Sun 26 Nov 17:44:23 GMT 2017
|
||||||
// this file is generated automatically, do not edit!
|
// this file is generated automatically, do not edit!
|
||||||
|
|
||||||
void VImage::system( char * cmd_format , VOption *options )
|
void VImage::system( char * cmd_format , VOption *options )
|
||||||
@@ -487,6 +487,21 @@ std::vector<double> VImage::getpoint( int x , int y , VOption *options )
|
|||||||
return( out_array );
|
return( out_array );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int VImage::find_trim( int * top , int * width , int * height , VOption *options )
|
||||||
|
{
|
||||||
|
int left;
|
||||||
|
|
||||||
|
call( "find_trim" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "in", *this ) ->
|
||||||
|
set( "left", &left ) ->
|
||||||
|
set( "top", top ) ->
|
||||||
|
set( "width", width ) ->
|
||||||
|
set( "height", height ) );
|
||||||
|
|
||||||
|
return( left );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::copy( VOption *options )
|
VImage VImage::copy( VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -563,6 +578,21 @@ VImage VImage::embed( int x , int y , int width , int height , VOption *options
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::gravity( VipsCompassDirection direction , int width , int height , VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "gravity" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "in", *this ) ->
|
||||||
|
set( "out", &out ) ->
|
||||||
|
set( "direction", direction ) ->
|
||||||
|
set( "width", width ) ->
|
||||||
|
set( "height", height ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::flip( VipsDirection direction , VOption *options )
|
VImage VImage::flip( VipsDirection direction , VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -988,6 +1018,19 @@ VImage VImage::gamma( VOption *options )
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::composite( std::vector<VImage> in , std::vector<int> mode , VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "composite" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "in", in ) ->
|
||||||
|
set( "out", &out ) ->
|
||||||
|
set( "mode", mode ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::black( int width , int height , VOption *options )
|
VImage VImage::black( int width , int height , VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -1904,6 +1947,19 @@ VImage VImage::thumbnail_buffer( VipsBlob * buffer , int width , VOption *option
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::thumbnail_image( int width , VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "thumbnail_image" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "in", *this ) ->
|
||||||
|
set( "out", &out ) ->
|
||||||
|
set( "width", width ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
VImage VImage::mapim( VImage index , VOption *options )
|
VImage VImage::mapim( VImage index , VOption *options )
|
||||||
{
|
{
|
||||||
VImage out;
|
VImage out;
|
||||||
@@ -2822,6 +2878,18 @@ VImage VImage::labelregions( VOption *options )
|
|||||||
return( mask );
|
return( mask );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage VImage::fill_nearest( VOption *options )
|
||||||
|
{
|
||||||
|
VImage out;
|
||||||
|
|
||||||
|
call( "fill_nearest" ,
|
||||||
|
(options ? options : VImage::option()) ->
|
||||||
|
set( "in", *this ) ->
|
||||||
|
set( "out", &out ) );
|
||||||
|
|
||||||
|
return( out );
|
||||||
|
}
|
||||||
|
|
||||||
void VImage::draw_rect( std::vector<double> ink , int left , int top , int width , int height , VOption *options )
|
void VImage::draw_rect( std::vector<double> ink , int left , int top , int width , int height , VOption *options )
|
||||||
{
|
{
|
||||||
call( "draw_rect" ,
|
call( "draw_rect" ,
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
MetadataWorker(
|
MetadataWorker(
|
||||||
Nan::Callback *callback, MetadataBaton *baton, Nan::Callback *debuglog,
|
Nan::Callback *callback, MetadataBaton *baton, Nan::Callback *debuglog,
|
||||||
std::vector<v8::Local<v8::Object>> const buffersToPersist) :
|
std::vector<v8::Local<v8::Object>> const buffersToPersist) :
|
||||||
Nan::AsyncWorker(callback), baton(baton), debuglog(debuglog),
|
Nan::AsyncWorker(callback, "sharp:MetadataWorker"),
|
||||||
|
baton(baton), debuglog(debuglog),
|
||||||
buffersToPersist(buffersToPersist) {
|
buffersToPersist(buffersToPersist) {
|
||||||
// Protect Buffer objects from GC, keyed on index
|
// Protect Buffer objects from GC, keyed on index
|
||||||
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
||||||
@@ -81,6 +82,22 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
memcpy(baton->icc, icc, iccLength);
|
memcpy(baton->icc, icc, iccLength);
|
||||||
baton->iccLength = iccLength;
|
baton->iccLength = iccLength;
|
||||||
}
|
}
|
||||||
|
// IPTC
|
||||||
|
if (image.get_typeof(VIPS_META_IPCT_NAME) == VIPS_TYPE_BLOB) {
|
||||||
|
size_t iptcLength;
|
||||||
|
void const *iptc = image.get_blob(VIPS_META_IPCT_NAME, &iptcLength);
|
||||||
|
baton->iptc = static_cast<char *>(g_malloc(iptcLength));
|
||||||
|
memcpy(baton->iptc, iptc, iptcLength);
|
||||||
|
baton->iptcLength = iptcLength;
|
||||||
|
}
|
||||||
|
// XMP
|
||||||
|
if (image.get_typeof(VIPS_META_XMP_NAME) == VIPS_TYPE_BLOB) {
|
||||||
|
size_t xmpLength;
|
||||||
|
void const *xmp = image.get_blob(VIPS_META_XMP_NAME, &xmpLength);
|
||||||
|
baton->xmp = static_cast<char *>(g_malloc(xmpLength));
|
||||||
|
memcpy(baton->xmp, xmp, xmpLength);
|
||||||
|
baton->xmpLength = xmpLength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
@@ -123,6 +140,16 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
New("icc").ToLocalChecked(),
|
New("icc").ToLocalChecked(),
|
||||||
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
if (baton->iptcLength > 0) {
|
||||||
|
Set(info,
|
||||||
|
New("iptc").ToLocalChecked(),
|
||||||
|
Nan::NewBuffer(baton->iptc, baton->iptcLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||||
|
}
|
||||||
|
if (baton->xmpLength > 0) {
|
||||||
|
Set(info,
|
||||||
|
New("xmp").ToLocalChecked(),
|
||||||
|
Nan::NewBuffer(baton->xmp, baton->xmpLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||||
|
}
|
||||||
argv[1] = info;
|
argv[1] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +166,12 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
std::string warning = sharp::VipsWarningPop();
|
std::string warning = sharp::VipsWarningPop();
|
||||||
while (!warning.empty()) {
|
while (!warning.empty()) {
|
||||||
v8::Local<v8::Value> message[1] = { New(warning).ToLocalChecked() };
|
v8::Local<v8::Value> message[1] = { New(warning).ToLocalChecked() };
|
||||||
debuglog->Call(1, message);
|
debuglog->Call(1, message, async_resource);
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return to JavaScript
|
// Return to JavaScript
|
||||||
callback->Call(2, argv);
|
callback->Call(2, argv, async_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ struct MetadataBaton {
|
|||||||
size_t exifLength;
|
size_t exifLength;
|
||||||
char *icc;
|
char *icc;
|
||||||
size_t iccLength;
|
size_t iccLength;
|
||||||
|
char *iptc;
|
||||||
|
size_t iptcLength;
|
||||||
|
char *xmp;
|
||||||
|
size_t xmpLength;
|
||||||
std::string err;
|
std::string err;
|
||||||
|
|
||||||
MetadataBaton():
|
MetadataBaton():
|
||||||
@@ -52,7 +56,11 @@ struct MetadataBaton {
|
|||||||
exif(nullptr),
|
exif(nullptr),
|
||||||
exifLength(0),
|
exifLength(0),
|
||||||
icc(nullptr),
|
icc(nullptr),
|
||||||
iccLength(0) {}
|
iccLength(0),
|
||||||
|
iptc(nullptr),
|
||||||
|
iptcLength(0),
|
||||||
|
xmp(nullptr),
|
||||||
|
xmpLength(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
NAN_METHOD(metadata);
|
NAN_METHOD(metadata);
|
||||||
|
|||||||
@@ -152,6 +152,32 @@ namespace sharp {
|
|||||||
return dst.bandjoin(mask.cast(dst.format()));
|
return dst.bandjoin(mask.cast(dst.format()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
|
*/
|
||||||
|
VImage Tint(VImage image, double const a, double const b) {
|
||||||
|
// Get original colourspace
|
||||||
|
VipsInterpretation typeBeforeTint = image.interpretation();
|
||||||
|
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
|
||||||
|
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
|
||||||
|
}
|
||||||
|
// Create 2 band image with every pixel set to the tint chroma
|
||||||
|
std::vector<double> chromaPixel {a, b};
|
||||||
|
VImage chroma = image.new_from_image(chromaPixel);
|
||||||
|
// Extract luminance
|
||||||
|
VImage luminance = image.colourspace(VIPS_INTERPRETATION_LAB)[0];
|
||||||
|
// Create the tinted version by combining the L from the original and the chroma from the tint
|
||||||
|
VImage tinted = luminance.bandjoin(chroma).colourspace(typeBeforeTint);
|
||||||
|
// Attach original alpha channel, if any
|
||||||
|
if (HasAlpha(image)) {
|
||||||
|
// Extract original alpha channel
|
||||||
|
VImage alpha = image[image.bands() - 1];
|
||||||
|
// Join alpha channel to normalised image
|
||||||
|
tinted = tinted.bandjoin(alpha);
|
||||||
|
}
|
||||||
|
return tinted;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stretch luminance to cover full dynamic range.
|
* Stretch luminance to cover full dynamic range.
|
||||||
*/
|
*/
|
||||||
@@ -267,23 +293,6 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Insert a tile cache to prevent over-computation of any previous operations in the pipeline
|
|
||||||
*/
|
|
||||||
VImage TileCache(VImage image, double const factor) {
|
|
||||||
int tile_width;
|
|
||||||
int tile_height;
|
|
||||||
int scanline_count;
|
|
||||||
vips_get_tile_size(image.get_image(), &tile_width, &tile_height, &scanline_count);
|
|
||||||
double const need_lines = 1.2 * scanline_count / factor;
|
|
||||||
return image.tilecache(VImage::option()
|
|
||||||
->set("tile_width", image.width())
|
|
||||||
->set("tile_height", 10)
|
|
||||||
->set("max_tiles", static_cast<int>(round(1.0 + need_lines / 10.0)))
|
|
||||||
->set("access", VIPS_ACCESS_SEQUENTIAL)
|
|
||||||
->set("threaded", TRUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
VImage Threshold(VImage image, double const threshold, bool const thresholdGrayscale) {
|
VImage Threshold(VImage image, double const threshold, bool const thresholdGrayscale) {
|
||||||
if (!thresholdGrayscale) {
|
if (!thresholdGrayscale) {
|
||||||
return image >= threshold;
|
return image >= threshold;
|
||||||
@@ -358,4 +367,18 @@ namespace sharp {
|
|||||||
return image.extract_area(left, top, width, height);
|
return image.extract_area(left, top, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate (a * in + b)
|
||||||
|
*/
|
||||||
|
VImage Linear(VImage image, double const a, double const b) {
|
||||||
|
if (HasAlpha(image)) {
|
||||||
|
// Separate alpha channel
|
||||||
|
VImage imageWithoutAlpha = image.extract_band(0,
|
||||||
|
VImage::option()->set("n", image.bands() - 1));
|
||||||
|
VImage alpha = image[image.bands() - 1];
|
||||||
|
return imageWithoutAlpha.linear(a, b).bandjoin(alpha);
|
||||||
|
} else {
|
||||||
|
return image.linear(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Cutout(VImage src, VImage dst, const int gravity);
|
VImage Cutout(VImage src, VImage dst, const int gravity);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
|
*/
|
||||||
|
VImage Tint(VImage image, double const a, double const b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stretch luminance to cover full dynamic range.
|
* Stretch luminance to cover full dynamic range.
|
||||||
*/
|
*/
|
||||||
@@ -72,11 +77,6 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Sharpen(VImage image, double const sigma, double const flat, double const jagged);
|
VImage Sharpen(VImage image, double const sigma, double const flat, double const jagged);
|
||||||
|
|
||||||
/*
|
|
||||||
Insert a tile cache to prevent over-computation of any previous operations in the pipeline
|
|
||||||
*/
|
|
||||||
VImage TileCache(VImage image, double const factor);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Threshold an image
|
Threshold an image
|
||||||
*/
|
*/
|
||||||
@@ -97,6 +97,11 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Trim(VImage image, int const tolerance);
|
VImage Trim(VImage image, int const tolerance);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Linear adjustment (a * in + b)
|
||||||
|
*/
|
||||||
|
VImage Linear(VImage image, double const a, double const b);
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
#endif // SRC_OPERATIONS_H_
|
#endif // SRC_OPERATIONS_H_
|
||||||
|
|||||||
220
src/pipeline.cc
@@ -35,7 +35,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
PipelineWorker(
|
PipelineWorker(
|
||||||
Nan::Callback *callback, PipelineBaton *baton, Nan::Callback *debuglog, Nan::Callback *queueListener,
|
Nan::Callback *callback, PipelineBaton *baton, Nan::Callback *debuglog, Nan::Callback *queueListener,
|
||||||
std::vector<v8::Local<v8::Object>> const buffersToPersist) :
|
std::vector<v8::Local<v8::Object>> const buffersToPersist) :
|
||||||
Nan::AsyncWorker(callback), baton(baton), debuglog(debuglog), queueListener(queueListener),
|
Nan::AsyncWorker(callback, "sharp:PipelineWorker"),
|
||||||
|
baton(baton), debuglog(debuglog), queueListener(queueListener),
|
||||||
buffersToPersist(buffersToPersist) {
|
buffersToPersist(buffersToPersist) {
|
||||||
// Protect Buffer objects from GC, keyed on index
|
// Protect Buffer objects from GC, keyed on index
|
||||||
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
||||||
@@ -222,20 +223,27 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// If integral x and y shrink are equal, try to use shrink-on-load for JPEG and WebP,
|
// If integral x and y shrink are equal, try to use shrink-on-load for JPEG and WebP,
|
||||||
// but not when applying gamma correction, pre-resize extract or trim
|
// but not when applying gamma correction, pre-resize extract or trim
|
||||||
int shrink_on_load = 1;
|
int shrink_on_load = 1;
|
||||||
|
|
||||||
|
int shrink_on_load_factor = 1;
|
||||||
|
// Leave at least a factor of two for the final resize step, when fastShrinkOnLoad: false
|
||||||
|
// for more consistent results and avoid occasional small image shifting
|
||||||
|
if (!baton->fastShrinkOnLoad) {
|
||||||
|
shrink_on_load_factor = 2;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
xshrink == yshrink && xshrink >= 2 &&
|
xshrink == yshrink && xshrink >= 2 * shrink_on_load_factor &&
|
||||||
(inputImageType == ImageType::JPEG || inputImageType == ImageType::WEBP) &&
|
(inputImageType == ImageType::JPEG || inputImageType == ImageType::WEBP) &&
|
||||||
baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimTolerance == 0
|
baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimTolerance == 0
|
||||||
) {
|
) {
|
||||||
if (xshrink >= 8) {
|
if (xshrink >= 8 * shrink_on_load_factor) {
|
||||||
xfactor = xfactor / 8;
|
xfactor = xfactor / 8;
|
||||||
yfactor = yfactor / 8;
|
yfactor = yfactor / 8;
|
||||||
shrink_on_load = 8;
|
shrink_on_load = 8;
|
||||||
} else if (xshrink >= 4) {
|
} else if (xshrink >= 4 * shrink_on_load_factor) {
|
||||||
xfactor = xfactor / 4;
|
xfactor = xfactor / 4;
|
||||||
yfactor = yfactor / 4;
|
yfactor = yfactor / 4;
|
||||||
shrink_on_load = 4;
|
shrink_on_load = 4;
|
||||||
} else if (xshrink >= 2) {
|
} else if (xshrink >= 2 * shrink_on_load_factor) {
|
||||||
xfactor = xfactor / 2;
|
xfactor = xfactor / 2;
|
||||||
yfactor = yfactor / 2;
|
yfactor = yfactor / 2;
|
||||||
shrink_on_load = 2;
|
shrink_on_load = 2;
|
||||||
@@ -249,7 +257,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
if (shrink_on_load > 1) {
|
if (shrink_on_load > 1) {
|
||||||
// Reload input using shrink-on-load
|
// Reload input using shrink-on-load
|
||||||
vips::VOption *option = VImage::option()->set("shrink", shrink_on_load);
|
vips::VOption *option = VImage::option()
|
||||||
|
->set("access", baton->accessMethod)
|
||||||
|
->set("shrink", shrink_on_load)
|
||||||
|
->set("fail", baton->input->failOnError);
|
||||||
if (baton->input->buffer != nullptr) {
|
if (baton->input->buffer != nullptr) {
|
||||||
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
||||||
if (inputImageType == ImageType::JPEG) {
|
if (inputImageType == ImageType::JPEG) {
|
||||||
@@ -279,23 +290,6 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
xfactor = static_cast<double>(shrunkOnLoadWidth) / static_cast<double>(targetResizeWidth);
|
xfactor = static_cast<double>(shrunkOnLoadWidth) / static_cast<double>(targetResizeWidth);
|
||||||
yfactor = static_cast<double>(shrunkOnLoadHeight) / static_cast<double>(targetResizeHeight);
|
yfactor = static_cast<double>(shrunkOnLoadHeight) / static_cast<double>(targetResizeHeight);
|
||||||
xshrink = std::max(1, static_cast<int>(floor(xfactor)));
|
|
||||||
yshrink = std::max(1, static_cast<int>(floor(yfactor)));
|
|
||||||
xresidual = static_cast<double>(xshrink) / xfactor;
|
|
||||||
yresidual = static_cast<double>(yshrink) / yfactor;
|
|
||||||
if (
|
|
||||||
!baton->rotateBeforePreExtract &&
|
|
||||||
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)
|
|
||||||
) {
|
|
||||||
std::swap(xresidual, yresidual);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Help ensure a final kernel-based reduction to prevent shrink aliasing
|
|
||||||
if (xshrink > 1 && yshrink > 1 && (xresidual == 1.0 || yresidual == 1.0)) {
|
|
||||||
xshrink = xshrink / 2;
|
|
||||||
yshrink = yshrink / 2;
|
|
||||||
xresidual = static_cast<double>(xshrink) / xfactor;
|
|
||||||
yresidual = static_cast<double>(yshrink) / yfactor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we're using a device-independent colour space
|
// Ensure we're using a device-independent colour space
|
||||||
@@ -361,13 +355,14 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool const shouldShrink = xshrink > 1 || yshrink > 1;
|
bool const shouldResize = xfactor != 1.0 || yfactor != 1.0;
|
||||||
bool const shouldReduce = xresidual != 1.0 || yresidual != 1.0;
|
|
||||||
bool const shouldBlur = baton->blurSigma != 0.0;
|
bool const shouldBlur = baton->blurSigma != 0.0;
|
||||||
bool const shouldConv = baton->convKernelWidth * baton->convKernelHeight > 0;
|
bool const shouldConv = baton->convKernelWidth * baton->convKernelHeight > 0;
|
||||||
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
||||||
|
bool const shouldApplyMedian = baton->medianSize > 0;
|
||||||
|
|
||||||
bool const shouldPremultiplyAlpha = HasAlpha(image) &&
|
bool const shouldPremultiplyAlpha = HasAlpha(image) &&
|
||||||
(shouldShrink || shouldReduce || shouldBlur || shouldConv || shouldSharpen || shouldOverlayWithAlpha);
|
(shouldResize || shouldBlur || shouldConv || shouldSharpen || shouldOverlayWithAlpha);
|
||||||
|
|
||||||
// Premultiply image alpha channel before all transformations to avoid
|
// Premultiply image alpha channel before all transformations to avoid
|
||||||
// dark fringing around bright pixels
|
// dark fringing around bright pixels
|
||||||
@@ -376,40 +371,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.premultiply();
|
image = image.premultiply();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast, integral box-shrink
|
// Resize
|
||||||
if (shouldShrink) {
|
if (shouldResize) {
|
||||||
if (yshrink > 1) {
|
|
||||||
image = image.shrinkv(yshrink);
|
|
||||||
}
|
|
||||||
if (xshrink > 1) {
|
|
||||||
image = image.shrinkh(xshrink);
|
|
||||||
}
|
|
||||||
// Recalculate residual float based on dimensions of required vs shrunk images
|
|
||||||
int shrunkWidth = image.width();
|
|
||||||
int shrunkHeight = image.height();
|
|
||||||
if (!baton->rotateBeforePreExtract &&
|
|
||||||
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) {
|
|
||||||
// Swap input output width and height when rotating by 90 or 270 degrees
|
|
||||||
std::swap(shrunkWidth, shrunkHeight);
|
|
||||||
}
|
|
||||||
xresidual = static_cast<double>(targetResizeWidth) / static_cast<double>(shrunkWidth);
|
|
||||||
yresidual = static_cast<double>(targetResizeHeight) / static_cast<double>(shrunkHeight);
|
|
||||||
if (
|
|
||||||
!baton->rotateBeforePreExtract &&
|
|
||||||
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)
|
|
||||||
) {
|
|
||||||
std::swap(xresidual, yresidual);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use affine increase or kernel reduce with the remaining float part
|
|
||||||
if (xresidual != 1.0 || yresidual != 1.0) {
|
|
||||||
// Insert tile cache to prevent over-computation of previous operations
|
|
||||||
if (baton->accessMethod == VIPS_ACCESS_SEQUENTIAL) {
|
|
||||||
image = sharp::TileCache(image, yresidual);
|
|
||||||
}
|
|
||||||
// Perform kernel-based reduction
|
|
||||||
if (yresidual < 1.0 || xresidual < 1.0) {
|
|
||||||
VipsKernel kernel = static_cast<VipsKernel>(
|
VipsKernel kernel = static_cast<VipsKernel>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data()));
|
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data()));
|
||||||
if (
|
if (
|
||||||
@@ -418,37 +381,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
) {
|
) {
|
||||||
throw vips::VError("Unknown kernel");
|
throw vips::VError("Unknown kernel");
|
||||||
}
|
}
|
||||||
if (yresidual < 1.0) {
|
|
||||||
image = image.reducev(1.0 / yresidual, VImage::option()
|
image = image.resize(1.0 / xfactor, VImage::option()
|
||||||
->set("kernel", kernel)
|
->set("vscale", 1.0 / yfactor)
|
||||||
->set("centre", baton->centreSampling));
|
->set("kernel", kernel));
|
||||||
}
|
|
||||||
if (xresidual < 1.0) {
|
|
||||||
image = image.reduceh(1.0 / xresidual, VImage::option()
|
|
||||||
->set("kernel", kernel)
|
|
||||||
->set("centre", baton->centreSampling));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Perform enlargement
|
|
||||||
if (yresidual > 1.0 || xresidual > 1.0) {
|
|
||||||
if (trunc(xresidual) == xresidual && trunc(yresidual) == yresidual && baton->interpolator == "nearest") {
|
|
||||||
// Fast, integral nearest neighbour enlargement
|
|
||||||
image = image.zoom(static_cast<int>(xresidual), static_cast<int>(yresidual));
|
|
||||||
} else {
|
|
||||||
// Floating point affine transformation
|
|
||||||
vips::VInterpolate interpolator = vips::VInterpolate::new_from_name(baton->interpolator.data());
|
|
||||||
if (yresidual > 1.0 && xresidual > 1.0) {
|
|
||||||
image = image.affine({xresidual, 0.0, 0.0, yresidual}, VImage::option()
|
|
||||||
->set("interpolate", interpolator));
|
|
||||||
} else if (yresidual > 1.0) {
|
|
||||||
image = image.affine({1.0, 0.0, 0.0, yresidual}, VImage::option()
|
|
||||||
->set("interpolate", interpolator));
|
|
||||||
} else if (xresidual > 1.0) {
|
|
||||||
image = image.affine({xresidual, 0.0, 0.0, 1.0}, VImage::option()
|
|
||||||
->set("interpolate", interpolator));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate
|
// Rotate
|
||||||
@@ -513,13 +449,29 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.bandjoin(
|
image = image.bandjoin(
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Embed
|
// Embed
|
||||||
int left = static_cast<int>(round((baton->width - image.width()) / 2));
|
|
||||||
int top = static_cast<int>(round((baton->height - image.height()) / 2));
|
// Calculate where to position the embeded image if gravity specified, else center.
|
||||||
image = image.embed(left, top, baton->width, baton->height, VImage::option()
|
int left;
|
||||||
|
int top;
|
||||||
|
|
||||||
|
left = static_cast<int>(round((baton->width - image.width()) / 2));
|
||||||
|
top = static_cast<int>(round((baton->height - image.height()) / 2));
|
||||||
|
|
||||||
|
int width = std::max(image.width(), baton->width);
|
||||||
|
int height = std::max(image.height(), baton->height);
|
||||||
|
std::tie(left, top) = sharp::CalculateEmbedPosition(
|
||||||
|
image.width(), image.height(), baton->width, baton->height, baton->embed);
|
||||||
|
|
||||||
|
image = image.embed(left, top, width, height, VImage::option()
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
->set("extend", VIPS_EXTEND_BACKGROUND)
|
||||||
->set("background", background));
|
->set("background", background));
|
||||||
} else if (baton->canvas != Canvas::IGNORE_ASPECT) {
|
|
||||||
|
} else if (
|
||||||
|
baton->canvas != Canvas::IGNORE_ASPECT &&
|
||||||
|
(image.width() > baton->width || image.height() > baton->height)
|
||||||
|
) {
|
||||||
// Crop/max/min
|
// Crop/max/min
|
||||||
if (baton->crop < 9) {
|
if (baton->crop < 9) {
|
||||||
// Gravity-based crop
|
// Gravity-based crop
|
||||||
@@ -532,8 +484,20 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.extract_area(left, top, width, height);
|
image = image.extract_area(left, top, width, height);
|
||||||
} else {
|
} else {
|
||||||
// Attention-based or Entropy-based crop
|
// Attention-based or Entropy-based crop
|
||||||
|
if (baton->width > image.width()) {
|
||||||
|
baton->width = image.width();
|
||||||
|
}
|
||||||
|
if (baton->height > image.height()) {
|
||||||
|
baton->height = image.height();
|
||||||
|
}
|
||||||
|
image = image.tilecache(VImage::option()
|
||||||
|
->set("access", baton->accessMethod)
|
||||||
|
->set("threaded", TRUE));
|
||||||
image = image.smartcrop(baton->width, baton->height, VImage::option()
|
image = image.smartcrop(baton->width, baton->height, VImage::option()
|
||||||
->set("interesting", baton->crop == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION));
|
->set("interesting", baton->crop == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION));
|
||||||
|
baton->hasCropOffset = true;
|
||||||
|
baton->cropOffsetLeft = static_cast<int>(image.xoffset());
|
||||||
|
baton->cropOffsetTop = static_cast<int>(image.yoffset());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,7 +546,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
||||||
VImage::option()->set("extend", VIPS_EXTEND_BACKGROUND)->set("background", background));
|
VImage::option()->set("extend", VIPS_EXTEND_BACKGROUND)->set("background", background));
|
||||||
}
|
}
|
||||||
|
// Median - must happen before blurring, due to the utility of blurring after thresholding
|
||||||
|
if (shouldApplyMedian) {
|
||||||
|
image = image.median(baton->medianSize);
|
||||||
|
}
|
||||||
// Threshold - must happen before blurring, due to the utility of blurring after thresholding
|
// Threshold - must happen before blurring, due to the utility of blurring after thresholding
|
||||||
if (baton->threshold != 0) {
|
if (baton->threshold != 0) {
|
||||||
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
||||||
@@ -692,6 +659,11 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = sharp::Gamma(image, baton->gamma);
|
image = sharp::Gamma(image, baton->gamma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Linear adjustment (a * in + b)
|
||||||
|
if (baton->linearA != 1.0 || baton->linearB != 0.0) {
|
||||||
|
image = sharp::Linear(image, baton->linearA, baton->linearB);
|
||||||
|
}
|
||||||
|
|
||||||
// Apply normalisation - stretch luminance to cover full dynamic range
|
// Apply normalisation - stretch luminance to cover full dynamic range
|
||||||
if (baton->normalise) {
|
if (baton->normalise) {
|
||||||
image = sharp::Normalise(image);
|
image = sharp::Normalise(image);
|
||||||
@@ -710,6 +682,11 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = sharp::Bandbool(image, baton->bandBoolOp);
|
image = sharp::Bandbool(image, baton->bandBoolOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tint the image
|
||||||
|
if (baton->tintA > 0 || baton->tintB > 0) {
|
||||||
|
image = sharp::Tint(image, baton->tintA, baton->tintB);
|
||||||
|
}
|
||||||
|
|
||||||
// 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()) {
|
||||||
@@ -856,9 +833,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
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 matchInput = baton->formatOut == "input" &&
|
bool const mightMatchInput = baton->formatOut == "input";
|
||||||
!(isJpeg || isPng || isWebp || isTiff || isDz || isDzZip || isV);
|
bool const willMatchInput = mightMatchInput && !(isJpeg || isPng || isWebp || isTiff || isDz || isDzZip || isV);
|
||||||
if (baton->formatOut == "jpeg" || isJpeg || (matchInput && inputImageType == ImageType::JPEG)) {
|
if (baton->formatOut == "jpeg" || (mightMatchInput && isJpeg) ||
|
||||||
|
(willMatchInput && inputImageType == ImageType::JPEG)) {
|
||||||
// Write JPEG to file
|
// Write JPEG to file
|
||||||
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
||||||
image.jpegsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.jpegsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
@@ -872,7 +850,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("optimize_coding", TRUE));
|
->set("optimize_coding", TRUE));
|
||||||
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" || isPng || (matchInput &&
|
} else if (baton->formatOut == "png" || (mightMatchInput && isPng) || (willMatchInput &&
|
||||||
(inputImageType == ImageType::PNG || inputImageType == ImageType::GIF || inputImageType == ImageType::SVG))) {
|
(inputImageType == ImageType::PNG || inputImageType == ImageType::GIF || inputImageType == ImageType::SVG))) {
|
||||||
// Write PNG to file
|
// Write PNG to file
|
||||||
sharp::AssertImageTypeDimensions(image, ImageType::PNG);
|
sharp::AssertImageTypeDimensions(image, ImageType::PNG);
|
||||||
@@ -885,9 +863,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE));
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE));
|
||||||
baton->formatOut = "png";
|
baton->formatOut = "png";
|
||||||
} else if (baton->formatOut == "webp" || isWebp || (matchInput && inputImageType == ImageType::WEBP)) {
|
} else if (baton->formatOut == "webp" || (mightMatchInput && isWebp) ||
|
||||||
|
(willMatchInput && inputImageType == ImageType::WEBP)) {
|
||||||
// Write WEBP to file
|
// Write WEBP to file
|
||||||
AssertImageTypeDimensions(image, ImageType::WEBP);
|
sharp::AssertImageTypeDimensions(image, ImageType::WEBP);
|
||||||
image.webpsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.webpsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
@@ -895,7 +874,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
->set("alpha_q", baton->webpAlphaQuality));
|
->set("alpha_q", baton->webpAlphaQuality));
|
||||||
baton->formatOut = "webp";
|
baton->formatOut = "webp";
|
||||||
} else if (baton->formatOut == "tiff" || isTiff || (matchInput && inputImageType == ImageType::TIFF)) {
|
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
||||||
|
(willMatchInput && inputImageType == ImageType::TIFF)) {
|
||||||
// Write TIFF to file
|
// Write TIFF to file
|
||||||
if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
|
if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
|
||||||
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
sharp::AssertImageTypeDimensions(image, ImageType::JPEG);
|
||||||
@@ -957,9 +937,11 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("overlap", baton->tileOverlap)
|
->set("overlap", baton->tileOverlap)
|
||||||
->set("container", baton->tileContainer)
|
->set("container", baton->tileContainer)
|
||||||
->set("layout", baton->tileLayout)
|
->set("layout", baton->tileLayout)
|
||||||
->set("suffix", const_cast<char*>(suffix.data())));
|
->set("suffix", const_cast<char*>(suffix.data()))
|
||||||
|
->set("angle", CalculateAngleRotation(baton->tileAngle)));
|
||||||
baton->formatOut = "dz";
|
baton->formatOut = "dz";
|
||||||
} else if (baton->formatOut == "v" || isV || (matchInput && inputImageType == ImageType::VIPS)) {
|
} else if (baton->formatOut == "v" || (mightMatchInput && isV) ||
|
||||||
|
(willMatchInput && inputImageType == ImageType::VIPS)) {
|
||||||
// Write V to file
|
// Write V to file
|
||||||
image.vipssave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.vipssave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
->set("strip", !baton->withMetadata));
|
->set("strip", !baton->withMetadata));
|
||||||
@@ -1005,9 +987,11 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
Set(info, New("height").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(height)));
|
Set(info, New("height").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(height)));
|
||||||
Set(info, New("channels").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(baton->channels)));
|
Set(info, New("channels").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(baton->channels)));
|
||||||
Set(info, New("premultiplied").ToLocalChecked(), New<v8::Boolean>(baton->premultiplied));
|
Set(info, New("premultiplied").ToLocalChecked(), New<v8::Boolean>(baton->premultiplied));
|
||||||
if (baton->cropCalcLeft != -1 && baton->cropCalcLeft != -1) {
|
if (baton->hasCropOffset) {
|
||||||
Set(info, New("cropCalcLeft").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(baton->cropCalcLeft)));
|
Set(info, New("cropOffsetLeft").ToLocalChecked(),
|
||||||
Set(info, New("cropCalcTop").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(baton->cropCalcTop)));
|
New<v8::Int32>(static_cast<int32_t>(baton->cropOffsetLeft)));
|
||||||
|
Set(info, New("cropOffsetTop").ToLocalChecked(),
|
||||||
|
New<v8::Int32>(static_cast<int32_t>(baton->cropOffsetTop)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baton->bufferOutLength > 0) {
|
if (baton->bufferOutLength > 0) {
|
||||||
@@ -1047,18 +1031,18 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
std::string warning = sharp::VipsWarningPop();
|
std::string warning = sharp::VipsWarningPop();
|
||||||
while (!warning.empty()) {
|
while (!warning.empty()) {
|
||||||
v8::Local<v8::Value> message[1] = { New(warning).ToLocalChecked() };
|
v8::Local<v8::Value> message[1] = { New(warning).ToLocalChecked() };
|
||||||
debuglog->Call(1, message);
|
debuglog->Call(1, message, async_resource);
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrement processing task counter
|
// Decrement processing task counter
|
||||||
g_atomic_int_dec_and_test(&sharp::counterProcess);
|
g_atomic_int_dec_and_test(&sharp::counterProcess);
|
||||||
v8::Local<v8::Value> queueLength[1] = { New<v8::Uint32>(sharp::counterQueue) };
|
v8::Local<v8::Value> queueLength[1] = { New<v8::Uint32>(sharp::counterQueue) };
|
||||||
queueListener->Call(1, queueLength);
|
queueListener->Call(1, queueLength, async_resource);
|
||||||
delete queueListener;
|
delete queueListener;
|
||||||
|
|
||||||
// Return to JavaScript
|
// Return to JavaScript
|
||||||
callback->Call(3, argv);
|
callback->Call(3, argv, async_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -1188,6 +1172,9 @@ NAN_METHOD(pipeline) {
|
|||||||
for (unsigned int i = 0; i < 4; i++) {
|
for (unsigned int i = 0; i < 4; i++) {
|
||||||
baton->background[i] = AttrTo<double>(background, i);
|
baton->background[i] = AttrTo<double>(background, i);
|
||||||
}
|
}
|
||||||
|
// Tint chroma
|
||||||
|
baton->tintA = AttrTo<double>(options, "tintA");
|
||||||
|
baton->tintB = AttrTo<double>(options, "tintB");
|
||||||
// Overlay options
|
// Overlay options
|
||||||
if (HasAttr(options, "overlay")) {
|
if (HasAttr(options, "overlay")) {
|
||||||
baton->overlay = CreateInputDescriptor(AttrAs<v8::Object>(options, "overlay"), buffersToPersist);
|
baton->overlay = CreateInputDescriptor(AttrAs<v8::Object>(options, "overlay"), buffersToPersist);
|
||||||
@@ -1200,9 +1187,9 @@ NAN_METHOD(pipeline) {
|
|||||||
// Resize options
|
// Resize options
|
||||||
baton->withoutEnlargement = AttrTo<bool>(options, "withoutEnlargement");
|
baton->withoutEnlargement = AttrTo<bool>(options, "withoutEnlargement");
|
||||||
baton->crop = AttrTo<int32_t>(options, "crop");
|
baton->crop = AttrTo<int32_t>(options, "crop");
|
||||||
|
baton->embed = AttrTo<int32_t>(options, "embed");
|
||||||
baton->kernel = AttrAsStr(options, "kernel");
|
baton->kernel = AttrAsStr(options, "kernel");
|
||||||
baton->interpolator = AttrAsStr(options, "interpolator");
|
baton->fastShrinkOnLoad = AttrTo<bool>(options, "fastShrinkOnLoad");
|
||||||
baton->centreSampling = AttrTo<bool>(options, "centreSampling");
|
|
||||||
// Join Channel Options
|
// Join Channel Options
|
||||||
if (HasAttr(options, "joinChannelIn")) {
|
if (HasAttr(options, "joinChannelIn")) {
|
||||||
v8::Local<v8::Object> joinChannelObject = Nan::Get(options, Nan::New("joinChannelIn").ToLocalChecked())
|
v8::Local<v8::Object> joinChannelObject = Nan::Get(options, Nan::New("joinChannelIn").ToLocalChecked())
|
||||||
@@ -1220,6 +1207,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->flatten = AttrTo<bool>(options, "flatten");
|
baton->flatten = AttrTo<bool>(options, "flatten");
|
||||||
baton->negate = AttrTo<bool>(options, "negate");
|
baton->negate = AttrTo<bool>(options, "negate");
|
||||||
baton->blurSigma = AttrTo<double>(options, "blurSigma");
|
baton->blurSigma = AttrTo<double>(options, "blurSigma");
|
||||||
|
baton->medianSize = AttrTo<uint32_t>(options, "medianSize");
|
||||||
baton->sharpenSigma = AttrTo<double>(options, "sharpenSigma");
|
baton->sharpenSigma = AttrTo<double>(options, "sharpenSigma");
|
||||||
baton->sharpenFlat = AttrTo<double>(options, "sharpenFlat");
|
baton->sharpenFlat = AttrTo<double>(options, "sharpenFlat");
|
||||||
baton->sharpenJagged = AttrTo<double>(options, "sharpenJagged");
|
baton->sharpenJagged = AttrTo<double>(options, "sharpenJagged");
|
||||||
@@ -1227,6 +1215,8 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->thresholdGrayscale = AttrTo<bool>(options, "thresholdGrayscale");
|
baton->thresholdGrayscale = AttrTo<bool>(options, "thresholdGrayscale");
|
||||||
baton->trimTolerance = AttrTo<int32_t>(options, "trimTolerance");
|
baton->trimTolerance = AttrTo<int32_t>(options, "trimTolerance");
|
||||||
baton->gamma = AttrTo<double>(options, "gamma");
|
baton->gamma = AttrTo<double>(options, "gamma");
|
||||||
|
baton->linearA = AttrTo<double>(options, "linearA");
|
||||||
|
baton->linearB = AttrTo<double>(options, "linearB");
|
||||||
baton->greyscale = AttrTo<bool>(options, "greyscale");
|
baton->greyscale = AttrTo<bool>(options, "greyscale");
|
||||||
baton->normalise = AttrTo<bool>(options, "normalise");
|
baton->normalise = AttrTo<bool>(options, "normalise");
|
||||||
baton->useExifOrientation = AttrTo<bool>(options, "useExifOrientation");
|
baton->useExifOrientation = AttrTo<bool>(options, "useExifOrientation");
|
||||||
@@ -1298,6 +1288,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->tileSize = AttrTo<uint32_t>(options, "tileSize");
|
baton->tileSize = AttrTo<uint32_t>(options, "tileSize");
|
||||||
baton->tileOverlap = AttrTo<uint32_t>(options, "tileOverlap");
|
baton->tileOverlap = AttrTo<uint32_t>(options, "tileOverlap");
|
||||||
std::string tileContainer = AttrAsStr(options, "tileContainer");
|
std::string tileContainer = AttrAsStr(options, "tileContainer");
|
||||||
|
baton->tileAngle = AttrTo<int32_t>(options, "tileAngle");
|
||||||
if (tileContainer == "zip") {
|
if (tileContainer == "zip") {
|
||||||
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
||||||
} else {
|
} else {
|
||||||
@@ -1332,5 +1323,6 @@ NAN_METHOD(pipeline) {
|
|||||||
// Increment queued task counter
|
// Increment queued task counter
|
||||||
g_atomic_int_inc(&sharp::counterQueue);
|
g_atomic_int_inc(&sharp::counterQueue);
|
||||||
v8::Local<v8::Value> queueLength[1] = { Nan::New<v8::Uint32>(sharp::counterQueue) };
|
v8::Local<v8::Value> queueLength[1] = { Nan::New<v8::Uint32>(sharp::counterQueue) };
|
||||||
queueListener->Call(1, queueLength);
|
v8::Local<v8::Object> recv = Nan::New<v8::Object>();
|
||||||
|
Nan::Call(*queueListener, recv, 1, queueLength);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,22 +62,28 @@ struct PipelineBaton {
|
|||||||
int channels;
|
int channels;
|
||||||
Canvas canvas;
|
Canvas canvas;
|
||||||
int crop;
|
int crop;
|
||||||
int cropCalcLeft;
|
int embed;
|
||||||
int cropCalcTop;
|
bool hasCropOffset;
|
||||||
|
int cropOffsetLeft;
|
||||||
|
int cropOffsetTop;
|
||||||
bool premultiplied;
|
bool premultiplied;
|
||||||
std::string kernel;
|
std::string kernel;
|
||||||
std::string interpolator;
|
bool fastShrinkOnLoad;
|
||||||
bool centreSampling;
|
|
||||||
double background[4];
|
double background[4];
|
||||||
|
double tintA;
|
||||||
|
double tintB;
|
||||||
bool flatten;
|
bool flatten;
|
||||||
bool negate;
|
bool negate;
|
||||||
double blurSigma;
|
double blurSigma;
|
||||||
|
int medianSize;
|
||||||
double sharpenSigma;
|
double sharpenSigma;
|
||||||
double sharpenFlat;
|
double sharpenFlat;
|
||||||
double sharpenJagged;
|
double sharpenJagged;
|
||||||
int threshold;
|
int threshold;
|
||||||
bool thresholdGrayscale;
|
bool thresholdGrayscale;
|
||||||
int trimTolerance;
|
int trimTolerance;
|
||||||
|
double linearA;
|
||||||
|
double linearB;
|
||||||
double gamma;
|
double gamma;
|
||||||
bool greyscale;
|
bool greyscale;
|
||||||
bool normalise;
|
bool normalise;
|
||||||
@@ -129,6 +135,7 @@ struct PipelineBaton {
|
|||||||
VipsForeignDzContainer tileContainer;
|
VipsForeignDzContainer tileContainer;
|
||||||
VipsForeignDzLayout tileLayout;
|
VipsForeignDzLayout tileLayout;
|
||||||
std::string tileFormat;
|
std::string tileFormat;
|
||||||
|
int tileAngle;
|
||||||
|
|
||||||
PipelineBaton():
|
PipelineBaton():
|
||||||
input(nullptr),
|
input(nullptr),
|
||||||
@@ -145,19 +152,25 @@ struct PipelineBaton {
|
|||||||
channels(0),
|
channels(0),
|
||||||
canvas(Canvas::CROP),
|
canvas(Canvas::CROP),
|
||||||
crop(0),
|
crop(0),
|
||||||
cropCalcLeft(-1),
|
embed(0),
|
||||||
cropCalcTop(-1),
|
hasCropOffset(false),
|
||||||
|
cropOffsetLeft(0),
|
||||||
|
cropOffsetTop(0),
|
||||||
premultiplied(false),
|
premultiplied(false),
|
||||||
centreSampling(false),
|
tintA(0.0),
|
||||||
|
tintB(0.0),
|
||||||
flatten(false),
|
flatten(false),
|
||||||
negate(false),
|
negate(false),
|
||||||
blurSigma(0.0),
|
blurSigma(0.0),
|
||||||
|
medianSize(0),
|
||||||
sharpenSigma(0.0),
|
sharpenSigma(0.0),
|
||||||
sharpenFlat(1.0),
|
sharpenFlat(1.0),
|
||||||
sharpenJagged(2.0),
|
sharpenJagged(2.0),
|
||||||
threshold(0),
|
threshold(0),
|
||||||
thresholdGrayscale(true),
|
thresholdGrayscale(true),
|
||||||
trimTolerance(0),
|
trimTolerance(0),
|
||||||
|
linearA(1.0),
|
||||||
|
linearB(0.0),
|
||||||
gamma(0.0),
|
gamma(0.0),
|
||||||
greyscale(false),
|
greyscale(false),
|
||||||
normalise(false),
|
normalise(false),
|
||||||
@@ -177,12 +190,12 @@ struct PipelineBaton {
|
|||||||
jpegOvershootDeringing(false),
|
jpegOvershootDeringing(false),
|
||||||
jpegOptimiseScans(false),
|
jpegOptimiseScans(false),
|
||||||
pngProgressive(false),
|
pngProgressive(false),
|
||||||
pngCompressionLevel(6),
|
pngCompressionLevel(9),
|
||||||
pngAdaptiveFiltering(true),
|
pngAdaptiveFiltering(false),
|
||||||
webpQuality(80),
|
webpQuality(80),
|
||||||
tiffQuality(80),
|
tiffQuality(80),
|
||||||
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
|
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
|
||||||
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_NONE),
|
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
||||||
tiffSquash(false),
|
tiffSquash(false),
|
||||||
tiffXres(1.0),
|
tiffXres(1.0),
|
||||||
tiffYres(1.0),
|
tiffYres(1.0),
|
||||||
@@ -200,7 +213,8 @@ struct PipelineBaton {
|
|||||||
tileSize(256),
|
tileSize(256),
|
||||||
tileOverlap(0),
|
tileOverlap(0),
|
||||||
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
||||||
tileLayout(VIPS_FOREIGN_DZ_LAYOUT_DZ) {
|
tileLayout(VIPS_FOREIGN_DZ_LAYOUT_DZ),
|
||||||
|
tileAngle(0){
|
||||||
background[0] = 0.0;
|
background[0] = 0.0;
|
||||||
background[1] = 0.0;
|
background[1] = 0.0;
|
||||||
background[2] = 0.0;
|
background[2] = 0.0;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
#include "stats.h"
|
||||||
|
|
||||||
NAN_MODULE_INIT(init) {
|
NAN_MODULE_INIT(init) {
|
||||||
vips_init("sharp");
|
vips_init("sharp");
|
||||||
@@ -46,6 +47,8 @@ NAN_MODULE_INIT(init) {
|
|||||||
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(format)).ToLocalChecked());
|
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(format)).ToLocalChecked());
|
||||||
Nan::Set(target, Nan::New("_maxColourDistance").ToLocalChecked(),
|
Nan::Set(target, Nan::New("_maxColourDistance").ToLocalChecked(),
|
||||||
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(_maxColourDistance)).ToLocalChecked());
|
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(_maxColourDistance)).ToLocalChecked());
|
||||||
|
Nan::Set(target, Nan::New("stats").ToLocalChecked(),
|
||||||
|
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(stats)).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(sharp, init)
|
NODE_MODULE(sharp, init)
|
||||||
|
|||||||
189
src/stats.cc
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <node.h>
|
||||||
|
#include <nan.h>
|
||||||
|
#include <vips/vips8>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "stats.h"
|
||||||
|
|
||||||
|
class StatsWorker : public Nan::AsyncWorker {
|
||||||
|
public:
|
||||||
|
StatsWorker(
|
||||||
|
Nan::Callback *callback, StatsBaton *baton, Nan::Callback *debuglog,
|
||||||
|
std::vector<v8::Local<v8::Object>> const buffersToPersist) :
|
||||||
|
Nan::AsyncWorker(callback, "sharp:StatsWorker"),
|
||||||
|
baton(baton), debuglog(debuglog),
|
||||||
|
buffersToPersist(buffersToPersist) {
|
||||||
|
// Protect Buffer objects from GC, keyed on index
|
||||||
|
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
||||||
|
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
||||||
|
SaveToPersistent(index, buffer);
|
||||||
|
return index + 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
~StatsWorker() {}
|
||||||
|
|
||||||
|
const int STAT_MIN_INDEX = 0;
|
||||||
|
const int STAT_MAX_INDEX = 1;
|
||||||
|
const int STAT_SUM_INDEX = 2;
|
||||||
|
const int STAT_SQ_SUM_INDEX = 3;
|
||||||
|
const int STAT_MEAN_INDEX = 4;
|
||||||
|
const int STAT_STDEV_INDEX = 5;
|
||||||
|
const int STAT_MINX_INDEX = 6;
|
||||||
|
const int STAT_MINY_INDEX = 7;
|
||||||
|
const int STAT_MAXX_INDEX = 8;
|
||||||
|
const int STAT_MAXY_INDEX = 9;
|
||||||
|
|
||||||
|
void Execute() {
|
||||||
|
// Decrement queued task counter
|
||||||
|
g_atomic_int_dec_and_test(&sharp::counterQueue);
|
||||||
|
using Nan::New;
|
||||||
|
using Nan::Set;
|
||||||
|
using sharp::MaximumImageAlpha;
|
||||||
|
|
||||||
|
vips::VImage image;
|
||||||
|
vips::VImage stats;
|
||||||
|
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::tie(image, imageType) = OpenInput(baton->input, baton->accessMethod);
|
||||||
|
} catch (vips::VError const &err) {
|
||||||
|
(baton->err).append(err.what());
|
||||||
|
}
|
||||||
|
if (imageType != sharp::ImageType::UNKNOWN) {
|
||||||
|
try {
|
||||||
|
stats = image.stats();
|
||||||
|
int bands = image.bands();
|
||||||
|
double const max = MaximumImageAlpha(image.interpretation());
|
||||||
|
for (int b = 1; b <= bands; b++) {
|
||||||
|
ChannelStats cStats(static_cast<int>(stats.getpoint(STAT_MIN_INDEX, b).front()),
|
||||||
|
static_cast<int>(stats.getpoint(STAT_MAX_INDEX, b).front()),
|
||||||
|
stats.getpoint(STAT_SUM_INDEX, b).front(), stats.getpoint(STAT_SQ_SUM_INDEX, b).front(),
|
||||||
|
stats.getpoint(STAT_MEAN_INDEX, b).front(), stats.getpoint(STAT_STDEV_INDEX, b).front(),
|
||||||
|
static_cast<int>(stats.getpoint(STAT_MINX_INDEX, b).front()),
|
||||||
|
static_cast<int>(stats.getpoint(STAT_MINY_INDEX, b).front()),
|
||||||
|
static_cast<int>(stats.getpoint(STAT_MAXX_INDEX, b).front()),
|
||||||
|
static_cast<int>(stats.getpoint(STAT_MAXY_INDEX, b).front()));
|
||||||
|
baton->channelStats.push_back(cStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
// alpha layer is there and the last band i.e. alpha has its max value greater than 0)
|
||||||
|
if (sharp::HasAlpha(image) && stats.getpoint(STAT_MIN_INDEX, bands).front() != max) {
|
||||||
|
baton->isOpaque = false;
|
||||||
|
}
|
||||||
|
} catch (vips::VError const &err) {
|
||||||
|
(baton->err).append(err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
vips_error_clear();
|
||||||
|
vips_thread_shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleOKCallback() {
|
||||||
|
using Nan::New;
|
||||||
|
using Nan::Set;
|
||||||
|
Nan::HandleScope();
|
||||||
|
|
||||||
|
v8::Local<v8::Value> argv[2] = { Nan::Null(), Nan::Null() };
|
||||||
|
if (!baton->err.empty()) {
|
||||||
|
argv[0] = Nan::Error(baton->err.data());
|
||||||
|
} else {
|
||||||
|
// Stats Object
|
||||||
|
v8::Local<v8::Object> info = New<v8::Object>();
|
||||||
|
v8::Local<v8::Array> channels = New<v8::Array>();
|
||||||
|
|
||||||
|
std::vector<ChannelStats>::iterator it;
|
||||||
|
int i = 0;
|
||||||
|
for (it=baton->channelStats.begin() ; it < baton->channelStats.end(); it++, i++) {
|
||||||
|
v8::Local<v8::Object> channelStat = New<v8::Object>();
|
||||||
|
Set(channelStat, New("min").ToLocalChecked(), New<v8::Number>(it->min));
|
||||||
|
Set(channelStat, New("max").ToLocalChecked(), New<v8::Number>(it->max));
|
||||||
|
Set(channelStat, New("sum").ToLocalChecked(), New<v8::Number>(it->sum));
|
||||||
|
Set(channelStat, New("squaresSum").ToLocalChecked(), New<v8::Number>(it->squaresSum));
|
||||||
|
Set(channelStat, New("mean").ToLocalChecked(), New<v8::Number>(it->mean));
|
||||||
|
Set(channelStat, New("stdev").ToLocalChecked(), New<v8::Number>(it->stdev));
|
||||||
|
Set(channelStat, New("minX").ToLocalChecked(), New<v8::Number>(it->minX));
|
||||||
|
Set(channelStat, New("minY").ToLocalChecked(), New<v8::Number>(it->minY));
|
||||||
|
Set(channelStat, New("maxX").ToLocalChecked(), New<v8::Number>(it->maxX));
|
||||||
|
Set(channelStat, New("maxY").ToLocalChecked(), New<v8::Number>(it->maxY));
|
||||||
|
channels->Set(i, channelStat);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set(info, New("channels").ToLocalChecked(), channels);
|
||||||
|
Set(info, New("isOpaque").ToLocalChecked(), New<v8::Boolean>(baton->isOpaque));
|
||||||
|
argv[1] = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispose of Persistent wrapper around input Buffers so they can be garbage collected
|
||||||
|
std::accumulate(buffersToPersist.begin(), buffersToPersist.end(), 0,
|
||||||
|
[this](uint32_t index, v8::Local<v8::Object> const buffer) -> uint32_t {
|
||||||
|
GetFromPersistent(index);
|
||||||
|
return index + 1;
|
||||||
|
});
|
||||||
|
delete baton->input;
|
||||||
|
delete baton;
|
||||||
|
|
||||||
|
// Handle warnings
|
||||||
|
std::string warning = sharp::VipsWarningPop();
|
||||||
|
while (!warning.empty()) {
|
||||||
|
v8::Local<v8::Value> message[1] = { New(warning).ToLocalChecked() };
|
||||||
|
debuglog->Call(1, message, async_resource);
|
||||||
|
warning = sharp::VipsWarningPop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return to JavaScript
|
||||||
|
callback->Call(2, argv, async_resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
StatsBaton* baton;
|
||||||
|
Nan::Callback *debuglog;
|
||||||
|
std::vector<v8::Local<v8::Object>> buffersToPersist;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
stats(options, callback)
|
||||||
|
*/
|
||||||
|
NAN_METHOD(stats) {
|
||||||
|
using sharp::AttrTo;
|
||||||
|
|
||||||
|
// Input Buffers must not undergo GC compaction during processing
|
||||||
|
std::vector<v8::Local<v8::Object>> buffersToPersist;
|
||||||
|
|
||||||
|
// V8 objects are converted to non-V8 types held in the baton struct
|
||||||
|
StatsBaton *baton = new StatsBaton;
|
||||||
|
v8::Local<v8::Object> options = info[0].As<v8::Object>();
|
||||||
|
|
||||||
|
// Input
|
||||||
|
baton->input = sharp::CreateInputDescriptor(sharp::AttrAs<v8::Object>(options, "input"), buffersToPersist);
|
||||||
|
baton->accessMethod = AttrTo<bool>(options, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||||
|
|
||||||
|
// Function to notify of libvips warnings
|
||||||
|
Nan::Callback *debuglog = new Nan::Callback(sharp::AttrAs<v8::Function>(options, "debuglog"));
|
||||||
|
|
||||||
|
// Join queue for worker thread
|
||||||
|
Nan::Callback *callback = new Nan::Callback(info[1].As<v8::Function>());
|
||||||
|
Nan::AsyncQueueWorker(new StatsWorker(callback, baton, debuglog, buffersToPersist));
|
||||||
|
|
||||||
|
// Increment queued task counter
|
||||||
|
g_atomic_int_inc(&sharp::counterQueue);
|
||||||
|
}
|
||||||
65
src/stats.h
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef SRC_STATS_H_
|
||||||
|
#define SRC_STATS_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <nan.h>
|
||||||
|
|
||||||
|
#include "./common.h"
|
||||||
|
|
||||||
|
struct ChannelStats {
|
||||||
|
// stats per channel
|
||||||
|
int min;
|
||||||
|
int max;
|
||||||
|
double sum;
|
||||||
|
double squaresSum;
|
||||||
|
double mean;
|
||||||
|
double stdev;
|
||||||
|
int minX;
|
||||||
|
int minY;
|
||||||
|
int maxX;
|
||||||
|
int maxY;
|
||||||
|
|
||||||
|
ChannelStats():
|
||||||
|
min(0), max(0), sum(0), squaresSum(0), mean(0), stdev(0)
|
||||||
|
, minX(0), minY(0), maxX(0), maxY(0) {}
|
||||||
|
|
||||||
|
ChannelStats(int minVal, int maxVal, double sumVal, double squaresSumVal,
|
||||||
|
double meanVal, double stdevVal, int minXVal, int minYVal, int maxXVal, int maxYVal):
|
||||||
|
min(minVal), max(maxVal), sum(sumVal), squaresSum(squaresSumVal),
|
||||||
|
mean(meanVal), stdev(stdevVal), minX(minXVal), minY(minYVal), maxX(maxXVal), maxY(maxYVal) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StatsBaton {
|
||||||
|
// Input
|
||||||
|
sharp::InputDescriptor *input;
|
||||||
|
VipsAccess accessMethod;
|
||||||
|
|
||||||
|
// Output
|
||||||
|
std::vector<ChannelStats> channelStats;
|
||||||
|
bool isOpaque;
|
||||||
|
|
||||||
|
std::string err;
|
||||||
|
|
||||||
|
StatsBaton():
|
||||||
|
input(nullptr),
|
||||||
|
isOpaque(true)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
NAN_METHOD(stats);
|
||||||
|
|
||||||
|
#endif // SRC_STATS_H_
|
||||||
@@ -8,16 +8,16 @@
|
|||||||
"test": "node perf && node random && node parallel"
|
"test": "node perf && node random && node parallel"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.5.0",
|
"async": "^2.6.0",
|
||||||
"benchmark": "^2.1.4",
|
"benchmark": "^2.1.4",
|
||||||
"gm": "^1.23.0",
|
"gm": "^1.23.1",
|
||||||
"imagemagick": "^0.1.3",
|
"imagemagick": "^0.1.3",
|
||||||
"imagemagick-native": "^1.9.3",
|
"imagemagick-native": "^1.9.3",
|
||||||
"images": "^3.0.0",
|
"images": "^3.0.1",
|
||||||
"jimp": "^0.2.28",
|
"jimp": "^0.2.28",
|
||||||
"mapnik": "^3.6.2",
|
"mapnik": "^3.6.2",
|
||||||
"pajk-lwip": "^0.2.0",
|
"pajk-lwip": "^0.2.0",
|
||||||
"semver": "^5.3.0"
|
"semver": "^5.4.1"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) {
|
|||||||
function (err, ids) {
|
function (err, ids) {
|
||||||
assert(!err);
|
assert(!err);
|
||||||
assert(ids.length === parallelism);
|
assert(ids.length === parallelism);
|
||||||
|
ids.sort();
|
||||||
const mean = ids.reduce(function (a, b) {
|
const mean = ids.reduce(function (a, b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
}) / ids.length;
|
}) / ids.length;
|
||||||
|
|||||||
@@ -601,7 +601,7 @@ async.series({
|
|||||||
callback(null, this.filter('fastest').map('name'));
|
callback(null, this.filter('fastest').map('name'));
|
||||||
}).run();
|
}).run();
|
||||||
},
|
},
|
||||||
// Comparitive speed of kernels
|
// Comparative speed of kernels
|
||||||
kernels: function (callback) {
|
kernels: function (callback) {
|
||||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
(new Benchmark.Suite('kernels')).add('sharp-cubic', {
|
(new Benchmark.Suite('kernels')).add('sharp-cubic', {
|
||||||
@@ -911,12 +911,12 @@ async.series({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).add('sharp-withoutAdaptiveFiltering', {
|
}).add('sharp-adaptiveFiltering', {
|
||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.png({ adaptiveFiltering: false })
|
.png({ adaptiveFiltering: true })
|
||||||
.toBuffer(function (err, buffer) {
|
.toBuffer(function (err, buffer) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
6
test/coverage/report.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
CPPFLAGS="--coverage" LDFLAGS="--coverage" npm rebuild
|
||||||
|
npm test
|
||||||
|
geninfo --no-external --base-directory src --output-file coverage/sharp.info build/Release/obj.target/sharp/src
|
||||||
|
genhtml --title sharp --demangle-cpp --output-directory coverage/sharp coverage/*.info
|
||||||
BIN
test/fixtures/2569067123_aca715a2ee_o.png
vendored
Normal file
|
After Width: | Height: | Size: 6.8 MiB |
BIN
test/fixtures/G31D_MULTI.TIF
vendored
Normal file
BIN
test/fixtures/Landscape_9.jpg
vendored
Normal file
|
After Width: | Height: | Size: 91 KiB |
BIN
test/fixtures/centered_image.jpeg
vendored
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
test/fixtures/embedgravitybird.png
vendored
Normal file
|
After Width: | Height: | Size: 476 KiB |
BIN
test/fixtures/expected/alpha-layer-1-fill-linear.png
vendored
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
test/fixtures/expected/alpha-layer-1-fill-offset.png
vendored
Normal file
|
After Width: | Height: | Size: 112 KiB |
BIN
test/fixtures/expected/alpha-layer-1-fill-slope.png
vendored
Normal file
|
After Width: | Height: | Size: 179 KiB |
BIN
test/fixtures/expected/alpha-layer-12.png
vendored
|
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 200 KiB |
BIN
test/fixtures/expected/crop-strategy-attention.jpg
vendored
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 5.8 KiB |
BIN
test/fixtures/expected/embed-16bit-rgba.png
vendored
|
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 910 B |
BIN
test/fixtures/expected/embed-2channel.png
vendored
|
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 857 B |
BIN
test/fixtures/expected/embed-4-into-4.png
vendored
|
Before Width: | Height: | Size: 670 B After Width: | Height: | Size: 392 B |
BIN
test/fixtures/expected/embed-enlarge.png
vendored
|
Before Width: | Height: | Size: 813 B After Width: | Height: | Size: 855 B |
BIN
test/fixtures/expected/embedgravitybird/1-nw.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/embedgravitybird/2-n.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/embedgravitybird/3-ne.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/embedgravitybird/4-e.png
vendored
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
test/fixtures/expected/embedgravitybird/5-se.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/embedgravitybird/6-s.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/embedgravitybird/7-sw.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
test/fixtures/expected/embedgravitybird/8-w.png
vendored
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
test/fixtures/expected/embedgravitybird/9-c.png
vendored
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
test/fixtures/expected/embedgravitybird/a1-nw.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a2-n.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a3-ne.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a4-e.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a5-se.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a6-s.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a7-sw.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a8-w.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
test/fixtures/expected/embedgravitybird/a9-c.png
vendored
Normal file
|
After Width: | Height: | Size: 45 KiB |