Compare commits
147 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa3ce760bb | ||
|
|
ba46ad1fd9 | ||
|
|
11214bab5d | ||
|
|
d87c289b4a | ||
|
|
af45c03b6f | ||
|
|
7d6fadce6b | ||
|
|
6b560f7a85 | ||
|
|
5d4221460d | ||
|
|
d42c383992 | ||
|
|
9c7f6fcb2b | ||
|
|
14af0bda61 | ||
|
|
fb5c393fbd | ||
|
|
69fe21a7ec | ||
|
|
da4e05c118 | ||
|
|
e4333ff6b0 | ||
|
|
4ae8999f62 | ||
|
|
3fa91bb4ce | ||
|
|
23b2e541ab | ||
|
|
5bfcf61a6f | ||
|
|
0778c112a9 | ||
|
|
2c300754a7 | ||
|
|
c610e306df | ||
|
|
417cca6e0d | ||
|
|
2ed4b5ae83 | ||
|
|
16e429cf2c | ||
|
|
6b7ce8a605 | ||
|
|
ba4ce75377 | ||
|
|
76ded7fd28 | ||
|
|
a0d1a7be50 | ||
|
|
690bc43abe | ||
|
|
50b461024d | ||
|
|
6cf0b3240d | ||
|
|
233b015d77 | ||
|
|
28de243c11 | ||
|
|
36e8a3da88 | ||
|
|
119d16cad3 | ||
|
|
38402d3185 | ||
|
|
6c02949fc1 | ||
|
|
b737d4601e | ||
|
|
3ff3353550 | ||
|
|
946d3c81a5 | ||
|
|
628996846d | ||
|
|
631a3597c7 | ||
|
|
cfa4f7d45c | ||
|
|
05d76eeadf | ||
|
|
28a6c53da0 | ||
|
|
6fcd2153c5 | ||
|
|
7ae0512b9b | ||
|
|
0890b59c32 | ||
|
|
df3ce450d9 | ||
|
|
bb0257b318 | ||
|
|
9c3597670d | ||
|
|
aa9b328778 | ||
|
|
159e8dace2 | ||
|
|
3be4d5bb45 | ||
|
|
af7caa7b25 | ||
|
|
b4ede75522 | ||
|
|
9d98114074 | ||
|
|
4ac51899c3 | ||
|
|
90a0382317 | ||
|
|
687795c801 | ||
|
|
2e0fbbb942 | ||
|
|
0a3512d066 | ||
|
|
6032171f91 | ||
|
|
fc178de309 | ||
|
|
3f4398457f | ||
|
|
b494b2e872 | ||
|
|
18afcf5f90 | ||
|
|
87a422942d | ||
|
|
ac515121e5 | ||
|
|
2bfea0ad76 | ||
|
|
83cdb558f6 | ||
|
|
9ee377963e | ||
|
|
9cc06c887b | ||
|
|
7457b50373 | ||
|
|
6387fb79b1 | ||
|
|
54e5514b9a | ||
|
|
1e4597c284 | ||
|
|
7cafd4386c | ||
|
|
e3549ba28c | ||
|
|
d1bbe62e52 | ||
|
|
36af74a09b | ||
|
|
5afe02be60 | ||
|
|
2262959673 | ||
|
|
ba3f914445 | ||
|
|
770be35c44 | ||
|
|
cc9f2b90fd | ||
|
|
4aff57b071 | ||
|
|
1df8d82fe0 | ||
|
|
98e90784f4 | ||
|
|
87ea54cc66 | ||
|
|
d5e98bc8ad | ||
|
|
fa69ff773a | ||
|
|
a183bb1cac | ||
|
|
cf62372cab | ||
|
|
56fa9c95a1 | ||
|
|
32a34a8841 | ||
|
|
98797445de | ||
|
|
bd377438b6 | ||
|
|
9dd6510de6 | ||
|
|
93ad9d4a4a | ||
|
|
4c01a099ea | ||
|
|
8e70579e47 | ||
|
|
ee8bfa3980 | ||
|
|
c5dfa49cae | ||
|
|
0822404129 | ||
|
|
144f39cd45 | ||
|
|
87f191fd05 | ||
|
|
37ed436202 | ||
|
|
88e490356d | ||
|
|
7c631c0787 | ||
|
|
f5d3721fe0 | ||
|
|
cc633589d9 | ||
|
|
cc1d4c1a6d | ||
|
|
30ca424942 | ||
|
|
813831acf0 | ||
|
|
a54fe9f77c | ||
|
|
8c6da5548a | ||
|
|
a2aa7d69e7 | ||
|
|
34d5252242 | ||
|
|
f31e4d2869 | ||
|
|
c695c40abc | ||
|
|
fd1ca1dbb2 | ||
|
|
f25dbd5f61 | ||
|
|
541e7104fd | ||
|
|
94945cf6ac | ||
|
|
db76e655f8 | ||
|
|
d43c7b581d | ||
|
|
383b933e26 | ||
|
|
d26ccf6294 | ||
|
|
6f9699f605 | ||
|
|
1e9093d781 | ||
|
|
9dc6492e52 | ||
|
|
d22f7cae6a | ||
|
|
473afaab45 | ||
|
|
dcd68303a4 | ||
|
|
03394556b5 | ||
|
|
1c4f6f75f3 | ||
|
|
f00928dedb | ||
|
|
a48f8fbb61 | ||
|
|
1fa388370e | ||
|
|
95ef6b3f71 | ||
|
|
de11d36d00 | ||
|
|
d77c2adabe | ||
|
|
c89c055ae0 | ||
|
|
dac8117f32 | ||
|
|
937b091bab |
23
CONTRIBUTING.md → .github/CONTRIBUTING.md
vendored
@@ -12,9 +12,12 @@ New bugs are assigned a `triage` label whilst under investigation.
|
|||||||
|
|
||||||
## Submit a new feature request
|
## Submit a new feature request
|
||||||
|
|
||||||
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](https://libvips.github.io/libvips/API/current/) the feature you need.
|
Implementation is usually straightforward if libvips
|
||||||
|
[already supports](https://libvips.github.io/libvips/API/current/func-list.html)
|
||||||
|
the feature you need.
|
||||||
|
|
||||||
## Submit a Pull Request to fix a bug
|
## Submit a Pull Request to fix a bug
|
||||||
|
|
||||||
@@ -41,18 +44,18 @@ Any change that modifies the existing public API should be added to the relevant
|
|||||||
|
|
||||||
| Release | WIP branch |
|
| Release | WIP branch |
|
||||||
| ------: | :--------- |
|
| ------: | :--------- |
|
||||||
| v0.21.0 | teeth |
|
| v0.24.0 | wit |
|
||||||
| v0.22.0 | uptake |
|
| v0.25.0 | yield |
|
||||||
|
|
||||||
Please squash your changes into a single commit using a command like `git rebase -i upstream/<wip-branch>`.
|
Please squash your changes into a single commit using a command like `git rebase -i upstream/<wip-branch>`.
|
||||||
|
|
||||||
### Add a new public method
|
### Add a new public method
|
||||||
|
|
||||||
The API tries to be as fluent as possible. Image processing concepts follow the naming conventions from _libvips_ and, to a lesser extent, _ImageMagick_.
|
The API tries to be as fluent as possible.
|
||||||
|
Image processing concepts follow the naming conventions from libvips and, to a lesser extent, ImageMagick.
|
||||||
|
|
||||||
Most methods have optional parameters and assume sensible defaults. Methods with mandatory parameters often have names like `doSomethingWith(X)`.
|
Most methods have optional parameters and assume sensible defaults.
|
||||||
|
Please ensure backwards compatibility where possible.
|
||||||
Please ensure backwards compatibility where possible. Methods to modify previously default behaviour often have names like `withoutOptionY()` or `withExtraZ()`.
|
|
||||||
|
|
||||||
Feel free to create a [new issue](https://github.com/lovell/sharp/issues/new) to gather feedback on a potential API change.
|
Feel free to create a [new issue](https://github.com/lovell/sharp/issues/new) to gather feedback on a potential API change.
|
||||||
|
|
||||||
@@ -60,7 +63,7 @@ Feel free to create a [new issue](https://github.com/lovell/sharp/issues/new) to
|
|||||||
|
|
||||||
A method to be removed should be deprecated in the next major version then removed in the following major version.
|
A method to be removed should be deprecated in the next major version then removed in the following major version.
|
||||||
|
|
||||||
By way of example, the [bilinearInterpolation method](https://github.com/lovell/sharp/blob/v0.6.0/index.js#L155) present in v0.5.0 was deprecated in v0.6.0 and removed in v0.7.0.
|
By way of example, the `background()` method present in v0.20.0 was deprecated in v0.21.0 and removed in v0.22.0.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
@@ -95,5 +98,5 @@ Please feel free to ask any questions via a
|
|||||||
[new issue](https://github.com/lovell/sharp/issues/new).
|
[new issue](https://github.com/lovell/sharp/issues/new).
|
||||||
|
|
||||||
If you're unable to post details publicly, please
|
If you're unable to post details publicly, please
|
||||||
[e-mail](https://github.com/lovell/sharp/blob/master/package.json#L4)
|
[e-mail](https://github.com/lovell/sharp/blob/master/package.json#L5)
|
||||||
for private, paid consulting.
|
for private, paid consulting.
|
||||||
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
open_collective: libvips
|
||||||
18
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
What are you trying to achieve?
|
||||||
|
|
||||||
|
Have you searched for similar feature requests?
|
||||||
|
|
||||||
|
What would you expect the API to look like?
|
||||||
|
|
||||||
|
What alternatives have you considered?
|
||||||
|
|
||||||
|
Is there a sample image that helps explain?
|
||||||
18
.github/ISSUE_TEMPLATE/installation.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
name: Installation
|
||||||
|
about: Something went wrong **installing** sharp
|
||||||
|
title: ''
|
||||||
|
labels: installation
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Did you see the [documentation relating to installation](https://sharp.pixelplumbing.com/en/stable/install/)?
|
||||||
|
|
||||||
|
Have you ensured the platform and version of Node.js used for `npm install` is the same as the platform and version of Node.js used at runtime?
|
||||||
|
|
||||||
|
If you're (mis)using `sudo npm install` have you tried with the `sudo npm install --unsafe-perm` flag?
|
||||||
|
|
||||||
|
What is the complete output of running `npm install --verbose sharp`? Have you checked this output for useful error messages?
|
||||||
|
|
||||||
|
What is the output of running `npx envinfo --binaries --languages --system --utilities`?
|
||||||
20
.github/ISSUE_TEMPLATE/possible-bug.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Possible bug
|
||||||
|
about: Something unexpected occurred **using** sharp
|
||||||
|
title: ''
|
||||||
|
labels: triage
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- If this issue relates to installation, please use https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md instead. -->
|
||||||
|
|
||||||
|
What is the output of running `npx envinfo --binaries --languages --system --utilities`?
|
||||||
|
|
||||||
|
What are the steps to reproduce?
|
||||||
|
|
||||||
|
What is the expected behaviour?
|
||||||
|
|
||||||
|
Are you able to provide a standalone code sample, without other dependencies, that demonstrates this problem?
|
||||||
|
|
||||||
|
Are you able to provide a sample image that helps explain the problem?
|
||||||
18
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
name: Question
|
||||||
|
about: For help understanding an existing feature
|
||||||
|
title: ''
|
||||||
|
labels: question
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- If this issue relates to installation, please use https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md instead. -->
|
||||||
|
|
||||||
|
What are you trying to achieve?
|
||||||
|
|
||||||
|
Have you searched for similar questions?
|
||||||
|
|
||||||
|
Are you able to provide a standalone code sample that demonstrates this question?
|
||||||
|
|
||||||
|
Are you able to provide a sample image that helps explain the question?
|
||||||
2
.gitignore
vendored
@@ -12,4 +12,6 @@ vendor
|
|||||||
.gitattributes
|
.gitattributes
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.nyc_output
|
.nyc_output
|
||||||
|
.vscode/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
.idea
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ docs/css/
|
|||||||
vendor
|
vendor
|
||||||
.prebuildrc
|
.prebuildrc
|
||||||
.nyc_output
|
.nyc_output
|
||||||
CONTRIBUTING.md
|
.github/
|
||||||
|
.vscode/
|
||||||
|
|||||||
32
.travis.yml
@@ -1,11 +1,5 @@
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- name: "Linux (glibc) - Node 6"
|
|
||||||
os: linux
|
|
||||||
dist: trusty
|
|
||||||
sudo: false
|
|
||||||
language: node_js
|
|
||||||
node_js: "6"
|
|
||||||
- name: "Linux (glibc) - Node 8"
|
- name: "Linux (glibc) - Node 8"
|
||||||
os: linux
|
os: linux
|
||||||
dist: trusty
|
dist: trusty
|
||||||
@@ -18,6 +12,12 @@ matrix:
|
|||||||
sudo: false
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: "10"
|
node_js: "10"
|
||||||
|
- name: "Linux (glibc) - Node 12"
|
||||||
|
os: linux
|
||||||
|
dist: trusty
|
||||||
|
sudo: false
|
||||||
|
language: node_js
|
||||||
|
node_js: "12"
|
||||||
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
|
||||||
@@ -41,11 +41,16 @@ matrix:
|
|||||||
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
||||||
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
script: sudo docker exec sharp sh -c "npm test"
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
- name: "OS X - Node 6"
|
- name: "Linux (musl) - Node 12"
|
||||||
os: osx
|
os: linux
|
||||||
osx_image: xcode9.2
|
dist: trusty
|
||||||
language: node_js
|
sudo: true
|
||||||
node_js: "6"
|
language: minimal
|
||||||
|
before_install:
|
||||||
|
- sudo docker run -dit --name sharp --env CI --env PREBUILD_TOKEN --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:12.0-alpine
|
||||||
|
- sudo docker exec sharp apk add build-base git python2 --update-cache
|
||||||
|
install: sudo docker exec sharp sh -c "npm install --unsafe-perm"
|
||||||
|
script: sudo docker exec sharp sh -c "npm test"
|
||||||
- name: "OS X - Node 8"
|
- name: "OS X - Node 8"
|
||||||
os: osx
|
os: osx
|
||||||
osx_image: xcode9.2
|
osx_image: xcode9.2
|
||||||
@@ -56,3 +61,8 @@ matrix:
|
|||||||
osx_image: xcode9.2
|
osx_image: xcode9.2
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: "10"
|
node_js: "10"
|
||||||
|
- name: "OS X - Node 12"
|
||||||
|
os: osx
|
||||||
|
osx_image: xcode9.2
|
||||||
|
language: node_js
|
||||||
|
node_js: "12"
|
||||||
|
|||||||
62
README.md
@@ -1,19 +1,18 @@
|
|||||||
# sharp
|
# sharp
|
||||||
|
|
||||||
|
<img src="https://raw.githubusercontent.com/lovell/sharp/master/docs/image/sharp-logo.svg?sanitize=true" width="160" height="160" alt="sharp logo" align="right">
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
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.
|
||||||
|
|
||||||
Resizing an image is typically 4x-5x faster than using the
|
Resizing an image is typically 4x-5x faster than using the
|
||||||
quickest ImageMagick and GraphicsMagick settings.
|
quickest ImageMagick and GraphicsMagick settings
|
||||||
|
due to its use of [libvips](https://github.com/libvips/libvips).
|
||||||
|
|
||||||
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
||||||
Lanczos resampling ensures quality is not sacrificed for speed.
|
Lanczos resampling ensures quality is not sacrificed for speed.
|
||||||
@@ -22,7 +21,7 @@ As well as image resizing, operations such as
|
|||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern 64-bit OS X, Windows and Linux systems running
|
Most modern 64-bit OS X, Windows and Linux systems running
|
||||||
Node versions 6, 8 and 10
|
Node versions 8, 10 and 12
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
@@ -31,22 +30,42 @@ do not require any additional install or runtime dependencies.
|
|||||||
const sharp = require('sharp');
|
const sharp = require('sharp');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Callback
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(inputBuffer)
|
sharp(inputBuffer)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
.toFile('output.webp', (err, info) => ... );
|
.toFile('output.webp', (err, info) => { ... });
|
||||||
// A Promises/A+ promise is returned when callback is not provided.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Promise
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(200)
|
.resize(200)
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then( data => ... )
|
.then( data => { ... })
|
||||||
.catch( err => ... );
|
.catch( err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Async/await
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const semiTransparentRedPng = await sharp({
|
||||||
|
create: {
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
channels: 4,
|
||||||
|
background: { r: 255, g: 0, b: 0, alpha: 0.5 }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.png()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stream
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const roundedCorners = Buffer.from(
|
const roundedCorners = Buffer.from(
|
||||||
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
|
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
|
||||||
@@ -55,7 +74,10 @@ const roundedCorners = Buffer.from(
|
|||||||
const roundedCornerResizer =
|
const roundedCornerResizer =
|
||||||
sharp()
|
sharp()
|
||||||
.resize(200, 200)
|
.resize(200, 200)
|
||||||
.overlayWith(roundedCorners, { cutout: true })
|
.composite([{
|
||||||
|
input: roundedCorners,
|
||||||
|
blend: 'dest-in'
|
||||||
|
}])
|
||||||
.png();
|
.png();
|
||||||
|
|
||||||
readableStream
|
readableStream
|
||||||
@@ -63,29 +85,29 @@ readableStream
|
|||||||
.pipe(writableStream);
|
.pipe(writableStream);
|
||||||
```
|
```
|
||||||
|
|
||||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
Visit [sharp.pixelplumbing.com](http://sharp.pixelplumbing.com/) for complete
|
Visit [sharp.pixelplumbing.com](https://sharp.pixelplumbing.com/) for complete
|
||||||
[installation instructions](http://sharp.pixelplumbing.com/page/install),
|
[installation instructions](https://sharp.pixelplumbing.com/page/install),
|
||||||
[API documentation](http://sharp.pixelplumbing.com/page/api),
|
[API documentation](https://sharp.pixelplumbing.com/page/api),
|
||||||
[benchmark tests](http://sharp.pixelplumbing.com/page/performance) and
|
[benchmark tests](https://sharp.pixelplumbing.com/page/performance) and
|
||||||
[changelog](http://sharp.pixelplumbing.com/page/changelog).
|
[changelog](https://sharp.pixelplumbing.com/page/changelog).
|
||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
A [guide for contributors](https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md)
|
A [guide for contributors](https://github.com/lovell/sharp/blob/master/.github/CONTRIBUTING.md)
|
||||||
covers reporting bugs, requesting features and submitting code changes.
|
covers reporting bugs, requesting features and submitting code changes.
|
||||||
|
|
||||||
### Licensing
|
### Licensing
|
||||||
|
|
||||||
Copyright 2013, 2014, 2015, 2016, 2017, 2018 Lovell Fuller and contributors.
|
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ build: off
|
|||||||
platform: x64
|
platform: x64
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- nodejs_version: "6"
|
|
||||||
- nodejs_version: "8"
|
- nodejs_version: "8"
|
||||||
- nodejs_version: "10"
|
- nodejs_version: "10"
|
||||||
|
- nodejs_version: "12"
|
||||||
install:
|
install:
|
||||||
- ps: Install-Product node $env:nodejs_version x64
|
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) x64
|
||||||
- npm install -g npm@5
|
- npm install -g npm@6
|
||||||
- npm install
|
- npm install
|
||||||
test_script:
|
test_script:
|
||||||
- npm test
|
- npm test
|
||||||
|
|||||||
@@ -97,7 +97,8 @@
|
|||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
'_ALLOW_KEYWORD_MACROS'
|
'_ALLOW_KEYWORD_MACROS',
|
||||||
|
'_FILE_OFFSET_BITS=64'
|
||||||
],
|
],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'../vendor/lib/libvips.lib',
|
'../vendor/lib/libvips.lib',
|
||||||
@@ -140,7 +141,6 @@
|
|||||||
'../vendor/lib/libgsf-1.so',
|
'../vendor/lib/libgsf-1.so',
|
||||||
'../vendor/lib/libgthread-2.0.so',
|
'../vendor/lib/libgthread-2.0.so',
|
||||||
'../vendor/lib/libharfbuzz.so',
|
'../vendor/lib/libharfbuzz.so',
|
||||||
'../vendor/lib/libharfbuzz-subset.so.0',
|
|
||||||
'../vendor/lib/libjpeg.so',
|
'../vendor/lib/libjpeg.so',
|
||||||
'../vendor/lib/liblcms2.so',
|
'../vendor/lib/liblcms2.so',
|
||||||
'../vendor/lib/liborc-0.4.so',
|
'../vendor/lib/liborc-0.4.so',
|
||||||
@@ -183,6 +183,9 @@
|
|||||||
},
|
},
|
||||||
'configurations': {
|
'configurations': {
|
||||||
'Release': {
|
'Release': {
|
||||||
|
'cflags_cc': [
|
||||||
|
'-Wno-cast-function-type'
|
||||||
|
],
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
'ExceptionHandling': 1
|
'ExceptionHandling': 1
|
||||||
|
|||||||
@@ -16,6 +16,22 @@ sharp('rgba.png')
|
|||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## ensureAlpha
|
||||||
|
|
||||||
|
Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp('rgb.jpg')
|
||||||
|
.ensureAlpha()
|
||||||
|
.toFile('rgba.png', function(err, info) {
|
||||||
|
// rgba.png is a 4 channel image with a fully opaque alpha channel
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
## extractChannel
|
## extractChannel
|
||||||
|
|
||||||
Extract a single channel from a multi-channel image.
|
Extract a single channel from a multi-channel image.
|
||||||
|
|||||||
@@ -1,33 +1,42 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
## overlayWith
|
## composite
|
||||||
|
|
||||||
Overlay (composite) an image over the processed (resized, extracted etc.) image.
|
Composite image(s) over the processed (resized, extracted etc.) image.
|
||||||
|
|
||||||
The overlay image must be the same size or smaller than the processed image.
|
The images to composite must be the same size or smaller than the processed image.
|
||||||
If both `top` and `left` options are provided, they take precedence over `gravity`.
|
If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||||
|
|
||||||
If the overlay image contains an alpha channel then composition with premultiplication will occur.
|
The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||||
|
`dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||||
|
`xor`, `add`, `saturate`, `multiply`, `screen`, `overlay`, `darken`, `lighten`,
|
||||||
|
`colour-dodge`, `color-dodge`, `colour-burn`,`color-burn`,
|
||||||
|
`hard-light`, `soft-light`, `difference`, `exclusion`.
|
||||||
|
|
||||||
|
More information about blend modes can be found at
|
||||||
|
[https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsBlendMode][1]
|
||||||
|
and [https://www.cairographics.org/operators/][2]
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `overlay` **([Buffer][1] \| [String][2])** Buffer containing image data or String containing the path to an image file.
|
- `images` **[Array][3]<[Object][4]>** Ordered list of images to composite
|
||||||
- `options` **[Object][3]?**
|
- `images[].input` **([Buffer][5] \| [String][6])?** Buffer containing image data, String containing the path to an image file, or Create object (see bellow)
|
||||||
- `options.gravity` **[String][2]** gravity at which to place the overlay. (optional, default `'centre'`)
|
- `images[].input.create` **[Object][4]?** describes a blank overlay to be created.
|
||||||
- `options.top` **[Number][4]?** the pixel offset from the top edge.
|
- `images[].input.create.width` **[Number][7]?**
|
||||||
- `options.left` **[Number][4]?** the pixel offset from the left edge.
|
- `images[].input.create.height` **[Number][7]?**
|
||||||
- `options.tile` **[Boolean][5]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
- `images[].input.create.channels` **[Number][7]?** 3-4
|
||||||
- `options.cutout` **[Boolean][5]** 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`)
|
- `images[].input.create.background` **([String][6] \| [Object][4])?** parsed by the [color][8] module to extract values for red, green, blue and alpha.
|
||||||
- `options.density` **[Number][4]** number representing the DPI for vector overlay image. (optional, default `72`)
|
- `images[].blend` **[String][6]** how to blend this image with the image below. (optional, default `'over'`)
|
||||||
- `options.raw` **[Object][3]?** describes overlay when using raw pixel data.
|
- `images[].gravity` **[String][6]** gravity at which to place the overlay. (optional, default `'centre'`)
|
||||||
- `options.raw.width` **[Number][4]?**
|
- `images[].top` **[Number][7]?** the pixel offset from the top edge.
|
||||||
- `options.raw.height` **[Number][4]?**
|
- `images[].left` **[Number][7]?** the pixel offset from the left edge.
|
||||||
- `options.raw.channels` **[Number][4]?**
|
- `images[].tile` **[Boolean][9]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
||||||
- `options.create` **[Object][3]?** describes a blank overlay to be created.
|
- `images[].premultiplied` **[Boolean][9]** set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option. (optional, default `false`)
|
||||||
- `options.create.width` **[Number][4]?**
|
- `images[].density` **[Number][7]** number representing the DPI for vector overlay image. (optional, default `72`)
|
||||||
- `options.create.height` **[Number][4]?**
|
- `images[].raw` **[Object][4]?** describes overlay when using raw pixel data.
|
||||||
- `options.create.channels` **[Number][4]?** 3-4
|
- `images[].raw.width` **[Number][7]?**
|
||||||
- `options.create.background` **([String][2] \| [Object][3])?** parsed by the [color][6] module to extract values for red, green, blue and alpha.
|
- `images[].raw.height` **[Number][7]?**
|
||||||
|
- `images[].raw.channels` **[Number][7]?**
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -35,9 +44,8 @@ If the overlay image contains an alpha channel then composition with premultipli
|
|||||||
sharp('input.png')
|
sharp('input.png')
|
||||||
.rotate(180)
|
.rotate(180)
|
||||||
.resize(300)
|
.resize(300)
|
||||||
.flatten()
|
.flatten( { background: '#ff6600' } )
|
||||||
.background('#ff6600')
|
.composite([{ input: 'overlay.png', gravity: 'southeast' }])
|
||||||
.overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
|
||||||
.sharpen()
|
.sharpen()
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.webp( { quality: 90 } )
|
.webp( { quality: 90 } )
|
||||||
@@ -49,20 +57,26 @@ sharp('input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][7]** Invalid parameters
|
- Throws **[Error][10]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: https://nodejs.org/api/buffer.html
|
[1]: https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsBlendMode
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[2]: https://www.cairographics.org/operators/
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[5]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[6]: https://www.npmjs.org/package/color
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
|
[8]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
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][3]?** if present, is an Object with optional attributes.
|
- `options` **[Object][3]?** if present, is an Object with optional attributes.
|
||||||
- `options.failOnError` **[Boolean][4]** by default apply a "best effort"
|
- `options.failOnError` **[Boolean][4]** by default halt processing and raise an error when loading invalid images.
|
||||||
to decode images, even if the data is corrupt or invalid. Set this flag to true
|
Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid. (optional, default `true`)
|
||||||
if you'd rather halt processing and raise an error when loading invalid images. (optional, default `false`)
|
|
||||||
- `options.density` **[Number][5]** number representing the DPI for vector images. (optional, default `72`)
|
- `options.density` **[Number][5]** number representing the DPI for vector images. (optional, default `72`)
|
||||||
- `options.page` **[Number][5]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
- `options.pages` **[Number][5]** number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages. (optional, default `1`)
|
||||||
|
- `options.page` **[Number][5]** page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default `0`)
|
||||||
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
- `options.raw.width` **[Number][5]?**
|
- `options.raw.width` **[Number][5]?**
|
||||||
- `options.raw.height` **[Number][5]?**
|
- `options.raw.height` **[Number][5]?**
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Returns **Sharp**
|
|||||||
## metadata
|
## metadata
|
||||||
|
|
||||||
Fast access to (uncached) image metadata without decoding any compressed image data.
|
Fast access to (uncached) image metadata without decoding any compressed image data.
|
||||||
A Promises/A+ promise is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||||
- `size`: Total size of image in bytes, for Stream and Buffer input only
|
- `size`: Total size of image in bytes, for Stream and Buffer input only
|
||||||
@@ -34,6 +34,9 @@ A Promises/A+ promise is returned when `callback` is not provided.
|
|||||||
- `density`: Number of pixels per inch (DPI), if present
|
- `density`: Number of pixels per inch (DPI), if present
|
||||||
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||||
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
|
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
|
- `pageHeight`: Number of pixels high each page in this PDF image will be.
|
||||||
|
- `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
- `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
|
||||||
@@ -68,7 +71,7 @@ Returns **([Promise][5]<[Object][6]> | Sharp)**
|
|||||||
## stats
|
## stats
|
||||||
|
|
||||||
Access to pixel-derived image statistics for every channel in the image.
|
Access to pixel-derived image statistics for every channel in the image.
|
||||||
A Promise is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||||
- `min` (minimum value in the channel)
|
- `min` (minimum value in the channel)
|
||||||
@@ -103,9 +106,9 @@ Returns **[Promise][5]<[Object][6]>**
|
|||||||
|
|
||||||
## limitInputPixels
|
## limitInputPixels
|
||||||
|
|
||||||
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 x 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.
|
||||||
The default limit is 268402689 (0x3FFF _ 0x3FFF) pixels.
|
The default limit is 268402689 (0x3FFF x 0x3FFF) pixels.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,8 @@ Merge alpha transparency channel, if any, with a background.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options`
|
- `options` **[Object][2]?**
|
||||||
|
- `options.background` **([String][3] \| [Object][2])** background colour, parsed by the [color][4] module, defaults to black. (optional, default `{r:0,g:0,b:0}`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -130,9 +131,12 @@ This can improve the perceived brightness of a resized image in non-linear colou
|
|||||||
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
||||||
when applying a gamma correction.
|
when applying a gamma correction.
|
||||||
|
|
||||||
|
Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `gamma` **[Number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
- `gamma` **[Number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
||||||
|
- `gammaOut` **[Number][1]?** value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][5]** Invalid parameters
|
- Throws **[Error][5]** Invalid parameters
|
||||||
@@ -254,6 +258,70 @@ Apply the linear formula a \* input + b to the image (levels adjustment)
|
|||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## recomb
|
||||||
|
|
||||||
|
Recomb the image with the specified matrix.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `inputMatrix`
|
||||||
|
- `3x3` **[Array][7]<[Array][7]<[Number][1]>>** Recombination matrix
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.recomb([
|
||||||
|
[0.3588, 0.7044, 0.1368],
|
||||||
|
[0.2990, 0.5870, 0.1140],
|
||||||
|
[0.2392, 0.4696, 0.0912],
|
||||||
|
])
|
||||||
|
.raw()
|
||||||
|
.toBuffer(function(err, data, info) {
|
||||||
|
// data contains the raw pixel data after applying the recomb
|
||||||
|
// With this example input, a sepia filter has been applied
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## modulate
|
||||||
|
|
||||||
|
Transforms the image using brightness, saturation and hue rotation.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `options` **[Object][2]?**
|
||||||
|
- `options.brightness` **[Number][1]?** Brightness multiplier
|
||||||
|
- `options.saturation` **[Number][1]?** Saturation multiplier
|
||||||
|
- `options.hue` **[Number][1]?** Degrees for hue rotation
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.modulate({
|
||||||
|
brightness: 2 // increase lightness by a factor of 2
|
||||||
|
});
|
||||||
|
|
||||||
|
sharp(input)
|
||||||
|
.modulate({
|
||||||
|
hue: 180 // hue-rotate by 180 degrees
|
||||||
|
});
|
||||||
|
|
||||||
|
// decreate brightness and saturation while also hue-rotating by 90 degrees
|
||||||
|
sharp(input)
|
||||||
|
.modulate({
|
||||||
|
brightness: 0.5,
|
||||||
|
saturation: 0.5,
|
||||||
|
hue: 90
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ 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.
|
||||||
|
|
||||||
|
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
|
See [withMetadata][1] for control over this.
|
||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `fileOut` **[String][1]** the path to write the image data to.
|
- `fileOut` **[String][2]** the path to write the image data to.
|
||||||
- `callback` **[Function][2]?** called on completion with two arguments `(err, info)`.
|
- `callback` **[Function][3]?** called on completion with two arguments `(err, info)`.
|
||||||
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
@@ -32,15 +35,19 @@ sharp(input)
|
|||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid parameters
|
- Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **[Promise][4]<[Object][5]>** when no callback is provided
|
Returns **[Promise][5]<[Object][6]>** when no callback is provided
|
||||||
|
|
||||||
## toBuffer
|
## toBuffer
|
||||||
|
|
||||||
Write output to a Buffer.
|
Write output to a Buffer.
|
||||||
JPEG, PNG, WebP, TIFF and RAW output are supported.
|
JPEG, PNG, WebP, TIFF and RAW output are supported.
|
||||||
By default, the format will match the input image, except GIF and SVG input which become PNG output.
|
|
||||||
|
If no explicit format is set, the output format will match the input image, except GIF and SVG input which become PNG output.
|
||||||
|
|
||||||
|
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
|
See [withMetadata][1] for control over this.
|
||||||
|
|
||||||
`callback`, if present, gets three arguments `(err, data, info)` where:
|
`callback`, if present, gets three arguments `(err, data, info)` where:
|
||||||
|
|
||||||
@@ -54,9 +61,9 @@ A `Promise` is returned when `callback` is not provided.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][5]?**
|
- `options` **[Object][6]?**
|
||||||
- `options.resolveWithObject` **[Boolean][6]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
- `options.resolveWithObject` **[Boolean][7]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
- `callback` **[Function][2]?**
|
- `callback` **[Function][3]?**
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -79,7 +86,7 @@ sharp(input)
|
|||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][4]<[Buffer][7]>** when no callback is provided
|
Returns **[Promise][5]<[Buffer][8]>** when no callback is provided
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
|
|
||||||
@@ -89,8 +96,8 @@ This will also convert to and add a web-friendly sRGB ICC profile.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `withMetadata` **[Object][5]?**
|
- `options` **[Object][6]?**
|
||||||
- `withMetadata.orientation` **[Number][8]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
- `options.orientation` **[Number][9]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -101,7 +108,7 @@ sharp('input.jpg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid parameters
|
- Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -111,19 +118,19 @@ Use these JPEG options for output image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][5]?** output options
|
- `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[Number][8]** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.progressive` **[Boolean][6]** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[Boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.chromaSubsampling` **[String][1]** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`)
|
- `options.chromaSubsampling` **[String][2]** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`)
|
||||||
- `options.trellisQuantisation` **[Boolean][6]** apply trellis quantisation, requires mozjpeg (optional, default `false`)
|
- `options.trellisQuantisation` **[Boolean][7]** apply trellis quantisation, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.overshootDeringing` **[Boolean][6]** apply overshoot deringing, requires mozjpeg (optional, default `false`)
|
- `options.overshootDeringing` **[Boolean][7]** apply overshoot deringing, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.optimiseScans` **[Boolean][6]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`)
|
- `options.optimiseScans` **[Boolean][7]** optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg (optional, default `false`)
|
||||||
- `options.optimizeScans` **[Boolean][6]** alternative spelling of optimiseScans (optional, default `false`)
|
- `options.optimizeScans` **[Boolean][7]** alternative spelling of optimiseScans (optional, default `false`)
|
||||||
- `options.optimiseCoding` **[Boolean][6]** optimise Huffman coding tables (optional, default `true`)
|
- `options.optimiseCoding` **[Boolean][7]** optimise Huffman coding tables (optional, default `true`)
|
||||||
- `options.optimizeCoding` **[Boolean][6]** alternative spelling of optimiseCoding (optional, default `true`)
|
- `options.optimizeCoding` **[Boolean][7]** alternative spelling of optimiseCoding (optional, default `true`)
|
||||||
- `options.quantisationTable` **[Number][8]** quantization table to use, integer 0-8, requires mozjpeg (optional, default `0`)
|
- `options.quantisationTable` **[Number][9]** quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg (optional, default `0`)
|
||||||
- `options.quantizationTable` **[Number][8]** alternative spelling of quantisationTable (optional, default `0`)
|
- `options.quantizationTable` **[Number][9]** alternative spelling of quantisationTable (optional, default `0`)
|
||||||
- `options.force` **[Boolean][6]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][7]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -137,7 +144,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid options
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -150,11 +157,16 @@ Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][5]?**
|
- `options` **[Object][6]?**
|
||||||
- `options.progressive` **[Boolean][6]** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[Boolean][7]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.compressionLevel` **[Number][8]** zlib compression level, 0-9 (optional, default `9`)
|
- `options.compressionLevel` **[Number][9]** zlib compression level, 0-9 (optional, default `9`)
|
||||||
- `options.adaptiveFiltering` **[Boolean][6]** use adaptive row filtering (optional, default `false`)
|
- `options.adaptiveFiltering` **[Boolean][7]** use adaptive row filtering (optional, default `false`)
|
||||||
- `options.force` **[Boolean][6]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.palette` **[Boolean][7]** quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant (optional, default `false`)
|
||||||
|
- `options.quality` **[Number][9]** use the lowest number of colours needed to achieve given quality, requires libvips compiled with support for libimagequant (optional, default `100`)
|
||||||
|
- `options.colours` **[Number][9]** maximum number of palette entries, requires libvips compiled with support for libimagequant (optional, default `256`)
|
||||||
|
- `options.colors` **[Number][9]** alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant (optional, default `256`)
|
||||||
|
- `options.dither` **[Number][9]** level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant (optional, default `1.0`)
|
||||||
|
- `options.force` **[Boolean][7]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -165,7 +177,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid options
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -175,12 +187,14 @@ Use these WebP options for output image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][5]?** output options
|
- `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[Number][8]** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.alphaQuality` **[Number][8]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
- `options.alphaQuality` **[Number][9]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
||||||
- `options.lossless` **[Boolean][6]** use lossless compression mode (optional, default `false`)
|
- `options.lossless` **[Boolean][7]** use lossless compression mode (optional, default `false`)
|
||||||
- `options.nearLossless` **[Boolean][6]** use near_lossless compression mode (optional, default `false`)
|
- `options.nearLossless` **[Boolean][7]** use near_lossless compression mode (optional, default `false`)
|
||||||
- `options.force` **[Boolean][6]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
- `options.smartSubsample` **[Boolean][7]** use high quality chroma subsampling (optional, default `false`)
|
||||||
|
- `options.reductionEffort` **[Number][9]** level of CPU effort to reduce file size, integer 0-6 (optional, default `4`)
|
||||||
|
- `options.force` **[Boolean][7]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -191,7 +205,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid options
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -201,14 +215,18 @@ Use these TIFF options for output image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][5]?** output options
|
- `options` **[Object][6]?** output options
|
||||||
- `options.quality` **[Number][8]** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.force` **[Boolean][6]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][7]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
||||||
- `options.compression` **[Boolean][6]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
- `options.compression` **[Boolean][7]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
||||||
- `options.predictor` **[Boolean][6]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
- `options.predictor` **[Boolean][7]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
||||||
- `options.xres` **[Number][8]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
- `options.pyramid` **[Boolean][7]** write an image pyramid (optional, default `false`)
|
||||||
- `options.yres` **[Number][8]** vertical resolution in pixels/mm (optional, default `1.0`)
|
- `options.tile` **[Boolean][7]** write a tiled tiff (optional, default `false`)
|
||||||
- `options.squash` **[Boolean][6]** squash 8-bit images down to 1 bit (optional, default `false`)
|
- `options.tileWidth` **[Boolean][7]** horizontal tile size (optional, default `256`)
|
||||||
|
- `options.tileHeight` **[Boolean][7]** vertical tile size (optional, default `256`)
|
||||||
|
- `options.xres` **[Number][9]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
||||||
|
- `options.yres` **[Number][9]** vertical resolution in pixels/mm (optional, default `1.0`)
|
||||||
|
- `options.squash` **[Boolean][7]** squash 8-bit images down to 1 bit (optional, default `false`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -223,7 +241,30 @@ sharp('input.svg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid options
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## heif
|
||||||
|
|
||||||
|
Use these HEIF options for output image.
|
||||||
|
|
||||||
|
Support for HEIF (HEIC/AVIF) is experimental.
|
||||||
|
Do not use this in production systems.
|
||||||
|
|
||||||
|
Requires a custom, globally-installed libvips compiled with support for libheif.
|
||||||
|
|
||||||
|
Most versions of libheif support only the patent-encumbered HEVC compression format.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `options` **[Object][6]?** output options
|
||||||
|
- `options.quality` **[Number][9]** quality, integer 1-100 (optional, default `80`)
|
||||||
|
- `options.compression` **[Boolean][7]** compression format: hevc, avc, jpeg, av1 (optional, default `'hevc'`)
|
||||||
|
- `options.lossless` **[Boolean][7]** use lossless compression (optional, default `false`)
|
||||||
|
|
||||||
|
|
||||||
|
- Throws **[Error][4]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -248,8 +289,8 @@ Force output to a given format.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `format` **([String][1] \| [Object][5])** as a String or an Object with an 'id' attribute
|
- `format` **([String][2] \| [Object][6])** as a String or an Object with an 'id' attribute
|
||||||
- `options` **[Object][5]** output options
|
- `options` **[Object][6]** output options
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -260,7 +301,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** unsupported format or options
|
- Throws **[Error][4]** unsupported format or options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -274,13 +315,14 @@ Warning: multiple sharp instances concurrently producing tile output can expose
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `tile` **[Object][5]?**
|
- `options` **[Object][6]?**
|
||||||
- `tile.size` **[Number][8]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
- `options.size` **[Number][9]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
||||||
- `tile.overlap` **[Number][8]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
- `options.overlap` **[Number][9]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
- `tile.angle` **[Number][8]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
- `options.angle` **[Number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
||||||
- `tile.depth` **[String][1]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
- `options.depth` **[String][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
- `tile.container` **[String][1]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
- `options.skipBlanks` **[Number][9]** threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images (optional, default `-1`)
|
||||||
- `tile.layout` **[String][1]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
- `options.container` **[String][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
|
- `options.layout` **[String][2]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -296,22 +338,24 @@ sharp('input.tiff')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][3]** Invalid parameters
|
- Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[1]: #withmetadata
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[7]: https://nodejs.org/api/buffer.html
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[8]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|||||||
@@ -30,22 +30,23 @@ Possible interpolation kernels are:
|
|||||||
|
|
||||||
- `nearest`: Use [nearest neighbour interpolation][4].
|
- `nearest`: Use [nearest neighbour interpolation][4].
|
||||||
- `cubic`: Use a [Catmull-Rom spline][5].
|
- `cubic`: Use a [Catmull-Rom spline][5].
|
||||||
- `lanczos2`: Use a [Lanczos kernel][6] with `a=2`.
|
- `mitchell`: Use a [Mitchell-Netravali spline][6].
|
||||||
|
- `lanczos2`: Use a [Lanczos kernel][7] with `a=2`.
|
||||||
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `width` **[Number][7]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
- `width` **[Number][8]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
||||||
- `height` **[Number][7]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
- `height` **[Number][8]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
||||||
- `options` **[Object][8]?**
|
- `options` **[Object][9]?**
|
||||||
- `options.width` **[String][9]?** alternative means of specifying `width`. If both are present this take priority.
|
- `options.width` **[String][10]?** alternative means of specifying `width`. If both are present this take priority.
|
||||||
- `options.height` **[String][9]?** alternative means of specifying `height`. If both are present this take priority.
|
- `options.height` **[String][10]?** alternative means of specifying `height`. If both are present this take priority.
|
||||||
- `options.fit` **[String][9]** how the image should be resized to fit both provided dimensions, one of `cover`, `contain`, `fill`, `inside` or `outside`. (optional, default `'cover'`)
|
- `options.fit` **[String][10]** how the image should be resized to fit both provided dimensions, one of `cover`, `contain`, `fill`, `inside` or `outside`. (optional, default `'cover'`)
|
||||||
- `options.position` **[String][9]** position, gravity or strategy to use when `fit` is `cover` or `contain`. (optional, default `'centre'`)
|
- `options.position` **[String][10]** position, gravity or strategy to use when `fit` is `cover` or `contain`. (optional, default `'centre'`)
|
||||||
- `options.background` **([String][9] \| [Object][8])** background colour when using a `fit` of `contain`, parsed by the [color][10] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
- `options.background` **([String][10] \| [Object][9])** background colour when using a `fit` of `contain`, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
||||||
- `options.kernel` **[String][9]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
- `options.kernel` **[String][10]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
||||||
- `options.withoutEnlargement` **[Boolean][11]** do not enlarge if the width _or_ height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. (optional, default `false`)
|
- `options.withoutEnlargement` **[Boolean][12]** do not enlarge if the width _or_ height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. (optional, default `false`)
|
||||||
- `options.fastShrinkOnLoad` **[Boolean][11]** 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.fastShrinkOnLoad` **[Boolean][12]** take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default `true`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][12]** Invalid parameters
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -124,12 +125,12 @@ This operation will always occur after resizing and extraction, if any.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `extend` **([Number][7] \| [Object][8])** single pixel count to add to all edges or an Object with per-edge counts
|
- `extend` **([Number][8] \| [Object][9])** single pixel count to add to all edges or an Object with per-edge counts
|
||||||
- `extend.top` **[Number][7]?**
|
- `extend.top` **[Number][8]?**
|
||||||
- `extend.left` **[Number][7]?**
|
- `extend.left` **[Number][8]?**
|
||||||
- `extend.bottom` **[Number][7]?**
|
- `extend.bottom` **[Number][8]?**
|
||||||
- `extend.right` **[Number][7]?**
|
- `extend.right` **[Number][8]?**
|
||||||
- `extend.background` **([String][9] \| [Object][8])** background colour, parsed by the [color][10] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
- `extend.background` **([String][10] \| [Object][9])** background colour, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -138,18 +139,17 @@ This operation will always occur after resizing and extraction, if any.
|
|||||||
// to the top, left and right edges and 20 to the bottom edge
|
// to the top, left and right edges and 20 to the bottom edge
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.resize(140)
|
.resize(140)
|
||||||
.)
|
|
||||||
.extend({
|
.extend({
|
||||||
top: 10,
|
top: 10,
|
||||||
bottom: 20,
|
bottom: 20,
|
||||||
left: 10,
|
left: 10,
|
||||||
right: 10
|
right: 10,
|
||||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||||
})
|
})
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][12]** Invalid parameters
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -163,11 +163,11 @@ Extract a region of the image.
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][8]**
|
- `options` **[Object][9]** describes the region to extract using integral pixel values
|
||||||
- `options.left` **[Number][7]** zero-indexed offset from left edge
|
- `options.left` **[Number][8]** zero-indexed offset from left edge
|
||||||
- `options.top` **[Number][7]** zero-indexed offset from top edge
|
- `options.top` **[Number][8]** zero-indexed offset from top edge
|
||||||
- `options.width` **[Number][7]** dimension of extracted image
|
- `options.width` **[Number][8]** width of region to extract
|
||||||
- `options.height` **[Number][7]** dimension of extracted image
|
- `options.height` **[Number][8]** height of region to extract
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][12]** Invalid parameters
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -200,10 +200,10 @@ The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` pro
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `threshold` **[Number][7]** the allowed difference from the top-left pixel, a number greater than zero. (optional, default `10`)
|
- `threshold` **[Number][8]** the allowed difference from the top-left pixel, a number greater than zero. (optional, default `10`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][12]** Invalid parameters
|
- Throws **[Error][13]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -217,16 +217,18 @@ Returns **Sharp**
|
|||||||
|
|
||||||
[5]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
[5]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
||||||
|
|
||||||
[6]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
|
[6]: https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[7]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[10]: https://www.npmjs.org/package/color
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[11]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
|
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|||||||
@@ -1,9 +1,161 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### v0.23 - "*vision*"
|
||||||
|
|
||||||
|
Requires libvips v8.8.1.
|
||||||
|
|
||||||
|
#### v0.23.1 - 26<sup>th</sup> September 2019
|
||||||
|
|
||||||
|
* Ensure `sharp.format.vips` is present and correct (filesystem only).
|
||||||
|
[#1813](https://github.com/lovell/sharp/issues/1813)
|
||||||
|
|
||||||
|
* Ensure invalid `width` and `height` provided as options to `resize` throw.
|
||||||
|
[#1817](https://github.com/lovell/sharp/issues/1817)
|
||||||
|
|
||||||
|
* Allow use of 'heic' and 'heif' identifiers with `toFormat`.
|
||||||
|
[#1834](https://github.com/lovell/sharp/pull/1834)
|
||||||
|
[@jaubourg](https://github.com/jaubourg)
|
||||||
|
|
||||||
|
* Add `premultiplied` option to `composite` operation.
|
||||||
|
[#1835](https://github.com/lovell/sharp/pull/1835)
|
||||||
|
[@Andargor](https://github.com/Andargor)
|
||||||
|
|
||||||
|
* Allow instance reuse with differing `toBuffer` options.
|
||||||
|
[#1860](https://github.com/lovell/sharp/pull/1860)
|
||||||
|
[@RaboliotTheGrey](https://github.com/RaboliotTheGrey)
|
||||||
|
|
||||||
|
* Ensure image is at least 3x3 pixels before attempting trim operation.
|
||||||
|
|
||||||
|
#### v0.23.0 - 29<sup>th</sup> July 2019
|
||||||
|
|
||||||
|
* Remove `overlayWith` previously deprecated in v0.22.0.
|
||||||
|
|
||||||
|
* Add experimental support for HEIF images. Requires libvips compiled with libheif.
|
||||||
|
[#1105](https://github.com/lovell/sharp/issues/1105)
|
||||||
|
|
||||||
|
* Expose libwebp `smartSubsample` and `reductionEffort` options.
|
||||||
|
[#1545](https://github.com/lovell/sharp/issues/1545)
|
||||||
|
|
||||||
|
* Add experimental support for Worker Threads.
|
||||||
|
[#1558](https://github.com/lovell/sharp/issues/1558)
|
||||||
|
|
||||||
|
* Use libvips' built-in CMYK and sRGB profiles when required.
|
||||||
|
[#1619](https://github.com/lovell/sharp/issues/1619)
|
||||||
|
|
||||||
|
* Drop support for Node.js versions 6 and 11.
|
||||||
|
[#1674](https://github.com/lovell/sharp/issues/1674)
|
||||||
|
|
||||||
|
* Expose `skipBlanks` option for tile-based output.
|
||||||
|
[#1687](https://github.com/lovell/sharp/pull/1687)
|
||||||
|
[@RaboliotTheGrey](https://github.com/RaboliotTheGrey)
|
||||||
|
|
||||||
|
* Allow use of `failOnError` option with Stream-based input.
|
||||||
|
[#1691](https://github.com/lovell/sharp/issues/1691)
|
||||||
|
|
||||||
|
* Fix rotate/extract ordering for non-90 angles.
|
||||||
|
[#1755](https://github.com/lovell/sharp/pull/1755)
|
||||||
|
[@iovdin](https://github.com/iovdin)
|
||||||
|
|
||||||
|
### v0.22 - "*uptake*"
|
||||||
|
|
||||||
|
Requires libvips v8.7.4.
|
||||||
|
|
||||||
|
#### v0.22.1 - 25<sup>th</sup> April 2019
|
||||||
|
|
||||||
|
* Add `modulate` operation for brightness, saturation and hue.
|
||||||
|
[#1601](https://github.com/lovell/sharp/pull/1601)
|
||||||
|
[@Goues](https://github.com/Goues)
|
||||||
|
|
||||||
|
* Improve help messaging should `require("sharp")` fail.
|
||||||
|
[#1638](https://github.com/lovell/sharp/pull/1638)
|
||||||
|
[@sidharthachatterjee](https://github.com/sidharthachatterjee)
|
||||||
|
|
||||||
|
* Add support for Node 12.
|
||||||
|
[#1668](https://github.com/lovell/sharp/issues/1668)
|
||||||
|
|
||||||
|
#### v0.22.0 - 18<sup>th</sup> March 2019
|
||||||
|
|
||||||
|
* Remove functions previously deprecated in v0.21.0:
|
||||||
|
`background`, `crop`, `embed`, `ignoreAspectRatio`, `max`, `min` and `withoutEnlargement`.
|
||||||
|
|
||||||
|
* Add `composite` operation supporting multiple images and blend modes; deprecate `overlayWith`.
|
||||||
|
[#728](https://github.com/lovell/sharp/issues/728)
|
||||||
|
|
||||||
|
* Add support for `pages` input option for multi-page input.
|
||||||
|
[#1566](https://github.com/lovell/sharp/issues/1566)
|
||||||
|
|
||||||
|
* Allow Stream-based input of raw pixel data.
|
||||||
|
[#1579](https://github.com/lovell/sharp/issues/1579)
|
||||||
|
|
||||||
|
* Add support for `page` input option to GIF and PDF.
|
||||||
|
[#1595](https://github.com/lovell/sharp/pull/1595)
|
||||||
|
[@ramiel](https://github.com/ramiel)
|
||||||
|
|
||||||
### v0.21 - "*teeth*"
|
### v0.21 - "*teeth*"
|
||||||
|
|
||||||
Requires libvips v8.7.0.
|
Requires libvips v8.7.0.
|
||||||
|
|
||||||
|
#### v0.21.3 - 19<sup>th</sup> January 2019
|
||||||
|
|
||||||
|
* Input image decoding now fails fast, set `failOnError` to change this behaviour.
|
||||||
|
|
||||||
|
* Failed filesystem-based input now separates missing file and invalid format errors.
|
||||||
|
[#1542](https://github.com/lovell/sharp/issues/1542)
|
||||||
|
|
||||||
|
#### v0.21.2 - 13<sup>th</sup> January 2019
|
||||||
|
|
||||||
|
* Ensure all metadata is removed from PNG output unless `withMetadata` used.
|
||||||
|
|
||||||
|
* Ensure shortest edge is at least one pixel after resizing.
|
||||||
|
[#1003](https://github.com/lovell/sharp/issues/1003)
|
||||||
|
|
||||||
|
* Add `ensureAlpha` operation to add an alpha channel, if missing.
|
||||||
|
[#1153](https://github.com/lovell/sharp/issues/1153)
|
||||||
|
|
||||||
|
* Expose `pages` and `pageHeight` metadata for multi-page input images.
|
||||||
|
[#1205](https://github.com/lovell/sharp/issues/1205)
|
||||||
|
|
||||||
|
* Expose PNG output options requiring libimagequant.
|
||||||
|
[#1484](https://github.com/lovell/sharp/issues/1484)
|
||||||
|
|
||||||
|
* Expose underlying error message for invalid input.
|
||||||
|
[#1505](https://github.com/lovell/sharp/issues/1505)
|
||||||
|
|
||||||
|
* Prevent mutatation of options passed to `jpeg`.
|
||||||
|
[#1516](https://github.com/lovell/sharp/issues/1516)
|
||||||
|
|
||||||
|
* Ensure forced output format applied correctly when output chaining.
|
||||||
|
[#1528](https://github.com/lovell/sharp/issues/1528)
|
||||||
|
|
||||||
|
#### v0.21.1 - 7<sup>th</sup> December 2018
|
||||||
|
|
||||||
|
* Install: support `sharp_dist_base_url` npm config, like existing `SHARP_DIST_BASE_URL`.
|
||||||
|
[#1422](https://github.com/lovell/sharp/pull/1422)
|
||||||
|
[@SethWen](https://github.com/SethWen)
|
||||||
|
|
||||||
|
* Ensure `channel` metadata is correct for raw, greyscale output.
|
||||||
|
[#1425](https://github.com/lovell/sharp/issues/1425)
|
||||||
|
|
||||||
|
* Add support for the "mitchell" kernel for image reductions.
|
||||||
|
[#1438](https://github.com/lovell/sharp/pull/1438)
|
||||||
|
[@Daiz](https://github.com/Daiz)
|
||||||
|
|
||||||
|
* Allow separate parameters for gamma encoding and decoding.
|
||||||
|
[#1439](https://github.com/lovell/sharp/pull/1439)
|
||||||
|
[@Daiz](https://github.com/Daiz)
|
||||||
|
|
||||||
|
* Build prototype with `Object.assign` to allow minification.
|
||||||
|
[#1475](https://github.com/lovell/sharp/pull/1475)
|
||||||
|
[@jaubourg](https://github.com/jaubourg)
|
||||||
|
|
||||||
|
* Expose libvips' recombination matrix operation.
|
||||||
|
[#1477](https://github.com/lovell/sharp/pull/1477)
|
||||||
|
[@fromkeith](https://github.com/fromkeith)
|
||||||
|
|
||||||
|
* Expose libvips' pyramid/tile options for TIFF output.
|
||||||
|
[#1483](https://github.com/lovell/sharp/pull/1483)
|
||||||
|
[@mbklein](https://github.com/mbklein)
|
||||||
|
|
||||||
#### v0.21.0 - 4<sup>th</sup> October 2018
|
#### v0.21.0 - 4<sup>th</sup> October 2018
|
||||||
|
|
||||||
* Deprecate the following resize-related functions:
|
* Deprecate the following resize-related functions:
|
||||||
|
|||||||
5
docs/image/sharp-logo.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="86 86 550 550">
|
||||||
|
<!-- Copyright 2019 Lovell Fuller. This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License. -->
|
||||||
|
<path fill="none" stroke="#9c0" stroke-width="80" d="M258.411 285.777l200.176-26.8M244.113 466.413L451.44 438.66M451.441 438.66V238.484M451.441 88.363v171.572l178.725-23.917M270.323 255.602V477.22M272.71 634.17V462.591L93.984 486.515"/>
|
||||||
|
<path fill="none" stroke="#090" stroke-width="80" d="M451.441 610.246V438.66l178.725-23.91M269.688 112.59v171.58L90.964 308.093"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 592 B |
@@ -1,11 +1,14 @@
|
|||||||
# sharp
|
# sharp
|
||||||
|
|
||||||
|
<img src="image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
||||||
|
|
||||||
The typical use case for this high speed Node.js module
|
The typical use case for this high speed Node.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.
|
||||||
|
|
||||||
Resizing an image is typically 4x-5x faster than using the
|
Resizing an image is typically 4x-5x faster than using the
|
||||||
quickest ImageMagick and GraphicsMagick settings.
|
quickest ImageMagick and GraphicsMagick settings
|
||||||
|
due to its use of [libvips](https://github.com/libvips/libvips).
|
||||||
|
|
||||||
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly.
|
||||||
Lanczos resampling ensures quality is not sacrificed for speed.
|
Lanczos resampling ensures quality is not sacrificed for speed.
|
||||||
@@ -14,7 +17,7 @@ As well as image resizing, operations such as
|
|||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern 64-bit OS X, Windows and Linux systems running
|
Most modern 64-bit OS X, Windows and Linux systems running
|
||||||
Node versions 6, 8 and 10
|
Node versions 8, 10 and 12
|
||||||
do not require any additional install or runtime dependencies.
|
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)
|
||||||
@@ -62,7 +65,7 @@ as [pngcrush](https://pmt.sourceforge.io/pngcrush/).
|
|||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
A [guide for contributors](https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md)
|
A [guide for contributors](https://github.com/lovell/sharp/blob/master/.github/CONTRIBUTING.md)
|
||||||
covers reporting bugs, requesting features and submitting code changes.
|
covers reporting bugs, requesting features and submitting code changes.
|
||||||
|
|
||||||
### Credits
|
### Credits
|
||||||
@@ -119,17 +122,23 @@ the help and code contributions of the following people:
|
|||||||
* [Aidan Hoolachan](https://github.com/ajhool)
|
* [Aidan Hoolachan](https://github.com/ajhool)
|
||||||
* [Axel Eirola](https://github.com/aeirola)
|
* [Axel Eirola](https://github.com/aeirola)
|
||||||
* [Freezy](https://github.com/freezy)
|
* [Freezy](https://github.com/freezy)
|
||||||
|
* [Julian Aubourg](https://github.com/jaubourg)
|
||||||
|
* [Keith Belovay](https://github.com/fromkeith)
|
||||||
|
* [Michael B. Klein](https://github.com/mbklein)
|
||||||
|
* [Jakub Michálek](https://github.com/Goues)
|
||||||
|
* [Ilya Ovdin](https://github.com/iovdin)
|
||||||
|
* [Andargor](https://github.com/Andargor)
|
||||||
|
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
### Licensing
|
### Licensing
|
||||||
|
|
||||||
Copyright 2013, 2014, 2015, 2016, 2017, 2018 Lovell Fuller and contributors.
|
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ yarn add sharp
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* Node v4.5.0+
|
* Node.js v8.5.0+
|
||||||
|
|
||||||
### Building from source
|
### Building from source
|
||||||
|
|
||||||
Pre-compiled binaries for sharp are provided for use with
|
Pre-compiled binaries for sharp are provided for use with
|
||||||
Node versions 6, 8 and 10 on
|
Node versions 8, 10 and 12 on
|
||||||
64-bit Windows, OS X and Linux platforms.
|
64-bit Windows, OS X and Linux platforms.
|
||||||
|
|
||||||
Sharp will be built from source at install time when:
|
Sharp will be built from source at install time when:
|
||||||
@@ -36,15 +36,16 @@ Building from source requires:
|
|||||||
[](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 8MB.
|
This involves an automated HTTPS download of approximately 10MB.
|
||||||
|
|
||||||
Most Linux-based (glibc, musl) operating systems running on x64 and ARMv6+ CPUs should "just work", e.g.:
|
Most Linux-based (glibc, musl) operating systems running on x64 and ARMv6+ CPUs should "just work", e.g.:
|
||||||
|
|
||||||
* Debian 7+
|
* Debian 8+
|
||||||
* Ubuntu 14.04+
|
* Ubuntu 14.04+
|
||||||
* Centos 7+
|
* Red Hat Enterprise 7+
|
||||||
* Alpine 3.8+ (Node 8 and 10)
|
* CentOS 7+
|
||||||
* Fedora
|
* Alpine 3.10+
|
||||||
|
* Fedora 21+
|
||||||
* openSUSE 13.2+
|
* openSUSE 13.2+
|
||||||
* Archlinux
|
* Archlinux
|
||||||
* Raspbian Jessie
|
* Raspbian Jessie
|
||||||
@@ -61,7 +62,8 @@ and `LD_LIBRARY_PATH` at runtime.
|
|||||||
|
|
||||||
This allows the use of newer versions of libvips with older versions of sharp.
|
This allows the use of newer versions of libvips with older versions of sharp.
|
||||||
|
|
||||||
For 32-bit Intel CPUs and older Linux-based operating systems such as Centos 6,
|
For 32-bit Intel CPUs and older Linux-based operating systems such as
|
||||||
|
those based on Red Hat Enterprise 6 (e.g. CentOS 6)
|
||||||
compiling libvips from source is recommended.
|
compiling libvips from source is recommended.
|
||||||
|
|
||||||
[https://libvips.github.io/libvips/install.html#building-libvips-from-a-source-tarball](https://libvips.github.io/libvips/install.html#building-libvips-from-a-source-tarball)
|
[https://libvips.github.io/libvips/install.html#building-libvips-from-a-source-tarball](https://libvips.github.io/libvips/install.html#building-libvips-from-a-source-tarball)
|
||||||
@@ -69,10 +71,12 @@ compiling libvips from source is recommended.
|
|||||||
#### Alpine Linux
|
#### Alpine Linux
|
||||||
|
|
||||||
libvips is available in the
|
libvips is available in the
|
||||||
[testing repository](https://pkgs.alpinelinux.org/packages?name=vips-dev):
|
[community repository](https://pkgs.alpinelinux.org/packages?name=vips-dev):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
apk add vips-dev fftw-dev build-base --update-cache --repository https://dl-3.alpinelinux.org/alpine/edge/testing/
|
apk add vips-dev fftw-dev build-base --update-cache \
|
||||||
|
--repository https://alpine.global.ssl.fastly.net/alpine/edge/community/ \
|
||||||
|
--repository https://alpine.global.ssl.fastly.net/alpine/edge/main
|
||||||
```
|
```
|
||||||
|
|
||||||
The smaller stack size of musl libc means
|
The smaller stack size of musl libc means
|
||||||
@@ -84,7 +88,7 @@ via `sharp.cache(false)` to avoid a stack overflow.
|
|||||||
[](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 8MB.
|
||||||
|
|
||||||
To use your own version of libvips instead of the provided binaries, make sure it is
|
To use your own 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 and
|
at least the version listed under `config.libvips` in the `package.json` file and
|
||||||
@@ -95,7 +99,9 @@ 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 13MB.
|
This involves an automated HTTPS download of approximately 10MB.
|
||||||
|
If you are having issues during installation consider removing the directory
|
||||||
|
`C:\Users\[user]\AppData\Roaming\npm-cache\_libvips`.
|
||||||
|
|
||||||
Only 64-bit (x64) `node.exe` is supported.
|
Only 64-bit (x64) `node.exe` is supported.
|
||||||
|
|
||||||
@@ -146,16 +152,25 @@ docker pull tailor/docker-libvips
|
|||||||
|
|
||||||
### AWS Lambda
|
### AWS Lambda
|
||||||
|
|
||||||
A [deployment package](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html) for the
|
Set the Lambda runtime to `nodejs10.x`.
|
||||||
[Lambda Execution Environment](http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html)
|
|
||||||
can be built using Docker.
|
The binaries in the `node_modules` directory of the
|
||||||
|
[deployment package](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html)
|
||||||
|
must be for the Linux x64 platform/architecture.
|
||||||
|
|
||||||
|
On non-Linux machines such as OS X and Windows run the following:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
rm -rf node_modules/sharp
|
rm -rf node_modules/sharp
|
||||||
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs8.10 npm install
|
npm install --arch=x64 --platform=linux --target=10.15.0 sharp
|
||||||
```
|
```
|
||||||
|
|
||||||
Set the Lambda runtime to Node.js 8.10.
|
Alternatively a Docker container closely matching the Lambda runtime can be used:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
rm -rf node_modules/sharp
|
||||||
|
docker run -v "$PWD":/var/task lambci/lambda:build-nodejs10.x npm install sharp
|
||||||
|
```
|
||||||
|
|
||||||
To get the best performance select the largest memory available.
|
To get the best performance select the largest memory available.
|
||||||
A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
||||||
@@ -217,7 +232,14 @@ you can do so via
|
|||||||
[https://github.com/lovell/sharp-libvips/releases](https://github.com/lovell/sharp-libvips/releases)
|
[https://github.com/lovell/sharp-libvips/releases](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` npm config option, e.g.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm config set sharp_dist_base_url "https://hostname/path/"
|
||||||
|
npm install sharp
|
||||||
|
```
|
||||||
|
|
||||||
|
or set the `SHARP_DIST_BASE_URL` environment variable, e.g.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
SHARP_DIST_BASE_URL="https://hostname/path/" npm install sharp
|
SHARP_DIST_BASE_URL="https://hostname/path/" npm install sharp
|
||||||
|
|||||||
@@ -4,16 +4,15 @@
|
|||||||
|
|
||||||
* AWS EC2 eu-west-1 [c5.large](https://aws.amazon.com/ec2/instance-types/c5/) (2x Xeon Platinum 8124M CPU @ 3.00GHz)
|
* AWS EC2 eu-west-1 [c5.large](https://aws.amazon.com/ec2/instance-types/c5/) (2x Xeon Platinum 8124M CPU @ 3.00GHz)
|
||||||
* Ubuntu 18.04 (hvm-ssd/ubuntu-bionic-18.04-amd64-server-20180912 ami-00035f41c82244dab)
|
* Ubuntu 18.04 (hvm-ssd/ubuntu-bionic-18.04-amd64-server-20180912 ami-00035f41c82244dab)
|
||||||
* Node.js v10.11.0
|
* Node.js v12.10.0
|
||||||
|
|
||||||
### The contenders
|
### The contenders
|
||||||
|
|
||||||
* [jimp](https://www.npmjs.com/package/jimp) v0.5.3 - Image processing in pure JavaScript. Provides bicubic interpolation.
|
* [jimp](https://www.npmjs.com/package/jimp) v0.8.4 - Image processing in pure JavaScript. Provides bicubic interpolation.
|
||||||
* [mapnik](https://www.npmjs.org/package/mapnik) v4.0.1 - Whilst primarily a map renderer, Mapnik contains bitmap image utilities.
|
* [mapnik](https://www.npmjs.org/package/mapnik) v4.3.1 - 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](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
* [imagemagick](https://www.npmjs.com/package/imagemagick) v0.1.3 - Supports filesystem only and "*has been unmaintained for a long time*".
|
||||||
* [gm](https://www.npmjs.com/package/gm) v1.23.1 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
* [gm](https://www.npmjs.com/package/gm) v1.23.1 - Fully featured wrapper around GraphicsMagick's `gm` command line utility.
|
||||||
* sharp v0.21.0 / libvips v8.7.0 - Caching within libvips disabled to ensure a fair comparison.
|
* sharp v0.23.1 / libvips v8.8.1 - Caching within libvips disabled to ensure a fair comparison.
|
||||||
|
|
||||||
### The task
|
### The task
|
||||||
|
|
||||||
@@ -25,14 +24,14 @@ 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 | buffer | buffer | 0.71 | 1.0 |
|
| jimp | buffer | buffer | 0.66 | 1.0 |
|
||||||
| mapnik | buffer | buffer | 3.32 | 4.7 |
|
| mapnik | buffer | buffer | 3.31 | 5.0 |
|
||||||
| gm | buffer | buffer | 3.97 | 5.6 |
|
| gm | buffer | buffer | 3.79 | 5.7 |
|
||||||
| imagemagick-native | buffer | buffer | 4.06 | 5.7 |
|
| gm | file | file | 3.82 | 5.8 |
|
||||||
| imagemagick | file | file | 4.24 | 6.0 |
|
| imagemagick | file | file | 4.17 | 6.3 |
|
||||||
| sharp | stream | stream | 25.30 | 35.6 |
|
| sharp | stream | stream | 25.81 | 39.1 |
|
||||||
| sharp | file | file | 26.17 | 36.9 |
|
| sharp | file | file | 26.76 | 40.5 |
|
||||||
| sharp | buffer | buffer | 26.45 | 37.3 |
|
| sharp | buffer | buffer | 28.06 | 42.5 |
|
||||||
|
|
||||||
Greater libvips performance can be expected with caching enabled (default)
|
Greater libvips performance can be expected with caching enabled (default)
|
||||||
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
and using 8+ core machines, especially those with larger L1/L2 CPU caches.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const copyFileSync = require('fs-copy-file-sync');
|
|
||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
const npmLog = require('npmlog');
|
const npmLog = require('npmlog');
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ if (process.platform === 'win32') {
|
|||||||
return /\.dll$/.test(filename);
|
return /\.dll$/.test(filename);
|
||||||
})
|
})
|
||||||
.forEach(function (filename) {
|
.forEach(function (filename) {
|
||||||
copyFileSync(
|
fs.copyFileSync(
|
||||||
path.join(vendorLibDir, filename),
|
path.join(vendorLibDir, filename),
|
||||||
path.join(buildReleaseDir, filename)
|
path.join(buildReleaseDir, filename)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,18 +9,18 @@ const npmLog = require('npmlog');
|
|||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const simpleGet = require('simple-get');
|
const simpleGet = require('simple-get');
|
||||||
const tar = require('tar');
|
const tar = require('tar');
|
||||||
const copyFileSync = require('fs-copy-file-sync');
|
|
||||||
|
|
||||||
const agent = require('../lib/agent');
|
const agent = require('../lib/agent');
|
||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
const platform = require('../lib/platform');
|
const platform = require('../lib/platform');
|
||||||
|
|
||||||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||||
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
||||||
|
|
||||||
const fail = function (err) {
|
const fail = function (err) {
|
||||||
npmLog.error('sharp', err.message);
|
npmLog.error('sharp', err.message);
|
||||||
npmLog.error('sharp', 'Please see http://sharp.pixelplumbing.com/page/install');
|
npmLog.info('sharp', 'Attempting to build from source via node-gyp but this may fail due to the above error');
|
||||||
|
npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/page/install for required dependencies');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,7 +33,12 @@ const extractTarball = function (tarPath) {
|
|||||||
cwd: vendorPath,
|
cwd: vendorPath,
|
||||||
strict: true
|
strict: true
|
||||||
})
|
})
|
||||||
.catch(fail);
|
.catch(function (err) {
|
||||||
|
if (/unexpected end of file/.test(err.message)) {
|
||||||
|
npmLog.error('sharp', `Please delete ${tarPath} as it is not a valid tarball`);
|
||||||
|
}
|
||||||
|
fail(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -55,10 +60,10 @@ try {
|
|||||||
if (arch === 'ia32') {
|
if (arch === 'ia32') {
|
||||||
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
if (platformAndArch === 'freebsd-x64') {
|
if (platformAndArch === 'freebsd-x64' || platformAndArch === 'openbsd-x64' || platformAndArch === 'sunos-x64') {
|
||||||
throw new Error(`FreeBSD systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`BSD/SunOS systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && semver.lt(`${detectLibc.version}.0`, '2.13.0')) {
|
if (detectLibc.family === detectLibc.GLIBC && detectLibc.version && semver.lt(`${detectLibc.version}.0`, '2.17.0')) {
|
||||||
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
// Download to per-process temporary file
|
// Download to per-process temporary file
|
||||||
@@ -79,7 +84,9 @@ try {
|
|||||||
if (response.statusCode !== 200) {
|
if (response.statusCode !== 200) {
|
||||||
throw new Error(`Status ${response.statusCode}`);
|
throw new Error(`Status ${response.statusCode}`);
|
||||||
}
|
}
|
||||||
response.pipe(tmpFile);
|
response
|
||||||
|
.on('error', fail)
|
||||||
|
.pipe(tmpFile);
|
||||||
});
|
});
|
||||||
tmpFile
|
tmpFile
|
||||||
.on('error', fail)
|
.on('error', fail)
|
||||||
@@ -89,7 +96,7 @@ try {
|
|||||||
fs.renameSync(tarPathTemp, tarPathCache);
|
fs.renameSync(tarPathTemp, tarPathCache);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Fall back to copy and unlink
|
// Fall back to copy and unlink
|
||||||
copyFileSync(tarPathTemp, tarPathCache);
|
fs.copyFileSync(tarPathTemp, tarPathCache);
|
||||||
fs.unlinkSync(tarPathTemp);
|
fs.unlinkSync(tarPathTemp);
|
||||||
}
|
}
|
||||||
extractTarball(tarPathCache);
|
extractTarball(tarPathCache);
|
||||||
|
|||||||
@@ -20,15 +20,18 @@ function env (key) {
|
|||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
try {
|
try {
|
||||||
const proxy = url.parse(proxies.map(env).find(is.string));
|
const proxy = new url.URL(proxies.map(env).find(is.string));
|
||||||
const tunnel = proxy.protocol === 'https:'
|
const tunnel = proxy.protocol === 'https:'
|
||||||
? tunnelAgent.httpsOverHttps
|
? tunnelAgent.httpsOverHttps
|
||||||
: tunnelAgent.httpsOverHttp;
|
: tunnelAgent.httpsOverHttp;
|
||||||
|
const proxyAuth = proxy.username && proxy.password
|
||||||
|
? `${proxy.username}:${proxy.password}`
|
||||||
|
: null;
|
||||||
return tunnel({
|
return tunnel({
|
||||||
proxy: {
|
proxy: {
|
||||||
port: Number(proxy.port),
|
port: Number(proxy.port),
|
||||||
host: proxy.hostname,
|
host: proxy.hostname,
|
||||||
proxyAuth: proxy.auth
|
proxyAuth
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -29,6 +29,23 @@ function removeAlpha () {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp('rgb.jpg')
|
||||||
|
* .ensureAlpha()
|
||||||
|
* .toFile('rgba.png', function(err, info) {
|
||||||
|
* // rgba.png is a 4 channel image with a fully opaque alpha channel
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
function ensureAlpha () {
|
||||||
|
this.options.ensureAlpha = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a single channel from a multi-channel image.
|
* Extract a single channel from a multi-channel image.
|
||||||
*
|
*
|
||||||
@@ -55,7 +72,7 @@ function extractChannel (channel) {
|
|||||||
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
|
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
|
||||||
this.options.extractChannel = channel;
|
this.options.extractChannel = channel;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Cannot extract invalid channel ' + channel);
|
throw is.invalidParameterError('channel', 'integer or one of: red, green, blue', channel);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -107,7 +124,7 @@ function bandbool (boolOp) {
|
|||||||
if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
|
if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
|
||||||
this.options.bandBoolOp = boolOp;
|
this.options.bandBoolOp = boolOp;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid bandbool operation ' + boolOp);
|
throw is.invalidParameterError('boolOp', 'one of: and, or, eor', boolOp);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -117,14 +134,13 @@ function bandbool (boolOp) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
// Public instance functions
|
Object.assign(Sharp.prototype, {
|
||||||
[
|
// Public instance functions
|
||||||
removeAlpha,
|
removeAlpha,
|
||||||
|
ensureAlpha,
|
||||||
extractChannel,
|
extractChannel,
|
||||||
joinChannel,
|
joinChannel,
|
||||||
bandbool
|
bandbool
|
||||||
].forEach(function (f) {
|
|
||||||
Sharp.prototype[f.name] = f;
|
|
||||||
});
|
});
|
||||||
// Class attributes
|
// Class attributes
|
||||||
Sharp.bool = bool;
|
Sharp.bool = bool;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const deprecate = require('util').deprecate;
|
|
||||||
|
|
||||||
const color = require('color');
|
const color = require('color');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
@@ -17,24 +15,6 @@ const colourspace = {
|
|||||||
srgb: 'srgb'
|
srgb: 'srgb'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function background (rgba) {
|
|
||||||
const colour = color(rgba);
|
|
||||||
const background = [
|
|
||||||
colour.red(),
|
|
||||||
colour.green(),
|
|
||||||
colour.blue(),
|
|
||||||
Math.round(colour.alpha() * 255)
|
|
||||||
];
|
|
||||||
this.options.resizeBackground = background;
|
|
||||||
this.options.extendBackground = background;
|
|
||||||
this.options.flattenBackground = background.slice(0, 3);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tint the image using the provided chroma while preserving the image luminance.
|
* 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.
|
* An alpha channel may be present and will be unchanged by the operation.
|
||||||
@@ -83,7 +63,7 @@ function grayscale (grayscale) {
|
|||||||
*/
|
*/
|
||||||
function toColourspace (colourspace) {
|
function toColourspace (colourspace) {
|
||||||
if (!is.string(colourspace)) {
|
if (!is.string(colourspace)) {
|
||||||
throw new Error('Invalid output colourspace ' + colourspace);
|
throw is.invalidParameterError('colourspace', 'string', colourspace);
|
||||||
}
|
}
|
||||||
this.options.colourspace = colourspace;
|
this.options.colourspace = colourspace;
|
||||||
return this;
|
return this;
|
||||||
@@ -103,18 +83,22 @@ function toColorspace (colorspace) {
|
|||||||
* Update a colour attribute of the this.options Object.
|
* Update a colour attribute of the this.options Object.
|
||||||
* @private
|
* @private
|
||||||
* @param {String} key
|
* @param {String} key
|
||||||
* @param {String|Object} val
|
* @param {String|Object} value
|
||||||
* @throws {Error} Invalid key
|
* @throws {Error} Invalid value
|
||||||
*/
|
*/
|
||||||
function _setColourOption (key, val) {
|
function _setBackgroundColourOption (key, value) {
|
||||||
if (is.object(val) || is.string(val)) {
|
if (is.defined(value)) {
|
||||||
const colour = color(val);
|
if (is.object(value) || is.string(value)) {
|
||||||
this.options[key] = [
|
const colour = color(value);
|
||||||
colour.red(),
|
this.options[key] = [
|
||||||
colour.green(),
|
colour.red(),
|
||||||
colour.blue(),
|
colour.green(),
|
||||||
Math.round(colour.alpha() * 255)
|
colour.blue(),
|
||||||
];
|
Math.round(colour.alpha() * 255)
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('background', 'object or string', value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +107,7 @@ function _setColourOption (key, val) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
[
|
Object.assign(Sharp.prototype, {
|
||||||
// Public
|
// Public
|
||||||
tint,
|
tint,
|
||||||
greyscale,
|
greyscale,
|
||||||
@@ -131,13 +115,9 @@ module.exports = function (Sharp) {
|
|||||||
toColourspace,
|
toColourspace,
|
||||||
toColorspace,
|
toColorspace,
|
||||||
// Private
|
// Private
|
||||||
_setColourOption
|
_setBackgroundColourOption
|
||||||
].forEach(function (f) {
|
|
||||||
Sharp.prototype[f.name] = f;
|
|
||||||
});
|
});
|
||||||
// Class attributes
|
// Class attributes
|
||||||
Sharp.colourspace = colourspace;
|
Sharp.colourspace = colourspace;
|
||||||
Sharp.colorspace = colourspace;
|
Sharp.colorspace = colourspace;
|
||||||
// Deprecated
|
|
||||||
Sharp.prototype.background = deprecate(background, 'background(background) is deprecated, use resize({ background }), extend({ background }) or flatten({ background }) instead');
|
|
||||||
};
|
};
|
||||||
|
|||||||
196
lib/composite.js
@@ -3,20 +3,62 @@
|
|||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overlay (composite) an image over the processed (resized, extracted etc.) image.
|
* Blend modes.
|
||||||
|
* @member
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const blend = {
|
||||||
|
clear: 'clear',
|
||||||
|
source: 'source',
|
||||||
|
over: 'over',
|
||||||
|
in: 'in',
|
||||||
|
out: 'out',
|
||||||
|
atop: 'atop',
|
||||||
|
dest: 'dest',
|
||||||
|
'dest-over': 'dest-over',
|
||||||
|
'dest-in': 'dest-in',
|
||||||
|
'dest-out': 'dest-out',
|
||||||
|
'dest-atop': 'dest-atop',
|
||||||
|
xor: 'xor',
|
||||||
|
add: 'add',
|
||||||
|
saturate: 'saturate',
|
||||||
|
multiply: 'multiply',
|
||||||
|
screen: 'screen',
|
||||||
|
overlay: 'overlay',
|
||||||
|
darken: 'darken',
|
||||||
|
lighten: 'lighten',
|
||||||
|
'colour-dodge': 'colour-dodge',
|
||||||
|
'color-dodge': 'colour-dodge',
|
||||||
|
'colour-burn': 'colour-burn',
|
||||||
|
'color-burn': 'colour-burn',
|
||||||
|
'hard-light': 'hard-light',
|
||||||
|
'soft-light': 'soft-light',
|
||||||
|
difference: 'difference',
|
||||||
|
exclusion: 'exclusion'
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composite image(s) over the processed (resized, extracted etc.) image.
|
||||||
*
|
*
|
||||||
* The overlay image must be the same size or smaller than the processed image.
|
* The images to composite must be the same size or smaller than the processed image.
|
||||||
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||||
*
|
*
|
||||||
* If the overlay image contains an alpha channel then composition with premultiplication will occur.
|
* The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||||
|
* `dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||||
|
* `xor`, `add`, `saturate`, `multiply`, `screen`, `overlay`, `darken`, `lighten`,
|
||||||
|
* `colour-dodge`, `color-dodge`, `colour-burn`,`color-burn`,
|
||||||
|
* `hard-light`, `soft-light`, `difference`, `exclusion`.
|
||||||
|
*
|
||||||
|
* More information about blend modes can be found at
|
||||||
|
* https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsBlendMode
|
||||||
|
* and https://www.cairographics.org/operators/
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('input.png')
|
* sharp('input.png')
|
||||||
* .rotate(180)
|
* .rotate(180)
|
||||||
* .resize(300)
|
* .resize(300)
|
||||||
* .flatten()
|
* .flatten( { background: '#ff6600' } )
|
||||||
* .background('#ff6600')
|
* .composite([{ input: 'overlay.png', gravity: 'southeast' }])
|
||||||
* .overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
|
||||||
* .sharpen()
|
* .sharpen()
|
||||||
* .withMetadata()
|
* .withMetadata()
|
||||||
* .webp( { quality: 90 } )
|
* .webp( { quality: 90 } )
|
||||||
@@ -27,63 +69,96 @@ const is = require('./is');
|
|||||||
* // sharpened, with metadata, 90% quality WebP image data. Phew!
|
* // sharpened, with metadata, 90% quality WebP image data. Phew!
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @param {(Buffer|String)} overlay - Buffer containing image data or String containing the path to an image file.
|
* @param {Object[]} images - Ordered list of images to composite
|
||||||
* @param {Object} [options]
|
* @param {Buffer|String} [images[].input] - Buffer containing image data, String containing the path to an image file, or Create object (see bellow)
|
||||||
* @param {String} [options.gravity='centre'] - gravity at which to place the overlay.
|
* @param {Object} [images[].input.create] - describes a blank overlay to be created.
|
||||||
* @param {Number} [options.top] - the pixel offset from the top edge.
|
* @param {Number} [images[].input.create.width]
|
||||||
* @param {Number} [options.left] - the pixel offset from the left edge.
|
* @param {Number} [images[].input.create.height]
|
||||||
* @param {Boolean} [options.tile=false] - set to true to repeat the overlay image across the entire image with the given `gravity`.
|
* @param {Number} [images[].input.create.channels] - 3-4
|
||||||
* @param {Boolean} [options.cutout=false] - 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.
|
* @param {String|Object} [images[].input.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||||
* @param {Number} [options.density=72] - number representing the DPI for vector overlay image.
|
* @param {String} [images[].blend='over'] - how to blend this image with the image below.
|
||||||
* @param {Object} [options.raw] - describes overlay when using raw pixel data.
|
* @param {String} [images[].gravity='centre'] - gravity at which to place the overlay.
|
||||||
* @param {Number} [options.raw.width]
|
* @param {Number} [images[].top] - the pixel offset from the top edge.
|
||||||
* @param {Number} [options.raw.height]
|
* @param {Number} [images[].left] - the pixel offset from the left edge.
|
||||||
* @param {Number} [options.raw.channels]
|
* @param {Boolean} [images[].tile=false] - set to true to repeat the overlay image across the entire image with the given `gravity`.
|
||||||
* @param {Object} [options.create] - describes a blank overlay to be created.
|
* @param {Boolean} [images[].premultiplied=false] - set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option.
|
||||||
* @param {Number} [options.create.width]
|
* @param {Number} [images[].density=72] - number representing the DPI for vector overlay image.
|
||||||
* @param {Number} [options.create.height]
|
* @param {Object} [images[].raw] - describes overlay when using raw pixel data.
|
||||||
* @param {Number} [options.create.channels] - 3-4
|
* @param {Number} [images[].raw.width]
|
||||||
* @param {String|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
* @param {Number} [images[].raw.height]
|
||||||
|
* @param {Number} [images[].raw.channels]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function overlayWith (overlay, options) {
|
function composite (images) {
|
||||||
this.options.overlay = this._createInputDescriptor(overlay, options, {
|
if (!Array.isArray(images)) {
|
||||||
allowStream: false
|
throw is.invalidParameterError('images to composite', 'array', images);
|
||||||
});
|
|
||||||
if (is.object(options)) {
|
|
||||||
if (is.defined(options.tile)) {
|
|
||||||
if (is.bool(options.tile)) {
|
|
||||||
this.options.overlayTile = options.tile;
|
|
||||||
} else {
|
|
||||||
throw new Error('Invalid overlay tile ' + options.tile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is.defined(options.cutout)) {
|
|
||||||
if (is.bool(options.cutout)) {
|
|
||||||
this.options.overlayCutout = options.cutout;
|
|
||||||
} else {
|
|
||||||
throw new Error('Invalid overlay cutout ' + options.cutout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is.defined(options.left) || is.defined(options.top)) {
|
|
||||||
if (is.integer(options.left) && options.left >= 0 && is.integer(options.top) && options.top >= 0) {
|
|
||||||
this.options.overlayXOffset = options.left;
|
|
||||||
this.options.overlayYOffset = options.top;
|
|
||||||
} else {
|
|
||||||
throw new Error('Invalid overlay left ' + options.left + ' and/or top ' + options.top);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is.defined(options.gravity)) {
|
|
||||||
if (is.integer(options.gravity) && is.inRange(options.gravity, 0, 8)) {
|
|
||||||
this.options.overlayGravity = options.gravity;
|
|
||||||
} else if (is.string(options.gravity) && is.integer(this.constructor.gravity[options.gravity])) {
|
|
||||||
this.options.overlayGravity = this.constructor.gravity[options.gravity];
|
|
||||||
} else {
|
|
||||||
throw new Error('Unsupported overlay gravity ' + options.gravity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.options.composite = images.map(image => {
|
||||||
|
if (!is.object(image)) {
|
||||||
|
throw is.invalidParameterError('image to composite', 'object', image);
|
||||||
|
}
|
||||||
|
const { raw, density } = image;
|
||||||
|
const inputOptions = (raw || density) ? { raw, density } : undefined;
|
||||||
|
const composite = {
|
||||||
|
input: this._createInputDescriptor(image.input, inputOptions, { allowStream: false }),
|
||||||
|
blend: 'over',
|
||||||
|
tile: false,
|
||||||
|
left: -1,
|
||||||
|
top: -1,
|
||||||
|
gravity: 0,
|
||||||
|
premultiplied: false
|
||||||
|
};
|
||||||
|
if (is.defined(image.blend)) {
|
||||||
|
if (is.string(blend[image.blend])) {
|
||||||
|
composite.blend = blend[image.blend];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('blend', 'valid blend name', image.blend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(image.tile)) {
|
||||||
|
if (is.bool(image.tile)) {
|
||||||
|
composite.tile = image.tile;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('tile', 'boolean', image.tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(image.left)) {
|
||||||
|
if (is.integer(image.left) && image.left >= 0) {
|
||||||
|
composite.left = image.left;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('left', 'positive integer', image.left);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(image.top)) {
|
||||||
|
if (is.integer(image.top) && image.top >= 0) {
|
||||||
|
composite.top = image.top;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('top', 'positive integer', image.top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (composite.left !== composite.top && Math.min(composite.left, composite.top) === -1) {
|
||||||
|
throw new Error('Expected both left and top to be set');
|
||||||
|
}
|
||||||
|
if (is.defined(image.gravity)) {
|
||||||
|
if (is.integer(image.gravity) && is.inRange(image.gravity, 0, 8)) {
|
||||||
|
composite.gravity = image.gravity;
|
||||||
|
} else if (is.string(image.gravity) && is.integer(this.constructor.gravity[image.gravity])) {
|
||||||
|
composite.gravity = this.constructor.gravity[image.gravity];
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('gravity', 'valid gravity', image.gravity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(image.premultiplied)) {
|
||||||
|
if (is.bool(image.premultiplied)) {
|
||||||
|
composite.premultiplied = image.premultiplied;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('premultiplied', 'boolean', image.premultiplied);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return composite;
|
||||||
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,5 +167,6 @@ function overlayWith (overlay, options) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
Sharp.prototype.overlayWith = overlayWith;
|
Sharp.prototype.composite = composite;
|
||||||
|
Sharp.blend = blend;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,33 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const events = require('events');
|
const events = require('events');
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
require('./libvips').hasVendoredLibvips();
|
require('./libvips').hasVendoredLibvips();
|
||||||
const sharp = require('../build/Release/sharp.node');
|
|
||||||
|
let sharp;
|
||||||
|
/* istanbul ignore next */
|
||||||
|
try {
|
||||||
|
sharp = require('../build/Release/sharp.node');
|
||||||
|
} catch (err) {
|
||||||
|
// Bail early if bindings aren't available
|
||||||
|
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, ''];
|
||||||
|
if (/NODE_MODULE_VERSION/.test(err.message)) {
|
||||||
|
help.push('- Ensure the version of Node.js used at install time matches that used at runtime');
|
||||||
|
} else if (/invalid ELF header/.test(err.message)) {
|
||||||
|
help.push(`- Ensure "${process.platform}" is used at install time as well as runtime`);
|
||||||
|
} else {
|
||||||
|
help.push('- Remove the "node_modules/sharp" directory, run "npm install" and look for errors');
|
||||||
|
}
|
||||||
|
help.push(
|
||||||
|
'- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/',
|
||||||
|
'- Search for this error at https://github.com/lovell/sharp/issues', ''
|
||||||
|
);
|
||||||
|
console.error(help.join('\n'));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Use NODE_DEBUG=sharp to enable libvips warnings
|
// Use NODE_DEBUG=sharp to enable libvips warnings
|
||||||
const debuglog = util.debuglog('sharp');
|
const debuglog = util.debuglog('sharp');
|
||||||
@@ -61,11 +81,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"
|
* @param {Boolean} [options.failOnError=true] - by default halt processing and raise an error when loading invalid images.
|
||||||
* to decode images, even if the data is corrupt or invalid. Set this flag to true
|
* Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid.
|
||||||
* if you'd rather halt processing and raise an error when loading invalid images.
|
|
||||||
* @param {Number} [options.density=72] - number representing the DPI for vector images.
|
* @param {Number} [options.density=72] - number representing the DPI for vector images.
|
||||||
* @param {Number} [options.page=0] - page number to extract for multi-page input (GIF, TIFF)
|
* @param {Number} [options.pages=1] - number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages.
|
||||||
|
* @param {Number} [options.page=0] - page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based.
|
||||||
* @param {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]
|
||||||
@@ -90,8 +110,6 @@ const Sharp = function (input, options) {
|
|||||||
// input options
|
// input options
|
||||||
sequentialRead: false,
|
sequentialRead: false,
|
||||||
limitInputPixels: Math.pow(0x3FFF, 2),
|
limitInputPixels: Math.pow(0x3FFF, 2),
|
||||||
// ICC profiles
|
|
||||||
iccProfilePath: path.join(__dirname, 'icc') + path.sep,
|
|
||||||
// resize options
|
// resize options
|
||||||
topOffsetPre: -1,
|
topOffsetPre: -1,
|
||||||
leftOffsetPre: -1,
|
leftOffsetPre: -1,
|
||||||
@@ -136,20 +154,20 @@ const Sharp = function (input, options) {
|
|||||||
thresholdGrayscale: true,
|
thresholdGrayscale: true,
|
||||||
trimThreshold: 0,
|
trimThreshold: 0,
|
||||||
gamma: 0,
|
gamma: 0,
|
||||||
|
gammaOut: 0,
|
||||||
greyscale: false,
|
greyscale: false,
|
||||||
normalise: 0,
|
normalise: 0,
|
||||||
|
brightness: 1,
|
||||||
|
saturation: 1,
|
||||||
|
hue: 0,
|
||||||
booleanBufferIn: null,
|
booleanBufferIn: null,
|
||||||
booleanFileIn: '',
|
booleanFileIn: '',
|
||||||
joinChannelIn: [],
|
joinChannelIn: [],
|
||||||
extractChannel: -1,
|
extractChannel: -1,
|
||||||
removeAlpha: false,
|
removeAlpha: false,
|
||||||
|
ensureAlpha: false,
|
||||||
colourspace: 'srgb',
|
colourspace: 'srgb',
|
||||||
// overlay
|
composite: [],
|
||||||
overlayGravity: 0,
|
|
||||||
overlayXOffset: -1,
|
|
||||||
overlayYOffset: -1,
|
|
||||||
overlayTile: false,
|
|
||||||
overlayCutout: false,
|
|
||||||
// output
|
// output
|
||||||
fileOut: '',
|
fileOut: '',
|
||||||
formatOut: 'input',
|
formatOut: 'input',
|
||||||
@@ -169,18 +187,32 @@ const Sharp = function (input, options) {
|
|||||||
pngProgressive: false,
|
pngProgressive: false,
|
||||||
pngCompressionLevel: 9,
|
pngCompressionLevel: 9,
|
||||||
pngAdaptiveFiltering: false,
|
pngAdaptiveFiltering: false,
|
||||||
|
pngPalette: false,
|
||||||
|
pngQuality: 100,
|
||||||
|
pngColours: 256,
|
||||||
|
pngDither: 1,
|
||||||
webpQuality: 80,
|
webpQuality: 80,
|
||||||
webpAlphaQuality: 100,
|
webpAlphaQuality: 100,
|
||||||
webpLossless: false,
|
webpLossless: false,
|
||||||
webpNearLossless: false,
|
webpNearLossless: false,
|
||||||
|
webpSmartSubsample: false,
|
||||||
|
webpReductionEffort: 4,
|
||||||
tiffQuality: 80,
|
tiffQuality: 80,
|
||||||
tiffCompression: 'jpeg',
|
tiffCompression: 'jpeg',
|
||||||
tiffPredictor: 'horizontal',
|
tiffPredictor: 'horizontal',
|
||||||
|
tiffPyramid: false,
|
||||||
tiffSquash: false,
|
tiffSquash: false,
|
||||||
|
tiffTile: false,
|
||||||
|
tiffTileHeight: 256,
|
||||||
|
tiffTileWidth: 256,
|
||||||
tiffXres: 1.0,
|
tiffXres: 1.0,
|
||||||
tiffYres: 1.0,
|
tiffYres: 1.0,
|
||||||
|
heifQuality: 80,
|
||||||
|
heifLossless: false,
|
||||||
|
heifCompression: 'hevc',
|
||||||
tileSize: 256,
|
tileSize: 256,
|
||||||
tileOverlap: 0,
|
tileOverlap: 0,
|
||||||
|
tileSkipBlanks: -1,
|
||||||
linearA: 1,
|
linearA: 1,
|
||||||
linearB: 0,
|
linearB: 0,
|
||||||
// Function to notify of libvips warnings
|
// Function to notify of libvips warnings
|
||||||
|
|||||||
BIN
lib/icc/cmyk.icm
BIN
lib/icc/sRGB.icc
82
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 = { failOnError: false };
|
const inputDescriptor = { failOnError: true };
|
||||||
if (is.string(input)) {
|
if (is.string(input)) {
|
||||||
// filesystem
|
// filesystem
|
||||||
inputDescriptor.file = input;
|
inputDescriptor.file = input;
|
||||||
@@ -19,6 +19,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
} else if (is.plainObject(input) && !is.defined(inputOptions)) {
|
||||||
// Plain Object descriptor, e.g. create
|
// Plain Object descriptor, e.g. create
|
||||||
inputOptions = input;
|
inputOptions = input;
|
||||||
|
if (is.plainObject(inputOptions.raw) || is.bool(inputOptions.failOnError)) {
|
||||||
|
// Raw Stream
|
||||||
|
inputDescriptor.buffer = [];
|
||||||
|
}
|
||||||
} else if (!is.defined(input) && is.object(containerOptions) && containerOptions.allowStream) {
|
} else if (!is.defined(input) && is.object(containerOptions) && containerOptions.allowStream) {
|
||||||
// Stream
|
// Stream
|
||||||
inputDescriptor.buffer = [];
|
inputDescriptor.buffer = [];
|
||||||
@@ -31,7 +35,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
if (is.bool(inputOptions.failOnError)) {
|
if (is.bool(inputOptions.failOnError)) {
|
||||||
inputDescriptor.failOnError = inputOptions.failOnError;
|
inputDescriptor.failOnError = inputOptions.failOnError;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid failOnError (boolean) ' + inputOptions.failOnError);
|
throw is.invalidParameterError('failOnError', 'boolean', inputOptions.failOnError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Density
|
// Density
|
||||||
@@ -39,7 +43,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
if (is.inRange(inputOptions.density, 1, 2400)) {
|
if (is.inRange(inputOptions.density, 1, 2400)) {
|
||||||
inputDescriptor.density = inputOptions.density;
|
inputDescriptor.density = inputOptions.density;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid density (1 to 2400) ' + inputOptions.density);
|
throw is.invalidParameterError('density', 'number between 1 and 2400', inputOptions.density);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Raw pixel input
|
// Raw pixel input
|
||||||
@@ -57,7 +61,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
|
// Multi-page input (GIF, TIFF, PDF)
|
||||||
|
if (is.defined(inputOptions.pages)) {
|
||||||
|
if (is.integer(inputOptions.pages) && is.inRange(inputOptions.pages, -1, 100000)) {
|
||||||
|
inputDescriptor.pages = inputOptions.pages;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is.defined(inputOptions.page)) {
|
if (is.defined(inputOptions.page)) {
|
||||||
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
||||||
inputDescriptor.page = inputOptions.page;
|
inputDescriptor.page = inputOptions.page;
|
||||||
@@ -106,9 +115,8 @@ function _write (chunk, encoding, callback) {
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (is.buffer(chunk)) {
|
if (is.buffer(chunk)) {
|
||||||
if (this.options.input.buffer.length === 0) {
|
if (this.options.input.buffer.length === 0) {
|
||||||
const that = this;
|
this.on('finish', () => {
|
||||||
this.on('finish', function () {
|
this.streamInFinished = true;
|
||||||
that.streamInFinished = true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.options.input.buffer.push(chunk);
|
this.options.input.buffer.push(chunk);
|
||||||
@@ -156,16 +164,15 @@ function _isStreamInput () {
|
|||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
function clone () {
|
function clone () {
|
||||||
const that = this;
|
|
||||||
// Clone existing options
|
// Clone existing options
|
||||||
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()) {
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', function () {
|
this.on('finish', () => {
|
||||||
// Clone inherits input data
|
// Clone inherits input data
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
clone.options.bufferIn = that.options.bufferIn;
|
clone.options.bufferIn = this.options.bufferIn;
|
||||||
clone.emit('finish');
|
clone.emit('finish');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -174,7 +181,7 @@ function clone () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fast access to (uncached) image metadata without decoding any compressed image data.
|
* Fast access to (uncached) image metadata without decoding any compressed image data.
|
||||||
* A Promises/A+ promise is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
*
|
*
|
||||||
* - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
* - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
||||||
* - `size`: Total size of image in bytes, for Stream and Buffer input only
|
* - `size`: Total size of image in bytes, for Stream and Buffer input only
|
||||||
@@ -186,6 +193,9 @@ function clone () {
|
|||||||
* - `density`: Number of pixels per inch (DPI), if present
|
* - `density`: Number of pixels per inch (DPI), if present
|
||||||
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||||
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
|
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
|
* - `pageHeight`: Number of pixels high each page in this PDF image will be.
|
||||||
|
* - `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
* - `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
|
||||||
@@ -212,12 +222,11 @@ function clone () {
|
|||||||
* @returns {Promise<Object>|Sharp}
|
* @returns {Promise<Object>|Sharp}
|
||||||
*/
|
*/
|
||||||
function metadata (callback) {
|
function metadata (callback) {
|
||||||
const that = this;
|
|
||||||
if (is.fn(callback)) {
|
if (is.fn(callback)) {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', function () {
|
this.on('finish', () => {
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.metadata(that.options, callback);
|
sharp.metadata(this.options, callback);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sharp.metadata(this.options, callback);
|
sharp.metadata(this.options, callback);
|
||||||
@@ -225,10 +234,10 @@ function metadata (callback) {
|
|||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
that.on('finish', function () {
|
this.on('finish', () => {
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.metadata(that.options, function (err, metadata) {
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@@ -238,8 +247,8 @@ function metadata (callback) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
sharp.metadata(that.options, function (err, metadata) {
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@@ -253,7 +262,7 @@ function metadata (callback) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Access to pixel-derived image statistics for every channel in the image.
|
* Access to pixel-derived image statistics for every channel in the image.
|
||||||
* A Promise is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
*
|
*
|
||||||
* - `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
* - `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||||
* - `min` (minimum value in the channel)
|
* - `min` (minimum value in the channel)
|
||||||
@@ -281,12 +290,11 @@ function metadata (callback) {
|
|||||||
* @returns {Promise<Object>}
|
* @returns {Promise<Object>}
|
||||||
*/
|
*/
|
||||||
function stats (callback) {
|
function stats (callback) {
|
||||||
const that = this;
|
|
||||||
if (is.fn(callback)) {
|
if (is.fn(callback)) {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
this.on('finish', function () {
|
this.on('finish', () => {
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.stats(that.options, callback);
|
sharp.stats(this.options, callback);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sharp.stats(this.options, callback);
|
sharp.stats(this.options, callback);
|
||||||
@@ -294,10 +302,10 @@ function stats (callback) {
|
|||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
that.on('finish', function () {
|
this.on('finish', function () {
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.stats(that.options, function (err, stats) {
|
sharp.stats(this.options, (err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@@ -307,8 +315,8 @@ function stats (callback) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
sharp.stats(that.options, function (err, stats) {
|
sharp.stats(this.options, (err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@@ -321,9 +329,9 @@ function stats (callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 x 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.
|
||||||
* The default limit is 268402689 (0x3FFF * 0x3FFF) pixels.
|
* The default limit is 268402689 (0x3FFF x 0x3FFF) pixels.
|
||||||
* @param {(Number|Boolean)} limit - an integral Number of pixels, zero or false to remove limit, true to use default limit.
|
* @param {(Number|Boolean)} limit - an integral Number of pixels, zero or false to remove limit, true to use default limit.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid limit
|
* @throws {Error} Invalid limit
|
||||||
@@ -362,7 +370,7 @@ function sequentialRead (sequentialRead) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
[
|
Object.assign(Sharp.prototype, {
|
||||||
// Private
|
// Private
|
||||||
_createInputDescriptor,
|
_createInputDescriptor,
|
||||||
_write,
|
_write,
|
||||||
@@ -374,7 +382,5 @@ module.exports = function (Sharp) {
|
|||||||
stats,
|
stats,
|
||||||
limitInputPixels,
|
limitInputPixels,
|
||||||
sequentialRead
|
sequentialRead
|
||||||
].forEach(function (f) {
|
|
||||||
Sharp.prototype[f.name] = f;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ const semver = require('semver');
|
|||||||
const platform = require('./platform');
|
const platform = require('./platform');
|
||||||
|
|
||||||
const env = process.env;
|
const env = process.env;
|
||||||
const minimumLibvipsVersion = env.npm_package_config_libvips || require('../package.json').config.libvips;
|
const minimumLibvipsVersion = env.npm_package_config_libvips || /* istanbul ignore next */
|
||||||
|
require('../package.json').config.libvips;
|
||||||
|
|
||||||
const spawnSyncOptions = {
|
const spawnSyncOptions = {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
@@ -19,6 +20,7 @@ const mkdirSync = function (dirPath) {
|
|||||||
try {
|
try {
|
||||||
fs.mkdirSync(dirPath);
|
fs.mkdirSync(dirPath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
/* istanbul ignore if */
|
||||||
if (err.code !== 'EEXIST') {
|
if (err.code !== 'EEXIST') {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -26,7 +28,8 @@ const mkdirSync = function (dirPath) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const cachePath = function () {
|
const cachePath = function () {
|
||||||
const npmCachePath = env.npm_config_cache || (env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'));
|
const npmCachePath = env.npm_config_cache || /* istanbul ignore next */
|
||||||
|
(env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'));
|
||||||
mkdirSync(npmCachePath);
|
mkdirSync(npmCachePath);
|
||||||
const libvipsCachePath = path.join(npmCachePath, '_libvips');
|
const libvipsCachePath = path.join(npmCachePath, '_libvips');
|
||||||
mkdirSync(libvipsCachePath);
|
mkdirSync(libvipsCachePath);
|
||||||
@@ -51,17 +54,21 @@ const hasVendoredLibvips = function () {
|
|||||||
vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips;
|
vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips;
|
||||||
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
/* istanbul ignore if */
|
||||||
if (vendorVersionId && vendorVersionId !== minimumLibvipsVersion) {
|
if (vendorVersionId && vendorVersionId !== minimumLibvipsVersion) {
|
||||||
throw new Error(`Found vendored libvips v${vendorVersionId} but require v${minimumLibvipsVersion}. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
throw new Error(`Found vendored libvips v${vendorVersionId} but require v${minimumLibvipsVersion}. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
||||||
}
|
}
|
||||||
|
/* istanbul ignore else */
|
||||||
if (vendorPlatformId) {
|
if (vendorPlatformId) {
|
||||||
|
/* istanbul ignore else */
|
||||||
if (currentPlatformId === vendorPlatformId) {
|
if (currentPlatformId === vendorPlatformId) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const pkgConfigPath = function () {
|
const pkgConfigPath = function () {
|
||||||
@@ -81,7 +88,8 @@ const useGlobalLibvips = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const globalVipsVersion = globalLibvipsVersion();
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
return !!globalVipsVersion && /* istanbul ignore next */
|
||||||
|
semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
140
lib/operation.js
@@ -55,7 +55,7 @@ function rotate (angle, options) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unsupported angle: must be a number.');
|
throw is.invalidParameterError('angle', 'numeric', angle);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ function sharpen (sigma, flat, jagged) {
|
|||||||
if (is.number(flat) && is.inRange(flat, 0, 10000)) {
|
if (is.number(flat) && is.inRange(flat, 0, 10000)) {
|
||||||
this.options.sharpenFlat = flat;
|
this.options.sharpenFlat = flat;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid sharpen level for flat areas (0.0 - 10000.0) ' + flat);
|
throw is.invalidParameterError('flat', 'number between 0 and 10000', flat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Control over jagged areas
|
// Control over jagged areas
|
||||||
@@ -117,11 +117,11 @@ function sharpen (sigma, flat, jagged) {
|
|||||||
if (is.number(jagged) && is.inRange(jagged, 0, 10000)) {
|
if (is.number(jagged) && is.inRange(jagged, 0, 10000)) {
|
||||||
this.options.sharpenJagged = jagged;
|
this.options.sharpenJagged = jagged;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid sharpen level for jagged areas (0.0 - 10000.0) ' + jagged);
|
throw is.invalidParameterError('jagged', 'number between 0 and 10000', jagged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid sharpen sigma (0.01 - 10000) ' + sigma);
|
throw is.invalidParameterError('sigma', 'number between 0.01 and 10000', sigma);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ function median (size) {
|
|||||||
// Numeric argument: specific sigma
|
// Numeric argument: specific sigma
|
||||||
this.options.medianSize = size;
|
this.options.medianSize = size;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid median size ' + size);
|
throw is.invalidParameterError('size', 'integer between 1 and 1000', size);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -165,20 +165,21 @@ function blur (sigma) {
|
|||||||
// Numeric argument: specific sigma
|
// Numeric argument: specific sigma
|
||||||
this.options.blurSigma = sigma;
|
this.options.blurSigma = sigma;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid blur sigma (0.3 - 1000.0) ' + sigma);
|
throw is.invalidParameterError('sigma', 'number between 0.3 and 1000', sigma);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge alpha transparency channel, if any, with a background.
|
* Merge alpha transparency channel, if any, with a background.
|
||||||
|
* @param {Object} [options]
|
||||||
* @param {String|Object} [options.background={r: 0, g: 0, b: 0}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black.
|
* @param {String|Object} [options.background={r: 0, g: 0, b: 0}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
function flatten (options) {
|
function flatten (options) {
|
||||||
this.options.flatten = is.bool(options) ? options : true;
|
this.options.flatten = is.bool(options) ? options : true;
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
this._setColourOption('flattenBackground', options.background);
|
this._setBackgroundColourOption('flattenBackground', options.background);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -189,18 +190,30 @@ function flatten (options) {
|
|||||||
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||||
* JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
* JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
||||||
* when applying a gamma correction.
|
* when applying a gamma correction.
|
||||||
|
*
|
||||||
|
* Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
||||||
|
*
|
||||||
* @param {Number} [gamma=2.2] value between 1.0 and 3.0.
|
* @param {Number} [gamma=2.2] value between 1.0 and 3.0.
|
||||||
|
* @param {Number} [gammaOut] value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function gamma (gamma) {
|
function gamma (gamma, gammaOut) {
|
||||||
if (!is.defined(gamma)) {
|
if (!is.defined(gamma)) {
|
||||||
// Default gamma correction of 2.2 (sRGB)
|
// Default gamma correction of 2.2 (sRGB)
|
||||||
this.options.gamma = 2.2;
|
this.options.gamma = 2.2;
|
||||||
} else if (is.number(gamma) && is.inRange(gamma, 1, 3)) {
|
} else if (is.number(gamma) && is.inRange(gamma, 1, 3)) {
|
||||||
this.options.gamma = gamma;
|
this.options.gamma = gamma;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid gamma correction (1.0 to 3.0) ' + gamma);
|
throw is.invalidParameterError('gamma', 'number between 1.0 and 3.0', gamma);
|
||||||
|
}
|
||||||
|
if (!is.defined(gammaOut)) {
|
||||||
|
// Default gamma correction for output is same as input
|
||||||
|
this.options.gammaOut = this.options.gamma;
|
||||||
|
} else if (is.number(gammaOut) && is.inRange(gammaOut, 1, 3)) {
|
||||||
|
this.options.gammaOut = gammaOut;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('gammaOut', 'number between 1.0 and 3.0', gammaOut);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -302,7 +315,7 @@ function threshold (threshold, options) {
|
|||||||
} else if (is.integer(threshold) && is.inRange(threshold, 0, 255)) {
|
} else if (is.integer(threshold) && is.inRange(threshold, 0, 255)) {
|
||||||
this.options.threshold = threshold;
|
this.options.threshold = threshold;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid threshold (0 to 255) ' + threshold);
|
throw is.invalidParameterError('threshold', 'integer between 0 and 255', threshold);
|
||||||
}
|
}
|
||||||
if (!is.object(options) || options.greyscale === true || options.grayscale === true) {
|
if (!is.object(options) || options.greyscale === true || options.grayscale === true) {
|
||||||
this.options.thresholdGrayscale = true;
|
this.options.thresholdGrayscale = true;
|
||||||
@@ -333,7 +346,7 @@ function boolean (operand, operator, options) {
|
|||||||
if (is.string(operator) && is.inArray(operator, ['and', 'or', 'eor'])) {
|
if (is.string(operator) && is.inArray(operator, ['and', 'or', 'eor'])) {
|
||||||
this.options.booleanOp = operator;
|
this.options.booleanOp = operator;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid boolean operator ' + operator);
|
throw is.invalidParameterError('operator', 'one of: and, or, eor', operator);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -351,17 +364,108 @@ function linear (a, b) {
|
|||||||
} else if (is.number(a)) {
|
} else if (is.number(a)) {
|
||||||
this.options.linearA = a;
|
this.options.linearA = a;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid linear transform multiplier ' + a);
|
throw is.invalidParameterError('a', 'numeric', a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is.defined(b)) {
|
if (!is.defined(b)) {
|
||||||
this.options.linearB = 0.0;
|
this.options.linearB = 0.0;
|
||||||
} else if (is.number(b)) {
|
} else if (is.number(b)) {
|
||||||
this.options.linearB = b;
|
this.options.linearB = b;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid linear transform offset ' + b);
|
throw is.invalidParameterError('b', 'numeric', b);
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recomb the image with the specified matrix.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .recomb([
|
||||||
|
* [0.3588, 0.7044, 0.1368],
|
||||||
|
* [0.2990, 0.5870, 0.1140],
|
||||||
|
* [0.2392, 0.4696, 0.0912],
|
||||||
|
* ])
|
||||||
|
* .raw()
|
||||||
|
* .toBuffer(function(err, data, info) {
|
||||||
|
* // data contains the raw pixel data after applying the recomb
|
||||||
|
* // With this example input, a sepia filter has been applied
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @param {Array<Array<Number>>} 3x3 Recombination matrix
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function recomb (inputMatrix) {
|
||||||
|
if (!Array.isArray(inputMatrix) || inputMatrix.length !== 3 ||
|
||||||
|
inputMatrix[0].length !== 3 ||
|
||||||
|
inputMatrix[1].length !== 3 ||
|
||||||
|
inputMatrix[2].length !== 3
|
||||||
|
) {
|
||||||
|
// must pass in a kernel
|
||||||
|
throw new Error('Invalid recombination matrix');
|
||||||
|
}
|
||||||
|
this.options.recombMatrix = [
|
||||||
|
inputMatrix[0][0], inputMatrix[0][1], inputMatrix[0][2],
|
||||||
|
inputMatrix[1][0], inputMatrix[1][1], inputMatrix[1][2],
|
||||||
|
inputMatrix[2][0], inputMatrix[2][1], inputMatrix[2][2]
|
||||||
|
].map(Number);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms the image using brightness, saturation and hue rotation.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .modulate({
|
||||||
|
* brightness: 2 // increase lightness by a factor of 2
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* sharp(input)
|
||||||
|
* .modulate({
|
||||||
|
* hue: 180 // hue-rotate by 180 degrees
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* // decreate brightness and saturation while also hue-rotating by 90 degrees
|
||||||
|
* sharp(input)
|
||||||
|
* .modulate({
|
||||||
|
* brightness: 0.5,
|
||||||
|
* saturation: 0.5,
|
||||||
|
* hue: 90
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @param {Object} [options]
|
||||||
|
* @param {Number} [options.brightness] Brightness multiplier
|
||||||
|
* @param {Number} [options.saturation] Saturation multiplier
|
||||||
|
* @param {Number} [options.hue] Degrees for hue rotation
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
function modulate (options) {
|
||||||
|
if (!is.plainObject(options)) {
|
||||||
|
throw is.invalidParameterError('options', 'plain object', options);
|
||||||
|
}
|
||||||
|
if ('brightness' in options) {
|
||||||
|
if (is.number(options.brightness) && options.brightness >= 0) {
|
||||||
|
this.options.brightness = options.brightness;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('brightness', 'number above zero', options.brightness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('saturation' in options) {
|
||||||
|
if (is.number(options.saturation) && options.saturation >= 0) {
|
||||||
|
this.options.saturation = options.saturation;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('saturation', 'number above zero', options.saturation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('hue' in options) {
|
||||||
|
if (is.integer(options.hue)) {
|
||||||
|
this.options.hue = options.hue % 360;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('hue', 'number', options.hue);
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +474,7 @@ function linear (a, b) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
[
|
Object.assign(Sharp.prototype, {
|
||||||
rotate,
|
rotate,
|
||||||
flip,
|
flip,
|
||||||
flop,
|
flop,
|
||||||
@@ -385,8 +489,8 @@ module.exports = function (Sharp) {
|
|||||||
convolve,
|
convolve,
|
||||||
threshold,
|
threshold,
|
||||||
boolean,
|
boolean,
|
||||||
linear
|
linear,
|
||||||
].forEach(function (f) {
|
recomb,
|
||||||
Sharp.prototype[f.name] = f;
|
modulate
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
457
lib/output.js
@@ -10,6 +10,9 @@ 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.
|
||||||
*
|
*
|
||||||
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
|
* See {@link withMetadata} for control over this.
|
||||||
|
*
|
||||||
* A `Promise` is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -32,7 +35,7 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
*/
|
*/
|
||||||
function toFile (fileOut, callback) {
|
function toFile (fileOut, callback) {
|
||||||
if (!fileOut || fileOut.length === 0) {
|
if (!fileOut || fileOut.length === 0) {
|
||||||
const errOutputInvalid = new Error('Invalid output');
|
const errOutputInvalid = new Error('Missing output file path');
|
||||||
if (is.fn(callback)) {
|
if (is.fn(callback)) {
|
||||||
callback(errOutputInvalid);
|
callback(errOutputInvalid);
|
||||||
} else {
|
} else {
|
||||||
@@ -57,7 +60,11 @@ function toFile (fileOut, callback) {
|
|||||||
/**
|
/**
|
||||||
* Write output to a Buffer.
|
* Write output to a Buffer.
|
||||||
* JPEG, PNG, WebP, TIFF and RAW output are supported.
|
* JPEG, PNG, WebP, TIFF and RAW output are supported.
|
||||||
* By default, the format will match the input image, except GIF and SVG input which become PNG output.
|
*
|
||||||
|
* If no explicit format is set, the output format will match the input image, except GIF and SVG input which become PNG output.
|
||||||
|
*
|
||||||
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
|
* See {@link withMetadata} for control over this.
|
||||||
*
|
*
|
||||||
* `callback`, if present, gets three arguments `(err, data, info)` where:
|
* `callback`, if present, gets three arguments `(err, data, info)` where:
|
||||||
* - `err` is an error, if any.
|
* - `err` is an error, if any.
|
||||||
@@ -91,9 +98,9 @@ function toFile (fileOut, callback) {
|
|||||||
*/
|
*/
|
||||||
function toBuffer (options, callback) {
|
function toBuffer (options, callback) {
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
if (is.bool(options.resolveWithObject)) {
|
this._setBooleanOption('resolveWithObject', options.resolveWithObject);
|
||||||
this.options.resolveWithObject = options.resolveWithObject;
|
} else if (this.options.resolveWithObject) {
|
||||||
}
|
this.options.resolveWithObject = false;
|
||||||
}
|
}
|
||||||
return this._pipeline(is.fn(options) ? options : callback);
|
return this._pipeline(is.fn(options) ? options : callback);
|
||||||
}
|
}
|
||||||
@@ -109,19 +116,19 @@ function toBuffer (options, callback) {
|
|||||||
* .toFile('output-with-metadata.jpg')
|
* .toFile('output-with-metadata.jpg')
|
||||||
* .then(info => { ... });
|
* .then(info => { ... });
|
||||||
*
|
*
|
||||||
* @param {Object} [withMetadata]
|
* @param {Object} [options]
|
||||||
* @param {Number} [withMetadata.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
* @param {Number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function withMetadata (withMetadata) {
|
function withMetadata (options) {
|
||||||
this.options.withMetadata = is.bool(withMetadata) ? withMetadata : true;
|
this.options.withMetadata = is.bool(options) ? options : true;
|
||||||
if (is.object(withMetadata)) {
|
if (is.object(options)) {
|
||||||
if (is.defined(withMetadata.orientation)) {
|
if (is.defined(options.orientation)) {
|
||||||
if (is.integer(withMetadata.orientation) && is.inRange(withMetadata.orientation, 1, 8)) {
|
if (is.integer(options.orientation) && is.inRange(options.orientation, 1, 8)) {
|
||||||
this.options.withMetadataOrientation = withMetadata.orientation;
|
this.options.withMetadataOrientation = options.orientation;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid orientation (1 to 8) ' + withMetadata.orientation);
|
throw is.invalidParameterError('orientation', 'integer between 1 and 8', options.orientation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,13 +151,13 @@ function withMetadata (withMetadata) {
|
|||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
* @param {String} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling when quality <= 90
|
* @param {String} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling when quality <= 90
|
||||||
* @param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg
|
* @param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
|
||||||
* @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires mozjpeg
|
* @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
|
||||||
* @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg
|
* @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
|
||||||
* @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
* @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
||||||
* @param {Boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
* @param {Boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
||||||
* @param {Boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
* @param {Boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
||||||
* @param {Number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires mozjpeg
|
* @param {Number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
|
||||||
* @param {Number} [options.quantizationTable=0] - alternative spelling of quantisationTable
|
* @param {Number} [options.quantizationTable=0] - alternative spelling of quantisationTable
|
||||||
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -162,7 +169,7 @@ function jpeg (options) {
|
|||||||
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
this.options.jpegQuality = options.quality;
|
this.options.jpegQuality = options.quality;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(options.progressive)) {
|
if (is.defined(options.progressive)) {
|
||||||
@@ -172,33 +179,33 @@ function jpeg (options) {
|
|||||||
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
|
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
|
||||||
this.options.jpegChromaSubsampling = options.chromaSubsampling;
|
this.options.jpegChromaSubsampling = options.chromaSubsampling;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid chromaSubsampling (4:2:0, 4:4:4) ' + options.chromaSubsampling);
|
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
|
const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
|
||||||
if (is.defined(options.trellisQuantisation)) {
|
if (is.defined(trellisQuantisation)) {
|
||||||
this._setBooleanOption('jpegTrellisQuantisation', options.trellisQuantisation);
|
this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
|
||||||
}
|
}
|
||||||
if (is.defined(options.overshootDeringing)) {
|
if (is.defined(options.overshootDeringing)) {
|
||||||
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
|
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
|
||||||
}
|
}
|
||||||
options.optimiseScans = is.bool(options.optimizeScans) ? options.optimizeScans : options.optimiseScans;
|
const optimiseScans = is.bool(options.optimizeScans) ? options.optimizeScans : options.optimiseScans;
|
||||||
if (is.defined(options.optimiseScans)) {
|
if (is.defined(optimiseScans)) {
|
||||||
this._setBooleanOption('jpegOptimiseScans', options.optimiseScans);
|
this._setBooleanOption('jpegOptimiseScans', optimiseScans);
|
||||||
if (options.optimiseScans) {
|
if (optimiseScans) {
|
||||||
this.options.jpegProgressive = true;
|
this.options.jpegProgressive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
|
const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
|
||||||
if (is.defined(options.optimiseCoding)) {
|
if (is.defined(optimiseCoding)) {
|
||||||
this._setBooleanOption('jpegOptimiseCoding', options.optimiseCoding);
|
this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
|
||||||
}
|
}
|
||||||
options.quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
|
const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
|
||||||
if (is.defined(options.quantisationTable)) {
|
if (is.defined(quantisationTable)) {
|
||||||
if (is.integer(options.quantisationTable) && is.inRange(options.quantisationTable, 0, 8)) {
|
if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
|
||||||
this.options.jpegQuantisationTable = options.quantisationTable;
|
this.options.jpegQuantisationTable = quantisationTable;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid quantisation table (integer, 0-8) ' + options.quantisationTable);
|
throw is.invalidParameterError('quantisationTable', 'integer between 0 and 8', quantisationTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,6 +228,11 @@ function jpeg (options) {
|
|||||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
|
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
|
||||||
* @param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
* @param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
||||||
|
* @param {Boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
|
||||||
|
* @param {Number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, requires libvips compiled with support for libimagequant
|
||||||
|
* @param {Number} [options.colours=256] - maximum number of palette entries, requires libvips compiled with support for libimagequant
|
||||||
|
* @param {Number} [options.colors=256] - alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant
|
||||||
|
* @param {Number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant
|
||||||
* @param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@@ -234,12 +246,39 @@ function png (options) {
|
|||||||
if (is.integer(options.compressionLevel) && is.inRange(options.compressionLevel, 0, 9)) {
|
if (is.integer(options.compressionLevel) && is.inRange(options.compressionLevel, 0, 9)) {
|
||||||
this.options.pngCompressionLevel = options.compressionLevel;
|
this.options.pngCompressionLevel = options.compressionLevel;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid compressionLevel (integer, 0-9) ' + options.compressionLevel);
|
throw is.invalidParameterError('compressionLevel', 'integer between 0 and 9', options.compressionLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.defined(options.adaptiveFiltering)) {
|
if (is.defined(options.adaptiveFiltering)) {
|
||||||
this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
|
this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
|
||||||
}
|
}
|
||||||
|
if (is.defined(options.palette)) {
|
||||||
|
this._setBooleanOption('pngPalette', options.palette);
|
||||||
|
if (this.options.pngPalette) {
|
||||||
|
if (is.defined(options.quality)) {
|
||||||
|
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
|
||||||
|
this.options.pngQuality = options.quality;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const colours = options.colours || options.colors;
|
||||||
|
if (is.defined(colours)) {
|
||||||
|
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
||||||
|
this.options.pngColours = colours;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.dither)) {
|
||||||
|
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
|
||||||
|
this.options.pngDither = options.dither;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this._updateFormatOut('png', options);
|
return this._updateFormatOut('png', options);
|
||||||
}
|
}
|
||||||
@@ -258,6 +297,8 @@ function png (options) {
|
|||||||
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
||||||
* @param {Boolean} [options.lossless=false] - use lossless compression mode
|
* @param {Boolean} [options.lossless=false] - use lossless compression mode
|
||||||
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
|
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
|
||||||
|
* @param {Boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
||||||
|
* @param {Number} [options.reductionEffort=4] - level of CPU effort to reduce file size, integer 0-6
|
||||||
* @param {Boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@@ -267,14 +308,14 @@ function webp (options) {
|
|||||||
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
this.options.webpQuality = options.quality;
|
this.options.webpQuality = options.quality;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.object(options) && is.defined(options.alphaQuality)) {
|
if (is.object(options) && is.defined(options.alphaQuality)) {
|
||||||
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 0, 100)) {
|
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 0, 100)) {
|
||||||
this.options.webpAlphaQuality = options.alphaQuality;
|
this.options.webpAlphaQuality = options.alphaQuality;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid webp alpha quality (integer, 0-100) ' + options.alphaQuality);
|
throw is.invalidParameterError('alphaQuality', 'integer between 0 and 100', options.alphaQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.object(options) && is.defined(options.lossless)) {
|
if (is.object(options) && is.defined(options.lossless)) {
|
||||||
@@ -283,6 +324,16 @@ function webp (options) {
|
|||||||
if (is.object(options) && is.defined(options.nearLossless)) {
|
if (is.object(options) && is.defined(options.nearLossless)) {
|
||||||
this._setBooleanOption('webpNearLossless', options.nearLossless);
|
this._setBooleanOption('webpNearLossless', options.nearLossless);
|
||||||
}
|
}
|
||||||
|
if (is.object(options) && is.defined(options.smartSubsample)) {
|
||||||
|
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
|
||||||
|
}
|
||||||
|
if (is.object(options) && is.defined(options.reductionEffort)) {
|
||||||
|
if (is.integer(options.reductionEffort) && is.inRange(options.reductionEffort, 0, 6)) {
|
||||||
|
this.options.webpReductionEffort = options.reductionEffort;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('reductionEffort', 'integer between 0 and 6', options.reductionEffort);
|
||||||
|
}
|
||||||
|
}
|
||||||
return this._updateFormatOut('webp', options);
|
return this._updateFormatOut('webp', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,6 +355,10 @@ function webp (options) {
|
|||||||
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
||||||
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
||||||
* @param {Boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
* @param {Boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
||||||
|
* @param {Boolean} [options.pyramid=false] - write an image pyramid
|
||||||
|
* @param {Boolean} [options.tile=false] - write a tiled tiff
|
||||||
|
* @param {Boolean} [options.tileWidth=256] - horizontal tile size
|
||||||
|
* @param {Boolean} [options.tileHeight=256] - vertical tile size
|
||||||
* @param {Number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
* @param {Number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
||||||
* @param {Number} [options.yres=1.0] - vertical resolution in pixels/mm
|
* @param {Number} [options.yres=1.0] - vertical resolution in pixels/mm
|
||||||
* @param {Boolean} [options.squash=false] - squash 8-bit images down to 1 bit
|
* @param {Boolean} [options.squash=false] - squash 8-bit images down to 1 bit
|
||||||
@@ -311,56 +366,121 @@ function webp (options) {
|
|||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
*/
|
*/
|
||||||
function tiff (options) {
|
function tiff (options) {
|
||||||
if (is.object(options) && is.defined(options.quality)) {
|
if (is.object(options)) {
|
||||||
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
if (is.defined(options.quality)) {
|
||||||
this.options.tiffQuality = options.quality;
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
} else {
|
this.options.tiffQuality = options.quality;
|
||||||
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
} else {
|
||||||
|
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (is.defined(options.squash)) {
|
||||||
if (is.object(options) && is.defined(options.squash)) {
|
this._setBooleanOption('tiffSquash', options.squash);
|
||||||
if (is.bool(options.squash)) {
|
|
||||||
this.options.tiffSquash = options.squash;
|
|
||||||
} else {
|
|
||||||
throw new Error('Invalid Value for squash ' + options.squash + ' Only Boolean Values allowed for options.squash.');
|
|
||||||
}
|
}
|
||||||
}
|
// tiling
|
||||||
// resolution
|
if (is.defined(options.tile)) {
|
||||||
if (is.object(options) && is.defined(options.xres)) {
|
this._setBooleanOption('tiffTile', options.tile);
|
||||||
if (is.number(options.xres)) {
|
|
||||||
this.options.tiffXres = options.xres;
|
|
||||||
} else {
|
|
||||||
throw new Error('Invalid Value for xres ' + options.xres + ' Only numeric values allowed for options.xres');
|
|
||||||
}
|
}
|
||||||
}
|
if (is.defined(options.tileWidth)) {
|
||||||
if (is.object(options) && is.defined(options.yres)) {
|
if (is.integer(options.tileWidth) && options.tileWidth > 0) {
|
||||||
if (is.number(options.yres)) {
|
this.options.tiffTileWidth = options.tileWidth;
|
||||||
this.options.tiffYres = options.yres;
|
} else {
|
||||||
} else {
|
throw is.invalidParameterError('tileWidth', 'integer greater than zero', options.tileWidth);
|
||||||
throw new Error('Invalid Value for yres ' + options.yres + ' Only numeric values allowed for options.yres');
|
}
|
||||||
}
|
}
|
||||||
}
|
if (is.defined(options.tileHeight)) {
|
||||||
// compression
|
if (is.integer(options.tileHeight) && options.tileHeight > 0) {
|
||||||
if (is.defined(options) && is.defined(options.compression)) {
|
this.options.tiffTileHeight = options.tileHeight;
|
||||||
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'ccittfax4', 'none'])) {
|
} else {
|
||||||
this.options.tiffCompression = options.compression;
|
throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
|
||||||
} else {
|
}
|
||||||
const message = `Invalid compression option "${options.compression}". Should be one of: lzw, deflate, jpeg, ccittfax4, none`;
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
}
|
||||||
}
|
// pyramid
|
||||||
// predictor
|
if (is.defined(options.pyramid)) {
|
||||||
if (is.defined(options) && is.defined(options.predictor)) {
|
this._setBooleanOption('tiffPyramid', options.pyramid);
|
||||||
if (is.string(options.predictor) && is.inArray(options.predictor, ['none', 'horizontal', 'float'])) {
|
}
|
||||||
this.options.tiffPredictor = options.predictor;
|
// resolution
|
||||||
} else {
|
if (is.defined(options.xres)) {
|
||||||
const message = `Invalid predictor option "${options.predictor}". Should be one of: none, horizontal, float`;
|
if (is.number(options.xres) && options.xres > 0) {
|
||||||
throw new Error(message);
|
this.options.tiffXres = options.xres;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('xres', 'number greater than zero', options.xres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.yres)) {
|
||||||
|
if (is.number(options.yres) && options.yres > 0) {
|
||||||
|
this.options.tiffYres = options.yres;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('yres', 'number greater than zero', options.yres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// compression
|
||||||
|
if (is.defined(options.compression)) {
|
||||||
|
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'ccittfax4', 'none'])) {
|
||||||
|
this.options.tiffCompression = options.compression;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('compression', 'one of: lzw, deflate, jpeg, ccittfax4, none', options.compression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// predictor
|
||||||
|
if (is.defined(options.predictor)) {
|
||||||
|
if (is.string(options.predictor) && is.inArray(options.predictor, ['none', 'horizontal', 'float'])) {
|
||||||
|
this.options.tiffPredictor = options.predictor;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('predictor', 'one of: none, horizontal, float', options.predictor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._updateFormatOut('tiff', options);
|
return this._updateFormatOut('tiff', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use these HEIF options for output image.
|
||||||
|
*
|
||||||
|
* Support for HEIF (HEIC/AVIF) is experimental.
|
||||||
|
* Do not use this in production systems.
|
||||||
|
*
|
||||||
|
* Requires a custom, globally-installed libvips compiled with support for libheif.
|
||||||
|
*
|
||||||
|
* Most versions of libheif support only the patent-encumbered HEVC compression format.
|
||||||
|
*
|
||||||
|
* @param {Object} [options] - output options
|
||||||
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
|
* @param {Boolean} [options.compression='hevc'] - compression format: hevc, avc, jpeg, av1
|
||||||
|
* @param {Boolean} [options.lossless=false] - use lossless compression
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid options
|
||||||
|
*/
|
||||||
|
function heif (options) {
|
||||||
|
if (!this.constructor.format.heif.output.buffer) {
|
||||||
|
throw new Error('The heif operation requires libvips to have been installed with support for libheif');
|
||||||
|
}
|
||||||
|
if (is.object(options)) {
|
||||||
|
if (is.defined(options.quality)) {
|
||||||
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
||||||
|
this.options.heifQuality = options.quality;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.lossless)) {
|
||||||
|
if (is.bool(options.lossless)) {
|
||||||
|
this.options.heifLossless = options.lossless;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('lossless', 'boolean', options.lossless);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is.defined(options.compression)) {
|
||||||
|
if (is.string(options.compression) && is.inArray(options.compression, ['hevc', 'avc', 'jpeg', 'av1'])) {
|
||||||
|
this.options.heifCompression = options.compression;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('compression', 'one of: hevc, avc, jpeg, av1', options.compression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this._updateFormatOut('heif', options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to be raw, uncompressed uint8 pixel data.
|
* Force output to be raw, uncompressed uint8 pixel data.
|
||||||
*
|
*
|
||||||
@@ -376,6 +496,17 @@ function raw () {
|
|||||||
return this._updateFormatOut('raw');
|
return this._updateFormatOut('raw');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formats = new Map([
|
||||||
|
['heic', 'heif'],
|
||||||
|
['heif', 'heif'],
|
||||||
|
['jpeg', 'jpeg'],
|
||||||
|
['jpg', 'jpeg'],
|
||||||
|
['png', 'png'],
|
||||||
|
['raw', 'raw'],
|
||||||
|
['tiff', 'tiff'],
|
||||||
|
['webp', 'webp']
|
||||||
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to a given format.
|
* Force output to a given format.
|
||||||
*
|
*
|
||||||
@@ -391,14 +522,11 @@ function raw () {
|
|||||||
* @throws {Error} unsupported format or options
|
* @throws {Error} unsupported format or options
|
||||||
*/
|
*/
|
||||||
function toFormat (format, options) {
|
function toFormat (format, options) {
|
||||||
if (is.object(format) && is.string(format.id)) {
|
const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
|
||||||
format = format.id;
|
if (!actualFormat) {
|
||||||
|
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(', ')}`, format);
|
||||||
}
|
}
|
||||||
if (format === 'jpg') format = 'jpeg';
|
return this[actualFormat](options);
|
||||||
if (!is.inArray(format, ['jpeg', 'png', 'webp', 'tiff', 'raw'])) {
|
|
||||||
throw new Error('Unsupported output format ' + format);
|
|
||||||
}
|
|
||||||
return this[format](options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -419,79 +547,87 @@ function toFormat (format, options) {
|
|||||||
* // output_files contains 512x512 tiles grouped by zoom level
|
* // output_files contains 512x512 tiles grouped by zoom level
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @param {Object} [tile]
|
* @param {Object} [options]
|
||||||
* @param {Number} [tile.size=256] tile size in pixels, a value between 1 and 8192.
|
* @param {Number} [options.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} [options.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 {Number} [options.angle=0] tile angle of rotation, must be a multiple of 90.
|
||||||
* @param {String} [tile.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
* @param {String} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
* @param {String} [tile.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
* @param {Number} [options.skipBlanks=-1] threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images
|
||||||
* @param {String} [tile.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
|
* @param {String} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
||||||
|
* @param {String} [options.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
function tile (tile) {
|
function tile (options) {
|
||||||
if (is.object(tile)) {
|
if (is.object(options)) {
|
||||||
// Size of square tiles, in pixels
|
// Size of square tiles, in pixels
|
||||||
if (is.defined(tile.size)) {
|
if (is.defined(options.size)) {
|
||||||
if (is.integer(tile.size) && is.inRange(tile.size, 1, 8192)) {
|
if (is.integer(options.size) && is.inRange(options.size, 1, 8192)) {
|
||||||
this.options.tileSize = tile.size;
|
this.options.tileSize = options.size;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid tile size (1 to 8192) ' + tile.size);
|
throw is.invalidParameterError('size', 'integer between 1 and 8192', options.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Overlap of tiles, in pixels
|
// Overlap of tiles, in pixels
|
||||||
if (is.defined(tile.overlap)) {
|
if (is.defined(options.overlap)) {
|
||||||
if (is.integer(tile.overlap) && is.inRange(tile.overlap, 0, 8192)) {
|
if (is.integer(options.overlap) && is.inRange(options.overlap, 0, 8192)) {
|
||||||
if (tile.overlap > this.options.tileSize) {
|
if (options.overlap > this.options.tileSize) {
|
||||||
throw new Error('Tile overlap ' + tile.overlap + ' cannot be larger than tile size ' + this.options.tileSize);
|
throw is.invalidParameterError('overlap', `<= size (${this.options.tileSize})`, options.overlap);
|
||||||
}
|
}
|
||||||
this.options.tileOverlap = tile.overlap;
|
this.options.tileOverlap = tile.overlap;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid tile overlap (0 to 8192) ' + tile.overlap);
|
throw is.invalidParameterError('overlap', 'integer between 0 and 8192', options.overlap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Container
|
// Container
|
||||||
if (is.defined(tile.container)) {
|
if (is.defined(options.container)) {
|
||||||
if (is.string(tile.container) && is.inArray(tile.container, ['fs', 'zip'])) {
|
if (is.string(options.container) && is.inArray(options.container, ['fs', 'zip'])) {
|
||||||
this.options.tileContainer = tile.container;
|
this.options.tileContainer = options.container;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid tile container ' + tile.container);
|
throw is.invalidParameterError('container', 'one of: fs, zip', options.container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Layout
|
// Layout
|
||||||
if (is.defined(tile.layout)) {
|
if (is.defined(options.layout)) {
|
||||||
if (is.string(tile.layout) && is.inArray(tile.layout, ['dz', 'google', 'zoomify'])) {
|
if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'zoomify'])) {
|
||||||
this.options.tileLayout = tile.layout;
|
this.options.tileLayout = options.layout;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid tile layout ' + tile.layout);
|
throw is.invalidParameterError('layout', 'one of: dz, google, zoomify', options.layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Angle of rotation,
|
// Angle of rotation,
|
||||||
if (is.defined(tile.angle)) {
|
if (is.defined(options.angle)) {
|
||||||
if (is.integer(tile.angle) && !(tile.angle % 90)) {
|
if (is.integer(options.angle) && !(options.angle % 90)) {
|
||||||
this.options.tileAngle = tile.angle;
|
this.options.tileAngle = options.angle;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unsupported angle: angle must be a positive/negative multiple of 90 ' + tile.angle);
|
throw is.invalidParameterError('angle', 'positive/negative multiple of 90', options.angle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Depth of tiles
|
// Depth of tiles
|
||||||
if (is.defined(tile.depth)) {
|
if (is.defined(options.depth)) {
|
||||||
if (is.string(tile.depth) && is.inArray(tile.depth, ['onepixel', 'onetile', 'one'])) {
|
if (is.string(options.depth) && is.inArray(options.depth, ['onepixel', 'onetile', 'one'])) {
|
||||||
this.options.tileDepth = tile.depth;
|
this.options.tileDepth = options.depth;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Invalid tile depth '" + tile.depth + "', should be one of 'onepixel', 'onetile' or 'one'");
|
throw is.invalidParameterError('depth', 'one of: onepixel, onetile, one', options.depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Threshold to skip blank tiles
|
||||||
|
if (is.defined(options.skipBlanks)) {
|
||||||
|
if (is.integer(options.skipBlanks) && is.inRange(options.skipBlanks, -1, 65535)) {
|
||||||
|
this.options.tileSkipBlanks = options.skipBlanks;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('skipBlanks', 'integer between -1 and 255/65535', options.skipBlanks);
|
||||||
|
}
|
||||||
|
} else if (is.defined(options.layout) && options.layout === 'google') {
|
||||||
|
this.options.tileSkipBlanks = 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Format
|
// Format
|
||||||
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
||||||
this.options.tileFormat = this.options.formatOut;
|
this.options.tileFormat = this.options.formatOut;
|
||||||
} else if (this.options.formatOut !== 'input') {
|
} else if (this.options.formatOut !== 'input') {
|
||||||
throw new Error('Invalid tile format ' + this.options.formatOut);
|
throw is.invalidParameterError('format', 'one of: jpeg, png, webp', this.options.formatOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._updateFormatOut('dz');
|
return this._updateFormatOut('dz');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +641,9 @@ function tile (tile) {
|
|||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
function _updateFormatOut (formatOut, options) {
|
function _updateFormatOut (formatOut, options) {
|
||||||
this.options.formatOut = (is.object(options) && options.force === false) ? 'input' : formatOut;
|
if (!(is.object(options) && options.force === false)) {
|
||||||
|
this.options.formatOut = formatOut;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,7 +658,7 @@ function _setBooleanOption (key, val) {
|
|||||||
if (is.bool(val)) {
|
if (is.bool(val)) {
|
||||||
this.options[key] = val;
|
this.options[key] = val;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid ' + key + ' (boolean) ' + val);
|
throw is.invalidParameterError(key, 'boolean', val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,6 +667,7 @@ function _setBooleanOption (key, val) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _read () {
|
function _read () {
|
||||||
|
/* istanbul ignore else */
|
||||||
if (!this.options.streamOut) {
|
if (!this.options.streamOut) {
|
||||||
this.options.streamOut = true;
|
this.options.streamOut = true;
|
||||||
this._pipeline();
|
this._pipeline();
|
||||||
@@ -541,14 +680,13 @@ function _read () {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _pipeline (callback) {
|
function _pipeline (callback) {
|
||||||
const that = this;
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
// output=file/buffer
|
// output=file/buffer
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
// output=file/buffer, input=stream
|
// output=file/buffer, input=stream
|
||||||
this.on('finish', function () {
|
this.on('finish', () => {
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.pipeline(that.options, callback);
|
sharp.pipeline(this.options, callback);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// output=file/buffer, input=file/buffer
|
// output=file/buffer, input=file/buffer
|
||||||
@@ -559,41 +697,31 @@ function _pipeline (callback) {
|
|||||||
// output=stream
|
// output=stream
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
// output=stream, input=stream
|
// output=stream, input=stream
|
||||||
if (this.streamInFinished) {
|
this.once('finish', () => {
|
||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.pipeline(this.options, function (err, data, info) {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
that.emit('error', err);
|
this.emit('error', err);
|
||||||
} else {
|
} else {
|
||||||
that.emit('info', info);
|
this.emit('info', info);
|
||||||
that.push(data);
|
this.push(data);
|
||||||
}
|
}
|
||||||
that.push(null);
|
this.push(null);
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.on('finish', function () {
|
|
||||||
that._flattenBufferIn();
|
|
||||||
sharp.pipeline(that.options, function (err, data, info) {
|
|
||||||
if (err) {
|
|
||||||
that.emit('error', err);
|
|
||||||
} else {
|
|
||||||
that.emit('info', info);
|
|
||||||
that.push(data);
|
|
||||||
}
|
|
||||||
that.push(null);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
if (this.streamInFinished) {
|
||||||
|
this.emit('finish');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// output=stream, input=file/buffer
|
// output=stream, input=file/buffer
|
||||||
sharp.pipeline(this.options, function (err, data, info) {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
that.emit('error', err);
|
this.emit('error', err);
|
||||||
} else {
|
} else {
|
||||||
that.emit('info', info);
|
this.emit('info', info);
|
||||||
that.push(data);
|
this.push(data);
|
||||||
}
|
}
|
||||||
that.push(null);
|
this.push(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -601,15 +729,15 @@ function _pipeline (callback) {
|
|||||||
// output=promise
|
// output=promise
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
// output=promise, input=stream
|
// output=promise, input=stream
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
that.on('finish', function () {
|
this.once('finish', () => {
|
||||||
that._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.pipeline(that.options, function (err, data, info) {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
if (that.options.resolveWithObject) {
|
if (this.options.resolveWithObject) {
|
||||||
resolve({ data: data, info: info });
|
resolve({ data, info });
|
||||||
} else {
|
} else {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}
|
}
|
||||||
@@ -619,12 +747,12 @@ function _pipeline (callback) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// output=promise, input=file/buffer
|
// output=promise, input=file/buffer
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise((resolve, reject) => {
|
||||||
sharp.pipeline(that.options, function (err, data, info) {
|
sharp.pipeline(this.options, (err, data, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
if (that.options.resolveWithObject) {
|
if (this.options.resolveWithObject) {
|
||||||
resolve({ data: data, info: info });
|
resolve({ data: data, info: info });
|
||||||
} else {
|
} else {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
@@ -641,7 +769,7 @@ function _pipeline (callback) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
[
|
Object.assign(Sharp.prototype, {
|
||||||
// Public
|
// Public
|
||||||
toFile,
|
toFile,
|
||||||
toBuffer,
|
toBuffer,
|
||||||
@@ -650,6 +778,7 @@ module.exports = function (Sharp) {
|
|||||||
png,
|
png,
|
||||||
webp,
|
webp,
|
||||||
tiff,
|
tiff,
|
||||||
|
heif,
|
||||||
raw,
|
raw,
|
||||||
toFormat,
|
toFormat,
|
||||||
tile,
|
tile,
|
||||||
@@ -658,7 +787,5 @@ module.exports = function (Sharp) {
|
|||||||
_setBooleanOption,
|
_setBooleanOption,
|
||||||
_read,
|
_read,
|
||||||
_pipeline
|
_pipeline
|
||||||
].forEach(function (f) {
|
|
||||||
Sharp.prototype[f.name] = f;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,17 +2,23 @@
|
|||||||
|
|
||||||
const detectLibc = require('detect-libc');
|
const detectLibc = require('detect-libc');
|
||||||
|
|
||||||
|
const env = process.env;
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const arch = process.env.npm_config_arch || process.arch;
|
const arch = env.npm_config_arch || process.arch;
|
||||||
const platform = process.env.npm_config_platform || process.platform;
|
const platform = env.npm_config_platform || process.platform;
|
||||||
|
/* istanbul ignore next */
|
||||||
const libc = (platform === 'linux' && detectLibc.isNonGlibcLinux) ? detectLibc.family : '';
|
const libc = (platform === 'linux' && detectLibc.isNonGlibcLinux) ? detectLibc.family : '';
|
||||||
|
|
||||||
const platformId = [`${platform}${libc}`];
|
const platformId = [`${platform}${libc}`];
|
||||||
if (arch === 'arm' || arch === 'armhf' || arch === 'arm64') {
|
|
||||||
const armVersion = (arch === 'arm64') ? '8' : process.env.npm_config_armv || process.config.variables.arm_version || '6';
|
if (arch === 'arm') {
|
||||||
platformId.push(`armv${armVersion}`);
|
platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || '6'}`);
|
||||||
|
} else if (arch === 'arm64') {
|
||||||
|
platformId.push(`arm64v${env.npm_config_arm_version || '8'}`);
|
||||||
} else {
|
} else {
|
||||||
platformId.push(arch);
|
platformId.push(arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return platformId.join('-');
|
return platformId.join('-');
|
||||||
};
|
};
|
||||||
|
|||||||
135
lib/resize.js
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const deprecate = require('util').deprecate;
|
|
||||||
const is = require('./is');
|
const is = require('./is');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +54,7 @@ const strategy = {
|
|||||||
const kernel = {
|
const kernel = {
|
||||||
nearest: 'nearest',
|
nearest: 'nearest',
|
||||||
cubic: 'cubic',
|
cubic: 'cubic',
|
||||||
|
mitchell: 'mitchell',
|
||||||
lanczos2: 'lanczos2',
|
lanczos2: 'lanczos2',
|
||||||
lanczos3: 'lanczos3'
|
lanczos3: 'lanczos3'
|
||||||
};
|
};
|
||||||
@@ -110,6 +110,7 @@ const mapFitToCanvas = {
|
|||||||
* Possible interpolation kernels are:
|
* Possible interpolation 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).
|
||||||
|
* - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
||||||
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||||
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
*
|
*
|
||||||
@@ -209,12 +210,20 @@ function resize (width, height, options) {
|
|||||||
}
|
}
|
||||||
if (is.object(options)) {
|
if (is.object(options)) {
|
||||||
// Width
|
// Width
|
||||||
if (is.integer(options.width) && options.width > 0) {
|
if (is.defined(options.width)) {
|
||||||
this.options.width = options.width;
|
if (is.integer(options.width) && options.width > 0) {
|
||||||
|
this.options.width = options.width;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('width', 'positive integer', options.width);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Height
|
// Height
|
||||||
if (is.integer(options.height) && options.height > 0) {
|
if (is.defined(options.height)) {
|
||||||
this.options.height = options.height;
|
if (is.integer(options.height) && options.height > 0) {
|
||||||
|
this.options.height = options.height;
|
||||||
|
} else {
|
||||||
|
throw is.invalidParameterError('height', 'positive integer', options.height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Fit
|
// Fit
|
||||||
if (is.defined(options.fit)) {
|
if (is.defined(options.fit)) {
|
||||||
@@ -238,7 +247,7 @@ function resize (width, height, options) {
|
|||||||
}
|
}
|
||||||
// Background
|
// Background
|
||||||
if (is.defined(options.background)) {
|
if (is.defined(options.background)) {
|
||||||
this._setColourOption('resizeBackground', options.background);
|
this._setBackgroundColourOption('resizeBackground', options.background);
|
||||||
}
|
}
|
||||||
// Kernel
|
// Kernel
|
||||||
if (is.defined(options.kernel)) {
|
if (is.defined(options.kernel)) {
|
||||||
@@ -269,12 +278,11 @@ function resize (width, height, options) {
|
|||||||
* // to the top, left and right edges and 20 to the bottom edge
|
* // to the top, left and right edges and 20 to the bottom edge
|
||||||
* sharp(input)
|
* sharp(input)
|
||||||
* .resize(140)
|
* .resize(140)
|
||||||
* .)
|
|
||||||
* .extend({
|
* .extend({
|
||||||
* top: 10,
|
* top: 10,
|
||||||
* bottom: 20,
|
* bottom: 20,
|
||||||
* left: 10,
|
* left: 10,
|
||||||
* right: 10
|
* right: 10,
|
||||||
* background: { r: 0, g: 0, b: 0, alpha: 0 }
|
* background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||||
* })
|
* })
|
||||||
* ...
|
* ...
|
||||||
@@ -305,9 +313,9 @@ function extend (extend) {
|
|||||||
this.options.extendBottom = extend.bottom;
|
this.options.extendBottom = extend.bottom;
|
||||||
this.options.extendLeft = extend.left;
|
this.options.extendLeft = extend.left;
|
||||||
this.options.extendRight = extend.right;
|
this.options.extendRight = extend.right;
|
||||||
this._setColourOption('extendBackground', extend.background);
|
this._setBackgroundColourOption('extendBackground', extend.background);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid edge extension ' + extend);
|
throw is.invalidParameterError('extend', 'integer or object', extend);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -334,11 +342,11 @@ function extend (extend) {
|
|||||||
* // Extract a region, resize, then extract from the resized image
|
* // Extract a region, resize, then extract from the resized image
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* @param {Object} options
|
* @param {Object} options - describes the region to extract using integral pixel values
|
||||||
* @param {Number} options.left - zero-indexed offset from left edge
|
* @param {Number} options.left - zero-indexed offset from left edge
|
||||||
* @param {Number} options.top - zero-indexed offset from top edge
|
* @param {Number} options.top - zero-indexed offset from top edge
|
||||||
* @param {Number} options.width - dimension of extracted image
|
* @param {Number} options.width - width of region to extract
|
||||||
* @param {Number} options.height - dimension of extracted image
|
* @param {Number} options.height - height of region to extract
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
*/
|
*/
|
||||||
@@ -349,11 +357,11 @@ function extract (options) {
|
|||||||
if (is.integer(value) && value >= 0) {
|
if (is.integer(value) && value >= 0) {
|
||||||
this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
|
this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Non-integer value for ' + name + ' of ' + value);
|
throw is.invalidParameterError(name, 'integer', value);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
// Ensure existing rotation occurs before pre-resize extraction
|
// Ensure existing rotation occurs before pre-resize extraction
|
||||||
if (suffix === 'Pre' && ((this.options.angle % 360) !== 0 || this.options.useExifOrientation === true)) {
|
if (suffix === 'Pre' && ((this.options.angle % 360) !== 0 || this.options.useExifOrientation === true || this.options.rotationAngle !== 0)) {
|
||||||
this.options.rotateBeforePreExtract = true;
|
this.options.rotateBeforePreExtract = true;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -377,104 +385,16 @@ function trim (threshold) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated functions
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function crop (crop) {
|
|
||||||
this.options.canvas = 'crop';
|
|
||||||
if (!is.defined(crop)) {
|
|
||||||
// Default
|
|
||||||
this.options.position = gravity.center;
|
|
||||||
} else if (is.integer(crop) && is.inRange(crop, 0, 8)) {
|
|
||||||
// Gravity (numeric)
|
|
||||||
this.options.position = crop;
|
|
||||||
} else if (is.string(crop) && is.integer(gravity[crop])) {
|
|
||||||
// Gravity (string)
|
|
||||||
this.options.position = gravity[crop];
|
|
||||||
} else if (is.integer(crop) && crop >= strategy.entropy) {
|
|
||||||
// Strategy
|
|
||||||
this.options.position = crop;
|
|
||||||
} else if (is.string(crop) && is.integer(strategy[crop])) {
|
|
||||||
// Strategy (string)
|
|
||||||
this.options.position = strategy[crop];
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('crop', 'valid crop id/name/strategy', crop);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function embed (embed) {
|
|
||||||
this.options.canvas = 'embed';
|
|
||||||
if (!is.defined(embed)) {
|
|
||||||
// Default
|
|
||||||
this.options.position = gravity.center;
|
|
||||||
} else if (is.integer(embed) && is.inRange(embed, 0, 8)) {
|
|
||||||
// Gravity (numeric)
|
|
||||||
this.options.position = embed;
|
|
||||||
} else if (is.string(embed) && is.integer(gravity[embed])) {
|
|
||||||
// Gravity (string)
|
|
||||||
this.options.position = gravity[embed];
|
|
||||||
} else {
|
|
||||||
throw is.invalidParameterError('embed', 'valid embed id/name', embed);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function max () {
|
|
||||||
this.options.canvas = 'max';
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function min () {
|
|
||||||
this.options.canvas = 'min';
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function ignoreAspectRatio () {
|
|
||||||
this.options.canvas = 'ignore_aspect';
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function withoutEnlargement (withoutEnlargement) {
|
|
||||||
this.options.withoutEnlargement = is.bool(withoutEnlargement) ? withoutEnlargement : true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the Sharp prototype with resize-related functions.
|
* Decorate the Sharp prototype with resize-related functions.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
[
|
Object.assign(Sharp.prototype, {
|
||||||
resize,
|
resize,
|
||||||
extend,
|
extend,
|
||||||
extract,
|
extract,
|
||||||
trim
|
trim
|
||||||
].forEach(function (f) {
|
|
||||||
Sharp.prototype[f.name] = f;
|
|
||||||
});
|
});
|
||||||
// Class attributes
|
// Class attributes
|
||||||
Sharp.gravity = gravity;
|
Sharp.gravity = gravity;
|
||||||
@@ -482,11 +402,4 @@ module.exports = function (Sharp) {
|
|||||||
Sharp.kernel = kernel;
|
Sharp.kernel = kernel;
|
||||||
Sharp.fit = fit;
|
Sharp.fit = fit;
|
||||||
Sharp.position = position;
|
Sharp.position = position;
|
||||||
// Deprecated functions, to be removed in v0.22.0
|
|
||||||
Sharp.prototype.crop = deprecate(crop, 'crop(position) is deprecated, use resize({ fit: "cover", position }) instead');
|
|
||||||
Sharp.prototype.embed = deprecate(embed, 'embed(position) is deprecated, use resize({ fit: "contain", position }) instead');
|
|
||||||
Sharp.prototype.max = deprecate(max, 'max() is deprecated, use resize({ fit: "inside" }) instead');
|
|
||||||
Sharp.prototype.min = deprecate(min, 'min() is deprecated, use resize({ fit: "outside" }) instead');
|
|
||||||
Sharp.prototype.ignoreAspectRatio = deprecate(ignoreAspectRatio, 'ignoreAspectRatio() is deprecated, use resize({ fit: "fill" }) instead');
|
|
||||||
Sharp.prototype.withoutEnlargement = deprecate(withoutEnlargement, 'withoutEnlargement() is deprecated, use resize({ withoutEnlargement: true }) instead');
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
site_name: sharp
|
site_name: sharp
|
||||||
site_url: http://sharp.pixelplumbing.com/
|
site_url: https://sharp.pixelplumbing.com/
|
||||||
repo_url: https://github.com/lovell/sharp
|
repo_url: https://github.com/lovell/sharp
|
||||||
site_description: High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images
|
site_description: High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images
|
||||||
copyright: <a href="https://pixelplumbing.com/">pixelplumbing.com</a>
|
copyright: <a href="https://pixelplumbing.com/">pixelplumbing.com</a>
|
||||||
|
|||||||
55
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.21.0",
|
"version": "0.23.1",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -55,13 +55,22 @@
|
|||||||
"Alun Davies <alun.owain.davies@googlemail.com>",
|
"Alun Davies <alun.owain.davies@googlemail.com>",
|
||||||
"Aidan Hoolachan <ajhoolachan21@gmail.com>",
|
"Aidan Hoolachan <ajhoolachan21@gmail.com>",
|
||||||
"Axel Eirola <axel.eirola@iki.fi>",
|
"Axel Eirola <axel.eirola@iki.fi>",
|
||||||
"Freezy <freezy@xbmc.org>"
|
"Freezy <freezy@xbmc.org>",
|
||||||
|
"Daiz <taneli.vatanen@gmail.com>",
|
||||||
|
"Julian Aubourg <j@ubourg.net>",
|
||||||
|
"Keith Belovay <keith@picthrive.com>",
|
||||||
|
"Michael B. Klein <mbklein@gmail.com>",
|
||||||
|
"Jordan Prudhomme <jordan@raboland.fr>",
|
||||||
|
"Ilya Ovdin <iovdin@gmail.com>",
|
||||||
|
"Andargor <andargor@yahoo.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
||||||
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
||||||
"test": "semistandard && cc && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js && prebuild-ci",
|
"test": "semistandard && cc && npm run test-unit && npm run test-licensing && prebuild-ci",
|
||||||
"coverage": "./test/coverage/report.sh",
|
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
||||||
|
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
||||||
|
"test-coverage": "./test/coverage/report.sh",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done"
|
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done"
|
||||||
},
|
},
|
||||||
@@ -87,38 +96,38 @@
|
|||||||
"vips"
|
"vips"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^3.0.0",
|
"color": "^3.1.2",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"nan": "^2.11.1",
|
"nan": "^2.14.0",
|
||||||
"fs-copy-file-sync": "^1.1.1",
|
|
||||||
"npmlog": "^4.1.2",
|
"npmlog": "^4.1.2",
|
||||||
"prebuild-install": "^5.2.0",
|
"prebuild-install": "^5.3.2",
|
||||||
"semver": "^5.5.1",
|
"semver": "^6.3.0",
|
||||||
"simple-get": "^3.0.3",
|
"simple-get": "^3.1.0",
|
||||||
"tar": "^4.4.6",
|
"tar": "^4.4.13",
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.6.1",
|
"async": "^3.1.0",
|
||||||
"cc": "^1.0.2",
|
"cc": "^1.0.2",
|
||||||
"decompress-zip": "^0.3.1",
|
"decompress-zip": "^0.3.2",
|
||||||
"documentation": "^8.1.2",
|
"documentation": "^12.1.2",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"mocha": "^5.2.0",
|
"license-checker": "^25.0.1",
|
||||||
"mock-fs": "^4.7.0",
|
"mocha": "^6.2.0",
|
||||||
"nyc": "^13.1.0",
|
"mock-fs": "^4.10.1",
|
||||||
"prebuild": "^8.1.0",
|
"nyc": "^14.1.1",
|
||||||
"prebuild-ci": "^2.2.3",
|
"prebuild": "^9.1.0",
|
||||||
"rimraf": "^2.6.2",
|
"prebuild-ci": "^3.1.0",
|
||||||
"semistandard": "^12.0.1"
|
"rimraf": "^3.0.0",
|
||||||
|
"semistandard": "^14.2.0"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"config": {
|
"config": {
|
||||||
"libvips": "8.7.0"
|
"libvips": "8.8.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=8.5.0"
|
||||||
},
|
},
|
||||||
"semistandard": {
|
"semistandard": {
|
||||||
"env": [
|
"env": [
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -31,13 +31,13 @@ using vips::VImage;
|
|||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
// Convenience methods to access the attributes of a v8::Object
|
// Convenience methods to access the attributes of a v8::Object
|
||||||
bool HasAttr(v8::Handle<v8::Object> obj, std::string attr) {
|
bool HasAttr(v8::Local<v8::Object> obj, std::string attr) {
|
||||||
return Nan::Has(obj, Nan::New(attr).ToLocalChecked()).FromJust();
|
return Nan::Has(obj, Nan::New(attr).ToLocalChecked()).FromJust();
|
||||||
}
|
}
|
||||||
std::string AttrAsStr(v8::Handle<v8::Object> obj, std::string attr) {
|
std::string AttrAsStr(v8::Local<v8::Object> obj, std::string attr) {
|
||||||
return *Nan::Utf8String(Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked());
|
return *Nan::Utf8String(Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked());
|
||||||
}
|
}
|
||||||
std::vector<double> AttrAsRgba(v8::Handle<v8::Object> obj, std::string attr) {
|
std::vector<double> AttrAsRgba(v8::Local<v8::Object> obj, std::string attr) {
|
||||||
v8::Local<v8::Object> background = AttrAs<v8::Object>(obj, attr);
|
v8::Local<v8::Object> background = AttrAs<v8::Object>(obj, attr);
|
||||||
std::vector<double> rgba(4);
|
std::vector<double> rgba(4);
|
||||||
for (unsigned int i = 0; i < 4; i++) {
|
for (unsigned int i = 0; i < 4; i++) {
|
||||||
@@ -48,7 +48,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::Local<v8::Object> input, std::vector<v8::Local<v8::Object>> &buffersToPersist
|
||||||
) {
|
) {
|
||||||
Nan::HandleScope();
|
Nan::HandleScope();
|
||||||
InputDescriptor *descriptor = new InputDescriptor;
|
InputDescriptor *descriptor = new InputDescriptor;
|
||||||
@@ -71,7 +71,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
|
// Multi-page input (GIF, TIFF, PDF)
|
||||||
|
if (HasAttr(input, "pages")) {
|
||||||
|
descriptor->pages = AttrTo<int32_t>(input, "pages");
|
||||||
|
}
|
||||||
if (HasAttr(input, "page")) {
|
if (HasAttr(input, "page")) {
|
||||||
descriptor->page = AttrTo<uint32_t>(input, "page");
|
descriptor->page = AttrTo<uint32_t>(input, "page");
|
||||||
}
|
}
|
||||||
@@ -107,6 +110,15 @@ namespace sharp {
|
|||||||
bool IsTiff(std::string const &str) {
|
bool IsTiff(std::string const &str) {
|
||||||
return EndsWith(str, ".tif") || EndsWith(str, ".tiff") || EndsWith(str, ".TIF") || EndsWith(str, ".TIFF");
|
return EndsWith(str, ".tif") || EndsWith(str, ".tiff") || EndsWith(str, ".TIF") || EndsWith(str, ".TIFF");
|
||||||
}
|
}
|
||||||
|
bool IsHeic(std::string const &str) {
|
||||||
|
return EndsWith(str, ".heic") || EndsWith(str, ".HEIC");
|
||||||
|
}
|
||||||
|
bool IsHeif(std::string const &str) {
|
||||||
|
return EndsWith(str, ".heif") || EndsWith(str, ".HEIF") || IsHeic(str) || IsAvif(str);
|
||||||
|
}
|
||||||
|
bool IsAvif(std::string const &str) {
|
||||||
|
return EndsWith(str, ".avif") || EndsWith(str, ".AVIF");
|
||||||
|
}
|
||||||
bool IsDz(std::string const &str) {
|
bool IsDz(std::string const &str) {
|
||||||
return EndsWith(str, ".dzi") || EndsWith(str, ".DZI");
|
return EndsWith(str, ".dzi") || EndsWith(str, ".DZI");
|
||||||
}
|
}
|
||||||
@@ -129,14 +141,16 @@ namespace sharp {
|
|||||||
case ImageType::TIFF: id = "tiff"; break;
|
case ImageType::TIFF: id = "tiff"; break;
|
||||||
case ImageType::GIF: id = "gif"; break;
|
case ImageType::GIF: id = "gif"; break;
|
||||||
case ImageType::SVG: id = "svg"; break;
|
case ImageType::SVG: id = "svg"; break;
|
||||||
|
case ImageType::HEIF: id = "heif"; break;
|
||||||
case ImageType::PDF: id = "pdf"; break;
|
case ImageType::PDF: id = "pdf"; break;
|
||||||
case ImageType::MAGICK: id = "magick"; break;
|
case ImageType::MAGICK: id = "magick"; break;
|
||||||
case ImageType::OPENSLIDE: id = "openslide"; break;
|
case ImageType::OPENSLIDE: id = "openslide"; break;
|
||||||
case ImageType::PPM: id = "ppm"; break;
|
case ImageType::PPM: id = "ppm"; break;
|
||||||
case ImageType::FITS: id = "fits"; break;
|
case ImageType::FITS: id = "fits"; break;
|
||||||
case ImageType::VIPS: id = "v"; break;
|
case ImageType::VIPS: id = "vips"; break;
|
||||||
case ImageType::RAW: id = "raw"; break;
|
case ImageType::RAW: id = "raw"; break;
|
||||||
case ImageType::UNKNOWN: id = "unknown"; break;
|
case ImageType::UNKNOWN: id = "unknown"; break;
|
||||||
|
case ImageType::MISSING: id = "missing"; break;
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -161,6 +175,8 @@ namespace sharp {
|
|||||||
imageType = ImageType::GIF;
|
imageType = ImageType::GIF;
|
||||||
} else if (EndsWith(loader, "SvgBuffer")) {
|
} else if (EndsWith(loader, "SvgBuffer")) {
|
||||||
imageType = ImageType::SVG;
|
imageType = ImageType::SVG;
|
||||||
|
} else if (EndsWith(loader, "HeifBuffer")) {
|
||||||
|
imageType = ImageType::HEIF;
|
||||||
} else if (EndsWith(loader, "PdfBuffer")) {
|
} else if (EndsWith(loader, "PdfBuffer")) {
|
||||||
imageType = ImageType::PDF;
|
imageType = ImageType::PDF;
|
||||||
} else if (EndsWith(loader, "MagickBuffer")) {
|
} else if (EndsWith(loader, "MagickBuffer")) {
|
||||||
@@ -192,6 +208,8 @@ namespace sharp {
|
|||||||
imageType = ImageType::GIF;
|
imageType = ImageType::GIF;
|
||||||
} else if (EndsWith(loader, "SvgFile")) {
|
} else if (EndsWith(loader, "SvgFile")) {
|
||||||
imageType = ImageType::SVG;
|
imageType = ImageType::SVG;
|
||||||
|
} else if (EndsWith(loader, "HeifFile")) {
|
||||||
|
imageType = ImageType::HEIF;
|
||||||
} else if (EndsWith(loader, "PdfFile")) {
|
} else if (EndsWith(loader, "PdfFile")) {
|
||||||
imageType = ImageType::PDF;
|
imageType = ImageType::PDF;
|
||||||
} else if (EndsWith(loader, "Ppm")) {
|
} else if (EndsWith(loader, "Ppm")) {
|
||||||
@@ -203,10 +221,25 @@ namespace sharp {
|
|||||||
} else if (EndsWith(loader, "Magick") || EndsWith(loader, "MagickFile")) {
|
} else if (EndsWith(loader, "Magick") || EndsWith(loader, "MagickFile")) {
|
||||||
imageType = ImageType::MAGICK;
|
imageType = ImageType::MAGICK;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (EndsWith(vips::VError().what(), " not found\n")) {
|
||||||
|
imageType = ImageType::MISSING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return imageType;
|
return imageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Does this image type support multiple pages?
|
||||||
|
*/
|
||||||
|
bool ImageTypeSupportsPage(ImageType imageType) {
|
||||||
|
return
|
||||||
|
imageType == ImageType::GIF ||
|
||||||
|
imageType == ImageType::TIFF ||
|
||||||
|
imageType == ImageType::HEIF ||
|
||||||
|
imageType == ImageType::PDF;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
|
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
|
||||||
*/
|
*/
|
||||||
@@ -238,15 +271,16 @@ namespace sharp {
|
|||||||
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) {
|
if (ImageTypeSupportsPage(imageType)) {
|
||||||
option->set("page", descriptor->page);
|
option->set("n", descriptor->pages);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (vips::VError const &err) {
|
||||||
throw vips::VError("Input buffer has corrupt header");
|
throw vips::VError(std::string("Input buffer has corrupt header: ") + err.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw vips::VError("Input buffer contains unsupported image format");
|
throw vips::VError("Input buffer contains unsupported image format");
|
||||||
@@ -269,6 +303,9 @@ namespace sharp {
|
|||||||
} else {
|
} else {
|
||||||
// From filesystem
|
// From filesystem
|
||||||
imageType = DetermineImageType(descriptor->file.data());
|
imageType = DetermineImageType(descriptor->file.data());
|
||||||
|
if (imageType == ImageType::MISSING) {
|
||||||
|
throw vips::VError("Input file is missing");
|
||||||
|
}
|
||||||
if (imageType != ImageType::UNKNOWN) {
|
if (imageType != ImageType::UNKNOWN) {
|
||||||
try {
|
try {
|
||||||
vips::VOption *option = VImage::option()
|
vips::VOption *option = VImage::option()
|
||||||
@@ -280,18 +317,19 @@ namespace sharp {
|
|||||||
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) {
|
if (ImageTypeSupportsPage(imageType)) {
|
||||||
option->set("page", descriptor->page);
|
option->set("n", descriptor->pages);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (vips::VError const &err) {
|
||||||
throw vips::VError("Input file has corrupt header");
|
throw vips::VError(std::string("Input file has corrupt header: ") + err.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw vips::VError("Input file is missing or of an unsupported image format");
|
throw vips::VError("Input file contains unsupported image format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/common.h
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 Lovell Fuller and contributors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
// Verify platform and compiler compatibility
|
// Verify platform and compiler compatibility
|
||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 6))
|
#if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 8))
|
||||||
#error libvips version 8.6.1+ is required - see sharp.pixelplumbing.com/page/install
|
#error libvips version 8.8.0+ 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)))
|
||||||
@@ -53,6 +53,7 @@ namespace sharp {
|
|||||||
int rawChannels;
|
int rawChannels;
|
||||||
int rawWidth;
|
int rawWidth;
|
||||||
int rawHeight;
|
int rawHeight;
|
||||||
|
int pages;
|
||||||
int page;
|
int page;
|
||||||
int createChannels;
|
int createChannels;
|
||||||
int createWidth;
|
int createWidth;
|
||||||
@@ -61,12 +62,13 @@ namespace sharp {
|
|||||||
|
|
||||||
InputDescriptor():
|
InputDescriptor():
|
||||||
buffer(nullptr),
|
buffer(nullptr),
|
||||||
failOnError(FALSE),
|
failOnError(TRUE),
|
||||||
bufferLength(0),
|
bufferLength(0),
|
||||||
density(72.0),
|
density(72.0),
|
||||||
rawChannels(0),
|
rawChannels(0),
|
||||||
rawWidth(0),
|
rawWidth(0),
|
||||||
rawHeight(0),
|
rawHeight(0),
|
||||||
|
pages(1),
|
||||||
page(0),
|
page(0),
|
||||||
createChannels(0),
|
createChannels(0),
|
||||||
createWidth(0),
|
createWidth(0),
|
||||||
@@ -75,22 +77,22 @@ namespace sharp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Convenience methods to access the attributes of a v8::Object
|
// Convenience methods to access the attributes of a v8::Object
|
||||||
bool HasAttr(v8::Handle<v8::Object> obj, std::string attr);
|
bool HasAttr(v8::Local<v8::Object> obj, std::string attr);
|
||||||
std::string AttrAsStr(v8::Handle<v8::Object> obj, std::string attr);
|
std::string AttrAsStr(v8::Local<v8::Object> obj, std::string attr);
|
||||||
std::vector<double> AttrAsRgba(v8::Handle<v8::Object> obj, std::string attr);
|
std::vector<double> AttrAsRgba(v8::Local<v8::Object> obj, std::string attr);
|
||||||
template<typename T> v8::Local<T> AttrAs(v8::Handle<v8::Object> obj, std::string attr) {
|
template<typename T> v8::Local<T> AttrAs(v8::Local<v8::Object> obj, std::string attr) {
|
||||||
return Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked().As<T>();
|
return Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked().As<T>();
|
||||||
}
|
}
|
||||||
template<typename T> T AttrTo(v8::Handle<v8::Object> obj, std::string attr) {
|
template<typename T> T AttrTo(v8::Local<v8::Object> obj, std::string attr) {
|
||||||
return Nan::To<T>(Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked()).FromJust();
|
return Nan::To<T>(Nan::Get(obj, Nan::New(attr).ToLocalChecked()).ToLocalChecked()).FromJust();
|
||||||
}
|
}
|
||||||
template<typename T> T AttrTo(v8::Handle<v8::Object> obj, int attr) {
|
template<typename T> T AttrTo(v8::Local<v8::Object> obj, int attr) {
|
||||||
return Nan::To<T>(Nan::Get(obj, attr).ToLocalChecked()).FromJust();
|
return Nan::To<T>(Nan::Get(obj, attr).ToLocalChecked()).FromJust();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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::Local<v8::Object> input, std::vector<v8::Local<v8::Object>> &buffersToPersist);
|
||||||
|
|
||||||
enum class ImageType {
|
enum class ImageType {
|
||||||
JPEG,
|
JPEG,
|
||||||
@@ -99,6 +101,7 @@ namespace sharp {
|
|||||||
TIFF,
|
TIFF,
|
||||||
GIF,
|
GIF,
|
||||||
SVG,
|
SVG,
|
||||||
|
HEIF,
|
||||||
PDF,
|
PDF,
|
||||||
MAGICK,
|
MAGICK,
|
||||||
OPENSLIDE,
|
OPENSLIDE,
|
||||||
@@ -106,7 +109,8 @@ namespace sharp {
|
|||||||
FITS,
|
FITS,
|
||||||
VIPS,
|
VIPS,
|
||||||
RAW,
|
RAW,
|
||||||
UNKNOWN
|
UNKNOWN,
|
||||||
|
MISSING
|
||||||
};
|
};
|
||||||
|
|
||||||
// How many tasks are in the queue?
|
// How many tasks are in the queue?
|
||||||
@@ -120,6 +124,9 @@ namespace sharp {
|
|||||||
bool IsPng(std::string const &str);
|
bool IsPng(std::string const &str);
|
||||||
bool IsWebp(std::string const &str);
|
bool IsWebp(std::string const &str);
|
||||||
bool IsTiff(std::string const &str);
|
bool IsTiff(std::string const &str);
|
||||||
|
bool IsHeic(std::string const &str);
|
||||||
|
bool IsHeif(std::string const &str);
|
||||||
|
bool IsAvif(std::string const &str);
|
||||||
bool IsDz(std::string const &str);
|
bool IsDz(std::string const &str);
|
||||||
bool IsDzZip(std::string const &str);
|
bool IsDzZip(std::string const &str);
|
||||||
bool IsV(std::string const &str);
|
bool IsV(std::string const &str);
|
||||||
@@ -139,6 +146,11 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
ImageType DetermineImageType(char const *file);
|
ImageType DetermineImageType(char const *file);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Does this image type support multiple pages?
|
||||||
|
*/
|
||||||
|
bool ImageTypeSupportsPage(ImageType imageType);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
|
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,8 +32,6 @@
|
|||||||
#endif /*HAVE_CONFIG_H*/
|
#endif /*HAVE_CONFIG_H*/
|
||||||
#include <vips/intl.h>
|
#include <vips/intl.h>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
|
|
||||||
VIPS_NAMESPACE_START
|
VIPS_NAMESPACE_START
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ VImage::new_from_file( const char *name, VOption *options )
|
|||||||
}
|
}
|
||||||
|
|
||||||
VImage
|
VImage
|
||||||
VImage::new_from_buffer( void *buf, size_t len, const char *option_string,
|
VImage::new_from_buffer( const void *buf, size_t len, const char *option_string,
|
||||||
VOption *options )
|
VOption *options )
|
||||||
{
|
{
|
||||||
const char *operation_name;
|
const char *operation_name;
|
||||||
@@ -588,6 +588,13 @@ VImage::new_from_buffer( void *buf, size_t len, const char *option_string,
|
|||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VImage
|
||||||
|
VImage::new_from_buffer( const std::string &buf, const char *option_string,
|
||||||
|
VOption *options )
|
||||||
|
{
|
||||||
|
return( new_from_buffer( buf.c_str(), buf.size(), option_string, options ) );
|
||||||
|
}
|
||||||
|
|
||||||
VImage
|
VImage
|
||||||
VImage::new_matrix( int width, int height )
|
VImage::new_matrix( int width, int height )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -68,6 +68,18 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
||||||
baton->isProgressive = image.get_int("interlaced") == 1;
|
baton->isProgressive = image.get_int("interlaced") == 1;
|
||||||
}
|
}
|
||||||
|
if (image.get_typeof("palette-bit-depth") == G_TYPE_INT) {
|
||||||
|
baton->paletteBitDepth = image.get_int("palette-bit-depth");
|
||||||
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
||||||
|
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
||||||
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_PAGE_HEIGHT) == G_TYPE_INT) {
|
||||||
|
baton->pageHeight = image.get_int(VIPS_META_PAGE_HEIGHT);
|
||||||
|
}
|
||||||
|
if (image.get_typeof("heif-primary") == G_TYPE_INT) {
|
||||||
|
baton->pagePrimary = image.get_int("heif-primary");
|
||||||
|
}
|
||||||
baton->hasProfile = sharp::HasProfile(image);
|
baton->hasProfile = sharp::HasProfile(image);
|
||||||
// Derived attributes
|
// Derived attributes
|
||||||
baton->hasAlpha = sharp::HasAlpha(image);
|
baton->hasAlpha = sharp::HasAlpha(image);
|
||||||
@@ -140,6 +152,18 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
New<v8::String>(baton->chromaSubsampling).ToLocalChecked());
|
New<v8::String>(baton->chromaSubsampling).ToLocalChecked());
|
||||||
}
|
}
|
||||||
Set(info, New("isProgressive").ToLocalChecked(), New<v8::Boolean>(baton->isProgressive));
|
Set(info, New("isProgressive").ToLocalChecked(), New<v8::Boolean>(baton->isProgressive));
|
||||||
|
if (baton->paletteBitDepth > 0) {
|
||||||
|
Set(info, New("paletteBitDepth").ToLocalChecked(), New<v8::Uint32>(baton->paletteBitDepth));
|
||||||
|
}
|
||||||
|
if (baton->pages > 0) {
|
||||||
|
Set(info, New("pages").ToLocalChecked(), New<v8::Uint32>(baton->pages));
|
||||||
|
}
|
||||||
|
if (baton->pageHeight > 0) {
|
||||||
|
Set(info, New("pageHeight").ToLocalChecked(), New<v8::Uint32>(baton->pageHeight));
|
||||||
|
}
|
||||||
|
if (baton->pagePrimary > -1) {
|
||||||
|
Set(info, New("pagePrimary").ToLocalChecked(), New<v8::Uint32>(baton->pagePrimary));
|
||||||
|
}
|
||||||
Set(info, New("hasProfile").ToLocalChecked(), New<v8::Boolean>(baton->hasProfile));
|
Set(info, New("hasProfile").ToLocalChecked(), New<v8::Boolean>(baton->hasProfile));
|
||||||
Set(info, New("hasAlpha").ToLocalChecked(), New<v8::Boolean>(baton->hasAlpha));
|
Set(info, New("hasAlpha").ToLocalChecked(), New<v8::Boolean>(baton->hasAlpha));
|
||||||
if (baton->orientation > 0) {
|
if (baton->orientation > 0) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -33,6 +33,10 @@ struct MetadataBaton {
|
|||||||
int density;
|
int density;
|
||||||
std::string chromaSubsampling;
|
std::string chromaSubsampling;
|
||||||
bool isProgressive;
|
bool isProgressive;
|
||||||
|
int paletteBitDepth;
|
||||||
|
int pages;
|
||||||
|
int pageHeight;
|
||||||
|
int pagePrimary;
|
||||||
bool hasProfile;
|
bool hasProfile;
|
||||||
bool hasAlpha;
|
bool hasAlpha;
|
||||||
int orientation;
|
int orientation;
|
||||||
@@ -53,6 +57,10 @@ struct MetadataBaton {
|
|||||||
channels(0),
|
channels(0),
|
||||||
density(0),
|
density(0),
|
||||||
isProgressive(false),
|
isProgressive(false),
|
||||||
|
paletteBitDepth(0),
|
||||||
|
pages(0),
|
||||||
|
pageHeight(0),
|
||||||
|
pagePrimary(-1),
|
||||||
hasProfile(false),
|
hasProfile(false),
|
||||||
hasAlpha(false),
|
hasAlpha(false),
|
||||||
orientation(0),
|
orientation(0),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -39,127 +39,15 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Composite overlayImage over image at given position
|
Ensures alpha channel, if missing.
|
||||||
Assumes alpha channels are already premultiplied and will be unpremultiplied after
|
*/
|
||||||
*/
|
VImage EnsureAlpha(VImage image) {
|
||||||
VImage Composite(VImage image, VImage overlayImage, int const left, int const top) {
|
if (!HasAlpha(image)) {
|
||||||
if (HasAlpha(overlayImage)) {
|
std::vector<double> alpha;
|
||||||
// Alpha composite
|
alpha.push_back(sharp::MaximumImageAlpha(image.interpretation()));
|
||||||
if (overlayImage.width() < image.width() || overlayImage.height() < image.height()) {
|
image = image.bandjoin_const(alpha);
|
||||||
// Enlarge overlay
|
|
||||||
std::vector<double> const background { 0.0, 0.0, 0.0, 0.0 };
|
|
||||||
overlayImage = overlayImage.embed(left, top, image.width(), image.height(), VImage::option()
|
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
|
||||||
->set("background", background));
|
|
||||||
}
|
|
||||||
return AlphaComposite(image, overlayImage);
|
|
||||||
} else {
|
|
||||||
if (HasAlpha(image)) {
|
|
||||||
// Add alpha channel to overlayImage so channels match
|
|
||||||
double const multiplier = sharp::Is16Bit(overlayImage.interpretation()) ? 256.0 : 1.0;
|
|
||||||
overlayImage = overlayImage.bandjoin(
|
|
||||||
VImage::new_matrix(overlayImage.width(), overlayImage.height()).new_from_image(255 * multiplier));
|
|
||||||
}
|
|
||||||
return image.insert(overlayImage, left, top);
|
|
||||||
}
|
}
|
||||||
}
|
return image;
|
||||||
|
|
||||||
VImage AlphaComposite(VImage dst, VImage src) {
|
|
||||||
// Split src into non-alpha and alpha channels
|
|
||||||
VImage srcWithoutAlpha = src.extract_band(0, VImage::option()->set("n", src.bands() - 1));
|
|
||||||
VImage srcAlpha = src[src.bands() - 1] * (1.0 / 255.0);
|
|
||||||
|
|
||||||
// Split dst into non-alpha and alpha channels
|
|
||||||
VImage dstWithoutAlpha = dst.extract_band(0, VImage::option()->set("n", dst.bands() - 1));
|
|
||||||
VImage dstAlpha = dst[dst.bands() - 1] * (1.0 / 255.0);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Compute normalized output alpha channel:
|
|
||||||
//
|
|
||||||
// References:
|
|
||||||
// - http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
|
|
||||||
// - https://github.com/libvips/ruby-vips/issues/28#issuecomment-9014826
|
|
||||||
//
|
|
||||||
// out_a = src_a + dst_a * (1 - src_a)
|
|
||||||
// ^^^^^^^^^^^
|
|
||||||
// t0
|
|
||||||
VImage t0 = srcAlpha.linear(-1.0, 1.0);
|
|
||||||
VImage outAlphaNormalized = srcAlpha + dstAlpha * t0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Compute output RGB channels:
|
|
||||||
//
|
|
||||||
// Wikipedia:
|
|
||||||
// out_rgb = (src_rgb * src_a + dst_rgb * dst_a * (1 - src_a)) / out_a
|
|
||||||
// ^^^^^^^^^^^
|
|
||||||
// t0
|
|
||||||
//
|
|
||||||
// Omit division by `out_a` since `Compose` is supposed to output a
|
|
||||||
// premultiplied RGBA image as reversal of premultiplication is handled
|
|
||||||
// externally.
|
|
||||||
//
|
|
||||||
VImage outRGBPremultiplied = srcWithoutAlpha + dstWithoutAlpha * t0;
|
|
||||||
|
|
||||||
// Combine RGB and alpha channel into output image:
|
|
||||||
return outRGBPremultiplied.bandjoin(outAlphaNormalized * 255.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Cutout src over dst with given gravity.
|
|
||||||
*/
|
|
||||||
VImage Cutout(VImage mask, VImage dst, const int gravity) {
|
|
||||||
using sharp::CalculateCrop;
|
|
||||||
using sharp::HasAlpha;
|
|
||||||
using sharp::MaximumImageAlpha;
|
|
||||||
|
|
||||||
bool maskHasAlpha = HasAlpha(mask);
|
|
||||||
|
|
||||||
if (!maskHasAlpha && mask.bands() > 1) {
|
|
||||||
throw VError("Overlay image must have an alpha channel or one band");
|
|
||||||
}
|
|
||||||
if (!HasAlpha(dst)) {
|
|
||||||
throw VError("Image to be overlaid must have an alpha channel");
|
|
||||||
}
|
|
||||||
if (mask.width() > dst.width() || mask.height() > dst.height()) {
|
|
||||||
throw VError("Overlay image must have same dimensions or smaller");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enlarge overlay mask, if required
|
|
||||||
if (mask.width() < dst.width() || mask.height() < dst.height()) {
|
|
||||||
// Calculate the (left, top) coordinates of the output image within the input image, applying the given gravity.
|
|
||||||
int left;
|
|
||||||
int top;
|
|
||||||
std::tie(left, top) = CalculateCrop(dst.width(), dst.height(), mask.width(), mask.height(), gravity);
|
|
||||||
// Embed onto transparent background
|
|
||||||
std::vector<double> background { 0.0, 0.0, 0.0, 0.0 };
|
|
||||||
mask = mask.embed(left, top, dst.width(), dst.height(), VImage::option()
|
|
||||||
->set("extend", VIPS_EXTEND_BACKGROUND)
|
|
||||||
->set("background", background));
|
|
||||||
}
|
|
||||||
|
|
||||||
// we use the mask alpha if it has alpha
|
|
||||||
if (maskHasAlpha) {
|
|
||||||
mask = mask.extract_band(mask.bands() - 1, VImage::option()->set("n", 1));;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split dst into an optional alpha
|
|
||||||
VImage dstAlpha = dst.extract_band(dst.bands() - 1, VImage::option()->set("n", 1));
|
|
||||||
|
|
||||||
// we use the dst non-alpha
|
|
||||||
dst = dst.extract_band(0, VImage::option()->set("n", dst.bands() - 1));
|
|
||||||
|
|
||||||
// the range of the mask and the image need to match .. one could be
|
|
||||||
// 16-bit, one 8-bit
|
|
||||||
double const dstMax = MaximumImageAlpha(dst.interpretation());
|
|
||||||
double const maskMax = MaximumImageAlpha(mask.interpretation());
|
|
||||||
|
|
||||||
// combine the new mask and the existing alpha ... there are
|
|
||||||
// many ways of doing this, mult is the simplest
|
|
||||||
mask = dstMax * ((mask / maskMax) * (dstAlpha / dstMax));
|
|
||||||
|
|
||||||
// append the mask to the image data ... the mask might be float now,
|
|
||||||
// we must cast the format down to match the image data
|
|
||||||
return dst.bandjoin(mask.cast(dst.format()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -278,6 +166,40 @@ namespace sharp {
|
|||||||
return image.conv(kernel);
|
return image.conv(kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Recomb with a Matrix of the given bands/channel size.
|
||||||
|
* Eg. RGB will be a 3x3 matrix.
|
||||||
|
*/
|
||||||
|
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix) {
|
||||||
|
double *m = matrix.get();
|
||||||
|
return image
|
||||||
|
.colourspace(VIPS_INTERPRETATION_sRGB)
|
||||||
|
.recomb(image.bands() == 3
|
||||||
|
? VImage::new_from_memory(
|
||||||
|
m, 9 * sizeof(double), 3, 3, 1, VIPS_FORMAT_DOUBLE
|
||||||
|
)
|
||||||
|
: VImage::new_matrixv(4, 4,
|
||||||
|
m[0], m[1], m[2], 0.0,
|
||||||
|
m[3], m[4], m[5], 0.0,
|
||||||
|
m[6], m[7], m[8], 0.0,
|
||||||
|
0.0, 0.0, 0.0, 1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
VImage Modulate(VImage image, double const brightness, double const saturation, int const hue) {
|
||||||
|
if (HasAlpha(image)) {
|
||||||
|
// Separate alpha channel
|
||||||
|
VImage alpha = image[image.bands() - 1];
|
||||||
|
return RemoveAlpha(image)
|
||||||
|
.colourspace(VIPS_INTERPRETATION_LCH)
|
||||||
|
.linear({brightness, saturation, 1}, {0, 0, static_cast<double>(hue)})
|
||||||
|
.bandjoin(alpha);
|
||||||
|
} else {
|
||||||
|
return image
|
||||||
|
.colourspace(VIPS_INTERPRETATION_LCH)
|
||||||
|
.linear({brightness, saturation, 1}, {0, 0, static_cast<double>(hue)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
||||||
*/
|
*/
|
||||||
@@ -328,6 +250,9 @@ namespace sharp {
|
|||||||
Trim an image
|
Trim an image
|
||||||
*/
|
*/
|
||||||
VImage Trim(VImage image, double const threshold) {
|
VImage Trim(VImage image, double const threshold) {
|
||||||
|
if (image.width() < 3 && image.height() < 3) {
|
||||||
|
throw VError("Image to trim must be at least 3x3 pixels");
|
||||||
|
}
|
||||||
// Top-left pixel provides the background colour
|
// Top-left pixel provides the background colour
|
||||||
VImage background = image.extract_area(0, 0, 1, 1);
|
VImage background = image.extract_area(0, 0, 1, 1);
|
||||||
if (HasAlpha(background)) {
|
if (HasAlpha(background)) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -31,25 +31,9 @@ namespace sharp {
|
|||||||
VImage RemoveAlpha(VImage image);
|
VImage RemoveAlpha(VImage image);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Alpha composite src over dst with given gravity.
|
Ensures alpha channel, if missing.
|
||||||
Assumes alpha channels are already premultiplied and will be unpremultiplied after.
|
|
||||||
*/
|
|
||||||
VImage Composite(VImage src, VImage dst, const int gravity);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Composite overlayImage over image at given position
|
|
||||||
*/
|
|
||||||
VImage Composite(VImage image, VImage overlayImage, int const x, int const y);
|
|
||||||
|
|
||||||
/*
|
|
||||||
Alpha composite overlayImage over image, assumes matching dimensions
|
|
||||||
*/
|
*/
|
||||||
VImage AlphaComposite(VImage image, VImage overlayImage);
|
VImage EnsureAlpha(VImage image);
|
||||||
|
|
||||||
/*
|
|
||||||
Cutout src over dst with given gravity.
|
|
||||||
*/
|
|
||||||
VImage Cutout(VImage src, VImage dst, const int gravity);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tint an image using the specified chroma, preserving the original image luminance
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
@@ -107,6 +91,17 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Linear(VImage image, double const a, double const b);
|
VImage Linear(VImage image, double const a, double const b);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Recomb with a Matrix of the given bands/channel size.
|
||||||
|
* Eg. RGB will be a 3x3 matrix.
|
||||||
|
*/
|
||||||
|
VImage Recomb(VImage image, std::unique_ptr<double[]> const &matrix);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modulate brightness, saturation and hue
|
||||||
|
*/
|
||||||
|
VImage Modulate(VImage image, double const brightness, double const saturation, int const hue);
|
||||||
|
|
||||||
} // namespace sharp
|
} // namespace sharp
|
||||||
|
|
||||||
#endif // SRC_OPERATIONS_H_
|
#endif // SRC_OPERATIONS_H_
|
||||||
|
|||||||
373
src/pipeline.cc
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <vips/vips8>
|
#include <vips/vips8>
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
@@ -30,6 +32,17 @@
|
|||||||
#include "operations.h"
|
#include "operations.h"
|
||||||
#include "pipeline.h"
|
#include "pipeline.h"
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
#define STAT64_STRUCT __stat64
|
||||||
|
#define STAT64_FUNCTION _stat64
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#define STAT64_STRUCT stat
|
||||||
|
#define STAT64_FUNCTION stat
|
||||||
|
#else
|
||||||
|
#define STAT64_STRUCT stat64
|
||||||
|
#define STAT64_FUNCTION stat64
|
||||||
|
#endif
|
||||||
|
|
||||||
class PipelineWorker : public Nan::AsyncWorker {
|
class PipelineWorker : public Nan::AsyncWorker {
|
||||||
public:
|
public:
|
||||||
PipelineWorker(
|
PipelineWorker(
|
||||||
@@ -57,16 +70,6 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Increment processing task counter
|
// Increment processing task counter
|
||||||
g_atomic_int_inc(&sharp::counterProcess);
|
g_atomic_int_inc(&sharp::counterProcess);
|
||||||
|
|
||||||
std::map<VipsInterpretation, std::string> profileMap;
|
|
||||||
// Default sRGB ICC profile from https://packages.debian.org/sid/all/icc-profiles-free/filelist
|
|
||||||
profileMap.insert(
|
|
||||||
std::pair<VipsInterpretation, std::string>(VIPS_INTERPRETATION_sRGB,
|
|
||||||
baton->iccProfilePath + "sRGB.icc"));
|
|
||||||
// Convert to sRGB using default CMYK profile from http://www.argyllcms.com/cmyk.icm
|
|
||||||
profileMap.insert(
|
|
||||||
std::pair<VipsInterpretation, std::string>(VIPS_INTERPRETATION_CMYK,
|
|
||||||
baton->iccProfilePath + "cmyk.icm"));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Open input
|
// Open input
|
||||||
vips::VImage image;
|
vips::VImage image;
|
||||||
@@ -75,7 +78,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
|
|
||||||
// Limit input images to a given number of pixels, where pixels = width * height
|
// Limit input images to a given number of pixels, where pixels = width * height
|
||||||
// Ignore if 0
|
// Ignore if 0
|
||||||
if (baton->limitInputPixels > 0 && image.width() * image.height() > baton->limitInputPixels) {
|
if (baton->limitInputPixels > 0 &&
|
||||||
|
static_cast<uint64_t>(image.width() * image.height()) > static_cast<uint64_t>(baton->limitInputPixels)) {
|
||||||
(baton->err).append("Input image exceeds pixel limit");
|
(baton->err).append("Input image exceeds pixel limit");
|
||||||
return Error();
|
return Error();
|
||||||
}
|
}
|
||||||
@@ -94,9 +98,16 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rotate pre-extract
|
// Rotate pre-extract
|
||||||
if (baton->rotateBeforePreExtract && rotation != VIPS_ANGLE_D0) {
|
if (baton->rotateBeforePreExtract) {
|
||||||
image = image.rot(rotation);
|
if (rotation != VIPS_ANGLE_D0) {
|
||||||
sharp::RemoveExifOrientation(image);
|
image = image.rot(rotation);
|
||||||
|
sharp::RemoveExifOrientation(image);
|
||||||
|
}
|
||||||
|
if (baton->rotationAngle != 0.0) {
|
||||||
|
std::vector<double> background;
|
||||||
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground);
|
||||||
|
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim
|
// Trim
|
||||||
@@ -297,20 +308,18 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we're using a device-independent colour space
|
// Ensure we're using a device-independent colour space
|
||||||
if (sharp::HasProfile(image)) {
|
if (sharp::HasProfile(image) && image.interpretation() != VIPS_INTERPRETATION_LABS) {
|
||||||
// Convert to sRGB using embedded profile
|
// Convert to sRGB using embedded profile
|
||||||
try {
|
try {
|
||||||
image = image.icc_transform(
|
image = image.icc_transform("srgb", VImage::option()
|
||||||
const_cast<char*>(profileMap[VIPS_INTERPRETATION_sRGB].data()), VImage::option()
|
|
||||||
->set("embedded", TRUE)
|
->set("embedded", TRUE)
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
// Ignore failure of embedded profile
|
// Ignore failure of embedded profile
|
||||||
}
|
}
|
||||||
} else if (image.interpretation() == VIPS_INTERPRETATION_CMYK) {
|
} else if (image.interpretation() == VIPS_INTERPRETATION_CMYK) {
|
||||||
image = image.icc_transform(
|
image = image.icc_transform("srgb", VImage::option()
|
||||||
const_cast<char*>(profileMap[VIPS_INTERPRETATION_sRGB].data()), VImage::option()
|
->set("input_profile", "cmyk")
|
||||||
->set("input_profile", profileMap[VIPS_INTERPRETATION_CMYK].data())
|
|
||||||
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,30 +352,20 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.colourspace(VIPS_INTERPRETATION_B_W);
|
image = image.colourspace(VIPS_INTERPRETATION_B_W);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure image has an alpha channel when there is an overlay with an alpha channel
|
|
||||||
VImage overlayImage;
|
|
||||||
ImageType overlayImageType = ImageType::UNKNOWN;
|
|
||||||
bool shouldOverlayWithAlpha = FALSE;
|
|
||||||
if (baton->overlay != nullptr) {
|
|
||||||
std::tie(overlayImage, overlayImageType) = OpenInput(baton->overlay, baton->accessMethod);
|
|
||||||
if (HasAlpha(overlayImage)) {
|
|
||||||
shouldOverlayWithAlpha = !baton->overlayCutout;
|
|
||||||
if (!HasAlpha(image)) {
|
|
||||||
double const multiplier = sharp::Is16Bit(image.interpretation()) ? 256.0 : 1.0;
|
|
||||||
image = image.bandjoin(
|
|
||||||
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool const shouldResize = xfactor != 1.0 || yfactor != 1.0;
|
bool const shouldResize = xfactor != 1.0 || yfactor != 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 shouldApplyMedian = baton->medianSize > 0;
|
||||||
|
bool const shouldComposite = !baton->composite.empty();
|
||||||
|
bool const shouldModulate = baton->brightness != 1.0 || baton->saturation != 1.0 || baton->hue != 0.0;
|
||||||
|
|
||||||
|
if (shouldComposite && !HasAlpha(image)) {
|
||||||
|
image = sharp::EnsureAlpha(image);
|
||||||
|
}
|
||||||
|
|
||||||
bool const shouldPremultiplyAlpha = HasAlpha(image) &&
|
bool const shouldPremultiplyAlpha = HasAlpha(image) &&
|
||||||
(shouldResize || shouldBlur || shouldConv || shouldSharpen || shouldOverlayWithAlpha);
|
(shouldResize || shouldBlur || shouldConv || shouldSharpen || shouldComposite);
|
||||||
|
|
||||||
// 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
|
||||||
@@ -381,21 +380,31 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data()));
|
vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data()));
|
||||||
if (
|
if (
|
||||||
kernel != VIPS_KERNEL_NEAREST && kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 &&
|
kernel != VIPS_KERNEL_NEAREST && kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 &&
|
||||||
kernel != VIPS_KERNEL_LANCZOS3
|
kernel != VIPS_KERNEL_LANCZOS3 && kernel != VIPS_KERNEL_MITCHELL
|
||||||
) {
|
) {
|
||||||
throw vips::VError("Unknown kernel");
|
throw vips::VError("Unknown kernel");
|
||||||
}
|
}
|
||||||
|
// Ensure shortest edge is at least 1 pixel
|
||||||
|
if (image.width() / xfactor < 0.5) {
|
||||||
|
xfactor = 2 * image.width();
|
||||||
|
baton->width = 1;
|
||||||
|
}
|
||||||
|
if (image.height() / yfactor < 0.5) {
|
||||||
|
yfactor = 2 * image.height();
|
||||||
|
baton->height = 1;
|
||||||
|
}
|
||||||
image = image.resize(1.0 / xfactor, VImage::option()
|
image = image.resize(1.0 / xfactor, VImage::option()
|
||||||
->set("vscale", 1.0 / yfactor)
|
->set("vscale", 1.0 / yfactor)
|
||||||
->set("kernel", kernel));
|
->set("kernel", kernel));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate
|
// Rotate post-extract 90-angle
|
||||||
if (!baton->rotateBeforePreExtract && rotation != VIPS_ANGLE_D0) {
|
if (!baton->rotateBeforePreExtract && rotation != VIPS_ANGLE_D0) {
|
||||||
image = image.rot(rotation);
|
image = image.rot(rotation);
|
||||||
sharp::RemoveExifOrientation(image);
|
sharp::RemoveExifOrientation(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Flip (mirror about Y axis)
|
// Flip (mirror about Y axis)
|
||||||
if (baton->flip) {
|
if (baton->flip) {
|
||||||
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
||||||
@@ -478,8 +487,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate by degree
|
// Rotate post-extract non-90 angle
|
||||||
if (baton->rotationAngle != 0.0) {
|
if (!baton->rotateBeforePreExtract && baton->rotationAngle != 0.0) {
|
||||||
std::vector<double> background;
|
std::vector<double> background;
|
||||||
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground);
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground);
|
||||||
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background));
|
image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background));
|
||||||
@@ -525,77 +534,81 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
baton->convKernel);
|
baton->convKernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recomb
|
||||||
|
if (baton->recombMatrix != NULL) {
|
||||||
|
image = sharp::Recomb(image, baton->recombMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldModulate) {
|
||||||
|
image = sharp::Modulate(image, baton->brightness, baton->saturation, baton->hue);
|
||||||
|
}
|
||||||
|
|
||||||
// Sharpen
|
// Sharpen
|
||||||
if (shouldSharpen) {
|
if (shouldSharpen) {
|
||||||
image = sharp::Sharpen(image, baton->sharpenSigma, baton->sharpenFlat, baton->sharpenJagged);
|
image = sharp::Sharpen(image, baton->sharpenSigma, baton->sharpenFlat, baton->sharpenJagged);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Composite with overlay, if present
|
// Composite
|
||||||
if (baton->overlay != nullptr) {
|
if (shouldComposite) {
|
||||||
// Verify overlay image is within current dimensions
|
for (Composite *composite : baton->composite) {
|
||||||
if (overlayImage.width() > image.width() || overlayImage.height() > image.height()) {
|
VImage compositeImage;
|
||||||
throw vips::VError("Overlay image must have same dimensions or smaller");
|
ImageType compositeImageType = ImageType::UNKNOWN;
|
||||||
}
|
std::tie(compositeImage, compositeImageType) = OpenInput(composite->input, baton->accessMethod);
|
||||||
// Check if overlay is tiled
|
// Verify within current dimensions
|
||||||
if (baton->overlayTile) {
|
if (compositeImage.width() > image.width() || compositeImage.height() > image.height()) {
|
||||||
int const overlayImageWidth = overlayImage.width();
|
throw vips::VError("Image to composite must have same dimensions or smaller");
|
||||||
int const overlayImageHeight = overlayImage.height();
|
|
||||||
int across = 0;
|
|
||||||
int down = 0;
|
|
||||||
// Use gravity in overlay
|
|
||||||
if (overlayImageWidth <= baton->width) {
|
|
||||||
across = static_cast<int>(ceil(static_cast<double>(image.width()) / overlayImageWidth));
|
|
||||||
}
|
}
|
||||||
if (overlayImageHeight <= baton->height) {
|
// Check if overlay is tiled
|
||||||
down = static_cast<int>(ceil(static_cast<double>(image.height()) / overlayImageHeight));
|
if (composite->tile) {
|
||||||
}
|
int across = 0;
|
||||||
if (across != 0 || down != 0) {
|
int down = 0;
|
||||||
int left;
|
// Use gravity in overlay
|
||||||
int top;
|
if (compositeImage.width() <= baton->width) {
|
||||||
overlayImage = overlayImage.replicate(across, down);
|
across = static_cast<int>(ceil(static_cast<double>(image.width()) / compositeImage.width()));
|
||||||
if (baton->overlayXOffset >= 0 && baton->overlayYOffset >= 0) {
|
|
||||||
// the overlayX/YOffsets will now be used to CalculateCrop for extract_area
|
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
|
||||||
overlayImage.width(), overlayImage.height(), image.width(), image.height(),
|
|
||||||
baton->overlayXOffset, baton->overlayYOffset);
|
|
||||||
} else {
|
|
||||||
// the overlayGravity will now be used to CalculateCrop for extract_area
|
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
|
||||||
overlayImage.width(), overlayImage.height(), image.width(), image.height(), baton->overlayGravity);
|
|
||||||
}
|
}
|
||||||
overlayImage = overlayImage.extract_area(left, top, image.width(), image.height());
|
if (compositeImage.height() <= baton->height) {
|
||||||
}
|
down = static_cast<int>(ceil(static_cast<double>(image.height()) / compositeImage.height()));
|
||||||
// the overlayGravity was used for extract_area, therefore set it back to its default value of 0
|
|
||||||
baton->overlayGravity = 0;
|
|
||||||
}
|
|
||||||
if (baton->overlayCutout) {
|
|
||||||
// 'cut out' the image, premultiplication is not required
|
|
||||||
image = sharp::Cutout(overlayImage, image, baton->overlayGravity);
|
|
||||||
} else {
|
|
||||||
// Ensure overlay is sRGB
|
|
||||||
overlayImage = overlayImage.colourspace(VIPS_INTERPRETATION_sRGB);
|
|
||||||
// Ensure overlay matches premultiplication state
|
|
||||||
if (shouldPremultiplyAlpha) {
|
|
||||||
// Ensure overlay has alpha channel
|
|
||||||
if (!HasAlpha(overlayImage)) {
|
|
||||||
double const multiplier = sharp::Is16Bit(overlayImage.interpretation()) ? 256.0 : 1.0;
|
|
||||||
overlayImage = overlayImage.bandjoin(
|
|
||||||
VImage::new_matrix(overlayImage.width(), overlayImage.height()).new_from_image(255 * multiplier));
|
|
||||||
}
|
}
|
||||||
overlayImage = overlayImage.premultiply();
|
if (across != 0 || down != 0) {
|
||||||
|
int left;
|
||||||
|
int top;
|
||||||
|
compositeImage = compositeImage.replicate(across, down);
|
||||||
|
if (composite->left >= 0 && composite->top >= 0) {
|
||||||
|
std::tie(left, top) = sharp::CalculateCrop(
|
||||||
|
compositeImage.width(), compositeImage.height(), image.width(), image.height(),
|
||||||
|
composite->left, composite->top);
|
||||||
|
} else {
|
||||||
|
std::tie(left, top) = sharp::CalculateCrop(
|
||||||
|
compositeImage.width(), compositeImage.height(), image.width(), image.height(), composite->gravity);
|
||||||
|
}
|
||||||
|
compositeImage = compositeImage.extract_area(left, top, image.width(), image.height());
|
||||||
|
}
|
||||||
|
// gravity was used for extract_area, set it back to its default value of 0
|
||||||
|
composite->gravity = 0;
|
||||||
}
|
}
|
||||||
|
// Ensure image to composite is sRGB with premultiplied alpha
|
||||||
|
compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
|
if (!HasAlpha(compositeImage)) {
|
||||||
|
compositeImage = sharp::EnsureAlpha(compositeImage);
|
||||||
|
}
|
||||||
|
if (!composite->premultiplied) compositeImage = compositeImage.premultiply();
|
||||||
|
// Calculate position
|
||||||
int left;
|
int left;
|
||||||
int top;
|
int top;
|
||||||
if (baton->overlayXOffset >= 0 && baton->overlayYOffset >= 0) {
|
if (composite->left >= 0 && composite->top >= 0) {
|
||||||
// Composite images at given offsets
|
// Composite image at given offsets
|
||||||
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
||||||
overlayImage.width(), overlayImage.height(), baton->overlayXOffset, baton->overlayYOffset);
|
compositeImage.width(), compositeImage.height(), composite->left, composite->top);
|
||||||
} else {
|
} else {
|
||||||
// Composite images with given gravity
|
// Composite image with given gravity
|
||||||
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
||||||
overlayImage.width(), overlayImage.height(), baton->overlayGravity);
|
compositeImage.width(), compositeImage.height(), composite->gravity);
|
||||||
}
|
}
|
||||||
image = sharp::Composite(image, overlayImage, left, top);
|
// Composite
|
||||||
|
image = image.composite2(compositeImage, composite->mode, VImage::option()
|
||||||
|
->set("premultiplied", TRUE)
|
||||||
|
->set("x", left)
|
||||||
|
->set("y", top));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,8 +625,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
baton->premultiplied = shouldPremultiplyAlpha;
|
baton->premultiplied = shouldPremultiplyAlpha;
|
||||||
|
|
||||||
// Gamma decoding (brighten)
|
// Gamma decoding (brighten)
|
||||||
if (baton->gamma >= 1 && baton->gamma <= 3) {
|
if (baton->gammaOut >= 1 && baton->gammaOut <= 3) {
|
||||||
image = sharp::Gamma(image, baton->gamma);
|
image = sharp::Gamma(image, baton->gammaOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linear adjustment (a * in + b)
|
// Linear adjustment (a * in + b)
|
||||||
@@ -663,6 +676,11 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = sharp::RemoveAlpha(image);
|
image = sharp::RemoveAlpha(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure alpha channel, if missing
|
||||||
|
if (baton->ensureAlpha) {
|
||||||
|
image = sharp::EnsureAlpha(image);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert image to sRGB, if not already
|
// Convert image to sRGB, if not already
|
||||||
if (sharp::Is16Bit(image.interpretation())) {
|
if (sharp::Is16Bit(image.interpretation())) {
|
||||||
image = image.cast(VIPS_FORMAT_USHORT);
|
image = image.cast(VIPS_FORMAT_USHORT);
|
||||||
@@ -671,8 +689,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
// Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
|
||||||
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
||||||
// Transform colours from embedded profile to output profile
|
// Transform colours from embedded profile to output profile
|
||||||
if (baton->withMetadata && sharp::HasProfile(image) && profileMap[baton->colourspace] != std::string()) {
|
if (baton->withMetadata && sharp::HasProfile(image)) {
|
||||||
image = image.icc_transform(const_cast<char*>(profileMap[baton->colourspace].data()),
|
image = image.icc_transform(vips_enum_nick(VIPS_TYPE_INTERPRETATION, baton->colourspace),
|
||||||
VImage::option()->set("embedded", TRUE));
|
VImage::option()->set("embedded", TRUE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -716,14 +734,15 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
(inputImageType == ImageType::PNG || inputImageType == ImageType::GIF || inputImageType == ImageType::SVG))) {
|
(inputImageType == ImageType::PNG || inputImageType == ImageType::GIF || inputImageType == ImageType::SVG))) {
|
||||||
// Write PNG to buffer
|
// Write PNG to buffer
|
||||||
sharp::AssertImageTypeDimensions(image, ImageType::PNG);
|
sharp::AssertImageTypeDimensions(image, ImageType::PNG);
|
||||||
// Strip profile
|
|
||||||
if (!baton->withMetadata) {
|
|
||||||
vips_image_remove(image.get_image(), VIPS_META_ICC_NAME);
|
|
||||||
}
|
|
||||||
VipsArea *area = VIPS_AREA(image.pngsave_buffer(VImage::option()
|
VipsArea *area = VIPS_AREA(image.pngsave_buffer(VImage::option()
|
||||||
|
->set("strip", !baton->withMetadata)
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)));
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
|
||||||
|
->set("palette", baton->pngPalette)
|
||||||
|
->set("Q", baton->pngQuality)
|
||||||
|
->set("colours", baton->pngColours)
|
||||||
|
->set("dither", baton->pngDither)));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
@@ -737,6 +756,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
|
->set("smart_subsample", baton->webpSmartSubsample)
|
||||||
|
->set("reduction_effort", baton->webpReductionEffort)
|
||||||
->set("alpha_q", baton->webpAlphaQuality)));
|
->set("alpha_q", baton->webpAlphaQuality)));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
@@ -758,6 +779,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("squash", baton->tiffSquash)
|
->set("squash", baton->tiffSquash)
|
||||||
->set("compression", baton->tiffCompression)
|
->set("compression", baton->tiffCompression)
|
||||||
->set("predictor", baton->tiffPredictor)
|
->set("predictor", baton->tiffPredictor)
|
||||||
|
->set("pyramid", baton->tiffPyramid)
|
||||||
|
->set("tile", baton->tiffTile)
|
||||||
|
->set("tile_height", baton->tiffTileHeight)
|
||||||
|
->set("tile_width", baton->tiffTileWidth)
|
||||||
->set("xres", baton->tiffXres)
|
->set("xres", baton->tiffXres)
|
||||||
->set("yres", baton->tiffYres)));
|
->set("yres", baton->tiffYres)));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
@@ -766,11 +791,24 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
vips_area_unref(area);
|
vips_area_unref(area);
|
||||||
baton->formatOut = "tiff";
|
baton->formatOut = "tiff";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
|
} else if (baton->formatOut == "heif" || (baton->formatOut == "input" && inputImageType == ImageType::HEIF)) {
|
||||||
|
// Write HEIF to buffer
|
||||||
|
VipsArea *area = VIPS_AREA(image.heifsave_buffer(VImage::option()
|
||||||
|
->set("strip", !baton->withMetadata)
|
||||||
|
->set("compression", baton->heifCompression)
|
||||||
|
->set("Q", baton->heifQuality)
|
||||||
|
->set("lossless", baton->heifLossless)));
|
||||||
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
|
baton->bufferOutLength = area->length;
|
||||||
|
area->free_fn = nullptr;
|
||||||
|
vips_area_unref(area);
|
||||||
|
baton->formatOut = "heif";
|
||||||
} else if (baton->formatOut == "raw" || (baton->formatOut == "input" && inputImageType == ImageType::RAW)) {
|
} else if (baton->formatOut == "raw" || (baton->formatOut == "input" && inputImageType == ImageType::RAW)) {
|
||||||
// Write raw, uncompressed image data to buffer
|
// Write raw, uncompressed image data to buffer
|
||||||
if (baton->greyscale || image.interpretation() == VIPS_INTERPRETATION_B_W) {
|
if (baton->greyscale || image.interpretation() == VIPS_INTERPRETATION_B_W) {
|
||||||
// Extract first band for greyscale image
|
// Extract first band for greyscale image
|
||||||
image = image[0];
|
image = image[0];
|
||||||
|
baton->channels = 1;
|
||||||
}
|
}
|
||||||
if (image.format() != VIPS_FORMAT_UCHAR) {
|
if (image.format() != VIPS_FORMAT_UCHAR) {
|
||||||
// Cast pixels to uint8 (unsigned char)
|
// Cast pixels to uint8 (unsigned char)
|
||||||
@@ -799,6 +837,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
bool const isPng = sharp::IsPng(baton->fileOut);
|
bool const isPng = sharp::IsPng(baton->fileOut);
|
||||||
bool const isWebp = sharp::IsWebp(baton->fileOut);
|
bool const isWebp = sharp::IsWebp(baton->fileOut);
|
||||||
bool const isTiff = sharp::IsTiff(baton->fileOut);
|
bool const isTiff = sharp::IsTiff(baton->fileOut);
|
||||||
|
bool const isHeif = sharp::IsHeif(baton->fileOut);
|
||||||
bool const isDz = sharp::IsDz(baton->fileOut);
|
bool const isDz = sharp::IsDz(baton->fileOut);
|
||||||
bool const isDzZip = sharp::IsDzZip(baton->fileOut);
|
bool const isDzZip = sharp::IsDzZip(baton->fileOut);
|
||||||
bool const isV = sharp::IsV(baton->fileOut);
|
bool const isV = sharp::IsV(baton->fileOut);
|
||||||
@@ -824,14 +863,15 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
(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);
|
||||||
// Strip profile
|
|
||||||
if (!baton->withMetadata) {
|
|
||||||
vips_image_remove(image.get_image(), VIPS_META_ICC_NAME);
|
|
||||||
}
|
|
||||||
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
image.pngsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
|
->set("strip", !baton->withMetadata)
|
||||||
->set("interlace", baton->pngProgressive)
|
->set("interlace", baton->pngProgressive)
|
||||||
->set("compression", baton->pngCompressionLevel)
|
->set("compression", baton->pngCompressionLevel)
|
||||||
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE));
|
->set("filter", baton->pngAdaptiveFiltering ? VIPS_FOREIGN_PNG_FILTER_ALL : VIPS_FOREIGN_PNG_FILTER_NONE)
|
||||||
|
->set("palette", baton->pngPalette)
|
||||||
|
->set("Q", baton->pngQuality)
|
||||||
|
->set("colours", baton->pngColours)
|
||||||
|
->set("dither", baton->pngDither));
|
||||||
baton->formatOut = "png";
|
baton->formatOut = "png";
|
||||||
} else if (baton->formatOut == "webp" || (mightMatchInput && isWebp) ||
|
} else if (baton->formatOut == "webp" || (mightMatchInput && isWebp) ||
|
||||||
(willMatchInput && inputImageType == ImageType::WEBP)) {
|
(willMatchInput && inputImageType == ImageType::WEBP)) {
|
||||||
@@ -842,6 +882,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("Q", baton->webpQuality)
|
->set("Q", baton->webpQuality)
|
||||||
->set("lossless", baton->webpLossless)
|
->set("lossless", baton->webpLossless)
|
||||||
->set("near_lossless", baton->webpNearLossless)
|
->set("near_lossless", baton->webpNearLossless)
|
||||||
|
->set("smart_subsample", baton->webpSmartSubsample)
|
||||||
|
->set("reduction_effort", baton->webpReductionEffort)
|
||||||
->set("alpha_q", baton->webpAlphaQuality));
|
->set("alpha_q", baton->webpAlphaQuality));
|
||||||
baton->formatOut = "webp";
|
baton->formatOut = "webp";
|
||||||
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
} else if (baton->formatOut == "tiff" || (mightMatchInput && isTiff) ||
|
||||||
@@ -856,10 +898,28 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("squash", baton->tiffSquash)
|
->set("squash", baton->tiffSquash)
|
||||||
->set("compression", baton->tiffCompression)
|
->set("compression", baton->tiffCompression)
|
||||||
->set("predictor", baton->tiffPredictor)
|
->set("predictor", baton->tiffPredictor)
|
||||||
|
->set("pyramid", baton->tiffPyramid)
|
||||||
|
->set("tile", baton->tiffTile)
|
||||||
|
->set("tile_height", baton->tiffTileHeight)
|
||||||
|
->set("tile_width", baton->tiffTileWidth)
|
||||||
->set("xres", baton->tiffXres)
|
->set("xres", baton->tiffXres)
|
||||||
->set("yres", baton->tiffYres));
|
->set("yres", baton->tiffYres));
|
||||||
baton->formatOut = "tiff";
|
baton->formatOut = "tiff";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
|
} else if (baton->formatOut == "heif" || (mightMatchInput && isHeif) ||
|
||||||
|
(willMatchInput && inputImageType == ImageType::HEIF)) {
|
||||||
|
// Write HEIF to file
|
||||||
|
#ifdef VIPS_TYPE_FOREIGN_HEIF_COMPRESSION
|
||||||
|
if (sharp::IsAvif(baton->fileOut)) {
|
||||||
|
baton->heifCompression = VIPS_FOREIGN_HEIF_COMPRESSION_AV1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
image.heifsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
||||||
|
->set("strip", !baton->withMetadata)
|
||||||
|
->set("Q", baton->heifQuality)
|
||||||
|
->set("compression", baton->heifCompression)
|
||||||
|
->set("lossless", baton->heifLossless));
|
||||||
|
baton->formatOut = "heif";
|
||||||
} else if (baton->formatOut == "dz" || isDz || isDzZip) {
|
} else if (baton->formatOut == "dz" || isDz || isDzZip) {
|
||||||
if (isDzZip) {
|
if (isDzZip) {
|
||||||
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
||||||
@@ -878,7 +938,9 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
{"Q", std::to_string(baton->webpQuality)},
|
{"Q", std::to_string(baton->webpQuality)},
|
||||||
{"alpha_q", std::to_string(baton->webpAlphaQuality)},
|
{"alpha_q", std::to_string(baton->webpAlphaQuality)},
|
||||||
{"lossless", baton->webpLossless ? "TRUE" : "FALSE"},
|
{"lossless", baton->webpLossless ? "TRUE" : "FALSE"},
|
||||||
{"near_lossless", baton->webpNearLossless ? "TRUE" : "FALSE"}
|
{"near_lossless", baton->webpNearLossless ? "TRUE" : "FALSE"},
|
||||||
|
{"smart_subsample", baton->webpSmartSubsample ? "TRUE" : "FALSE"},
|
||||||
|
{"reduction_effort", std::to_string(baton->webpReductionEffort)}
|
||||||
};
|
};
|
||||||
suffix = AssembleSuffixString(".webp", options);
|
suffix = AssembleSuffixString(".webp", options);
|
||||||
} else {
|
} else {
|
||||||
@@ -905,7 +967,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->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));
|
->set("angle", CalculateAngleRotation(baton->tileAngle))
|
||||||
|
->set("skip_blanks", baton->tileSkipBlanks);
|
||||||
|
|
||||||
// libvips chooses a default depth based on layout. Instead of replicating that logic here by
|
// libvips chooses a default depth based on layout. Instead of replicating that logic here by
|
||||||
// not passing anything - libvips will handle choice
|
// not passing anything - libvips will handle choice
|
||||||
@@ -985,8 +1048,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
argv[2] = info;
|
argv[2] = info;
|
||||||
} else {
|
} else {
|
||||||
// Add file size to info
|
// Add file size to info
|
||||||
GStatBuf st;
|
struct STAT64_STRUCT st;
|
||||||
if (g_stat(baton->fileOut.data(), &st) == 0) {
|
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
|
||||||
Set(info, New("size").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(st.st_size)));
|
Set(info, New("size").ToLocalChecked(), New<v8::Uint32>(static_cast<uint32_t>(st.st_size)));
|
||||||
}
|
}
|
||||||
argv[1] = info;
|
argv[1] = info;
|
||||||
@@ -999,13 +1062,17 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
GetFromPersistent(index);
|
GetFromPersistent(index);
|
||||||
return index + 1;
|
return index + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Delete baton
|
||||||
delete baton->input;
|
delete baton->input;
|
||||||
delete baton->overlay;
|
|
||||||
delete baton->boolean;
|
delete baton->boolean;
|
||||||
for_each(baton->joinChannelIn.begin(), baton->joinChannelIn.end(),
|
for (Composite *composite : baton->composite) {
|
||||||
[this](sharp::InputDescriptor *joinChannelIn) {
|
delete composite->input;
|
||||||
delete joinChannelIn;
|
delete composite;
|
||||||
});
|
}
|
||||||
|
for (sharp::InputDescriptor *input : baton->joinChannelIn) {
|
||||||
|
delete input;
|
||||||
|
}
|
||||||
delete baton;
|
delete baton;
|
||||||
|
|
||||||
// Handle warnings
|
// Handle warnings
|
||||||
@@ -1117,9 +1184,6 @@ NAN_METHOD(pipeline) {
|
|||||||
|
|
||||||
// Input
|
// Input
|
||||||
baton->input = CreateInputDescriptor(AttrAs<v8::Object>(options, "input"), buffersToPersist);
|
baton->input = CreateInputDescriptor(AttrAs<v8::Object>(options, "input"), buffersToPersist);
|
||||||
|
|
||||||
// ICC profile to use when input CMYK image has no embedded profile
|
|
||||||
baton->iccProfilePath = AttrAsStr(options, "iccProfilePath");
|
|
||||||
baton->accessMethod = AttrTo<bool>(options, "sequentialRead") ?
|
baton->accessMethod = AttrTo<bool>(options, "sequentialRead") ?
|
||||||
VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||||
// Limit input images to a given number of pixels, where pixels = width * height
|
// Limit input images to a given number of pixels, where pixels = width * height
|
||||||
@@ -1152,14 +1216,22 @@ NAN_METHOD(pipeline) {
|
|||||||
// Tint chroma
|
// Tint chroma
|
||||||
baton->tintA = AttrTo<double>(options, "tintA");
|
baton->tintA = AttrTo<double>(options, "tintA");
|
||||||
baton->tintB = AttrTo<double>(options, "tintB");
|
baton->tintB = AttrTo<double>(options, "tintB");
|
||||||
// Overlay options
|
// Composite
|
||||||
if (HasAttr(options, "overlay")) {
|
v8::Local<v8::Array> compositeArray = Nan::Get(options, Nan::New("composite").ToLocalChecked())
|
||||||
baton->overlay = CreateInputDescriptor(AttrAs<v8::Object>(options, "overlay"), buffersToPersist);
|
.ToLocalChecked().As<v8::Array>();
|
||||||
baton->overlayGravity = AttrTo<int32_t>(options, "overlayGravity");
|
int const compositeArrayLength = AttrTo<uint32_t>(compositeArray, "length");
|
||||||
baton->overlayXOffset = AttrTo<int32_t>(options, "overlayXOffset");
|
for (int i = 0; i < compositeArrayLength; i++) {
|
||||||
baton->overlayYOffset = AttrTo<int32_t>(options, "overlayYOffset");
|
v8::Local<v8::Object> compositeObject = Nan::Get(compositeArray, i).ToLocalChecked().As<v8::Object>();
|
||||||
baton->overlayTile = AttrTo<bool>(options, "overlayTile");
|
Composite *composite = new Composite;
|
||||||
baton->overlayCutout = AttrTo<bool>(options, "overlayCutout");
|
composite->input = CreateInputDescriptor(AttrAs<v8::Object>(compositeObject, "input"), buffersToPersist);
|
||||||
|
composite->mode = static_cast<VipsBlendMode>(
|
||||||
|
vips_enum_from_nick(nullptr, VIPS_TYPE_BLEND_MODE, AttrAsStr(compositeObject, "blend").data()));
|
||||||
|
composite->gravity = AttrTo<uint32_t>(compositeObject, "gravity");
|
||||||
|
composite->left = AttrTo<int32_t>(compositeObject, "left");
|
||||||
|
composite->top = AttrTo<int32_t>(compositeObject, "top");
|
||||||
|
composite->tile = AttrTo<bool>(compositeObject, "tile");
|
||||||
|
composite->premultiplied = AttrTo<bool>(compositeObject, "premultiplied");
|
||||||
|
baton->composite.push_back(composite);
|
||||||
}
|
}
|
||||||
// Resize options
|
// Resize options
|
||||||
baton->withoutEnlargement = AttrTo<bool>(options, "withoutEnlargement");
|
baton->withoutEnlargement = AttrTo<bool>(options, "withoutEnlargement");
|
||||||
@@ -1185,6 +1257,9 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->flattenBackground = AttrAsRgba(options, "flattenBackground");
|
baton->flattenBackground = AttrAsRgba(options, "flattenBackground");
|
||||||
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->brightness = AttrTo<double>(options, "brightness");
|
||||||
|
baton->saturation = AttrTo<double>(options, "saturation");
|
||||||
|
baton->hue = AttrTo<int32_t>(options, "hue");
|
||||||
baton->medianSize = AttrTo<uint32_t>(options, "medianSize");
|
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");
|
||||||
@@ -1193,6 +1268,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->thresholdGrayscale = AttrTo<bool>(options, "thresholdGrayscale");
|
baton->thresholdGrayscale = AttrTo<bool>(options, "thresholdGrayscale");
|
||||||
baton->trimThreshold = AttrTo<double>(options, "trimThreshold");
|
baton->trimThreshold = AttrTo<double>(options, "trimThreshold");
|
||||||
baton->gamma = AttrTo<double>(options, "gamma");
|
baton->gamma = AttrTo<double>(options, "gamma");
|
||||||
|
baton->gammaOut = AttrTo<double>(options, "gammaOut");
|
||||||
baton->linearA = AttrTo<double>(options, "linearA");
|
baton->linearA = AttrTo<double>(options, "linearA");
|
||||||
baton->linearB = AttrTo<double>(options, "linearB");
|
baton->linearB = AttrTo<double>(options, "linearB");
|
||||||
baton->greyscale = AttrTo<bool>(options, "greyscale");
|
baton->greyscale = AttrTo<bool>(options, "greyscale");
|
||||||
@@ -1212,6 +1288,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->extractChannel = AttrTo<int32_t>(options, "extractChannel");
|
baton->extractChannel = AttrTo<int32_t>(options, "extractChannel");
|
||||||
|
|
||||||
baton->removeAlpha = AttrTo<bool>(options, "removeAlpha");
|
baton->removeAlpha = AttrTo<bool>(options, "removeAlpha");
|
||||||
|
baton->ensureAlpha = AttrTo<bool>(options, "ensureAlpha");
|
||||||
if (HasAttr(options, "boolean")) {
|
if (HasAttr(options, "boolean")) {
|
||||||
baton->boolean = CreateInputDescriptor(AttrAs<v8::Object>(options, "boolean"), buffersToPersist);
|
baton->boolean = CreateInputDescriptor(AttrAs<v8::Object>(options, "boolean"), buffersToPersist);
|
||||||
baton->booleanOp = sharp::GetBooleanOperation(AttrAsStr(options, "booleanOp"));
|
baton->booleanOp = sharp::GetBooleanOperation(AttrAsStr(options, "booleanOp"));
|
||||||
@@ -1232,6 +1309,13 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->convKernel[i] = AttrTo<double>(kdata, i);
|
baton->convKernel[i] = AttrTo<double>(kdata, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (HasAttr(options, "recombMatrix")) {
|
||||||
|
baton->recombMatrix = std::unique_ptr<double[]>(new double[9]);
|
||||||
|
v8::Local<v8::Array> recombMatrix = AttrAs<v8::Array>(options, "recombMatrix");
|
||||||
|
for (unsigned int i = 0; i < 9; i++) {
|
||||||
|
baton->recombMatrix[i] = AttrTo<double>(recombMatrix, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
baton->colourspace = sharp::GetInterpretation(AttrAsStr(options, "colourspace"));
|
baton->colourspace = sharp::GetInterpretation(AttrAsStr(options, "colourspace"));
|
||||||
if (baton->colourspace == VIPS_INTERPRETATION_ERROR) {
|
if (baton->colourspace == VIPS_INTERPRETATION_ERROR) {
|
||||||
baton->colourspace = VIPS_INTERPRETATION_sRGB;
|
baton->colourspace = VIPS_INTERPRETATION_sRGB;
|
||||||
@@ -1253,12 +1337,22 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->pngProgressive = AttrTo<bool>(options, "pngProgressive");
|
baton->pngProgressive = AttrTo<bool>(options, "pngProgressive");
|
||||||
baton->pngCompressionLevel = AttrTo<uint32_t>(options, "pngCompressionLevel");
|
baton->pngCompressionLevel = AttrTo<uint32_t>(options, "pngCompressionLevel");
|
||||||
baton->pngAdaptiveFiltering = AttrTo<bool>(options, "pngAdaptiveFiltering");
|
baton->pngAdaptiveFiltering = AttrTo<bool>(options, "pngAdaptiveFiltering");
|
||||||
|
baton->pngPalette = AttrTo<bool>(options, "pngPalette");
|
||||||
|
baton->pngQuality = AttrTo<uint32_t>(options, "pngQuality");
|
||||||
|
baton->pngColours = AttrTo<uint32_t>(options, "pngColours");
|
||||||
|
baton->pngDither = AttrTo<double>(options, "pngDither");
|
||||||
baton->webpQuality = AttrTo<uint32_t>(options, "webpQuality");
|
baton->webpQuality = AttrTo<uint32_t>(options, "webpQuality");
|
||||||
baton->webpAlphaQuality = AttrTo<uint32_t>(options, "webpAlphaQuality");
|
baton->webpAlphaQuality = AttrTo<uint32_t>(options, "webpAlphaQuality");
|
||||||
baton->webpLossless = AttrTo<bool>(options, "webpLossless");
|
baton->webpLossless = AttrTo<bool>(options, "webpLossless");
|
||||||
baton->webpNearLossless = AttrTo<bool>(options, "webpNearLossless");
|
baton->webpNearLossless = AttrTo<bool>(options, "webpNearLossless");
|
||||||
|
baton->webpSmartSubsample = AttrTo<bool>(options, "webpSmartSubsample");
|
||||||
|
baton->webpReductionEffort = AttrTo<uint32_t>(options, "webpReductionEffort");
|
||||||
baton->tiffQuality = AttrTo<uint32_t>(options, "tiffQuality");
|
baton->tiffQuality = AttrTo<uint32_t>(options, "tiffQuality");
|
||||||
|
baton->tiffPyramid = AttrTo<bool>(options, "tiffPyramid");
|
||||||
baton->tiffSquash = AttrTo<bool>(options, "tiffSquash");
|
baton->tiffSquash = AttrTo<bool>(options, "tiffSquash");
|
||||||
|
baton->tiffTile = AttrTo<bool>(options, "tiffTile");
|
||||||
|
baton->tiffTileWidth = AttrTo<uint32_t>(options, "tiffTileWidth");
|
||||||
|
baton->tiffTileHeight = AttrTo<uint32_t>(options, "tiffTileHeight");
|
||||||
baton->tiffXres = AttrTo<double>(options, "tiffXres");
|
baton->tiffXres = AttrTo<double>(options, "tiffXres");
|
||||||
baton->tiffYres = AttrTo<double>(options, "tiffYres");
|
baton->tiffYres = AttrTo<double>(options, "tiffYres");
|
||||||
// tiff compression options
|
// tiff compression options
|
||||||
@@ -1268,12 +1362,19 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->tiffPredictor = static_cast<VipsForeignTiffPredictor>(
|
baton->tiffPredictor = static_cast<VipsForeignTiffPredictor>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_TIFF_PREDICTOR,
|
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_TIFF_PREDICTOR,
|
||||||
AttrAsStr(options, "tiffPredictor").data()));
|
AttrAsStr(options, "tiffPredictor").data()));
|
||||||
|
baton->heifQuality = AttrTo<uint32_t>(options, "heifQuality");
|
||||||
|
baton->heifLossless = AttrTo<bool>(options, "heifLossless");
|
||||||
|
#ifdef VIPS_TYPE_FOREIGN_HEIF_COMPRESSION
|
||||||
|
baton->heifCompression = static_cast<VipsForeignHeifCompression>(
|
||||||
|
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_HEIF_COMPRESSION,
|
||||||
|
AttrAsStr(options, "heifCompression").data()));
|
||||||
|
#endif
|
||||||
// Tile output
|
// Tile output
|
||||||
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");
|
baton->tileAngle = AttrTo<int32_t>(options, "tileAngle");
|
||||||
|
baton->tileSkipBlanks = AttrTo<int32_t>(options, "tileSkipBlanks");
|
||||||
if (tileContainer == "zip") {
|
if (tileContainer == "zip") {
|
||||||
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
baton->tileContainer = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -34,20 +34,33 @@ enum class Canvas {
|
|||||||
IGNORE_ASPECT
|
IGNORE_ASPECT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Composite {
|
||||||
|
sharp::InputDescriptor *input;
|
||||||
|
VipsBlendMode mode;
|
||||||
|
int gravity;
|
||||||
|
int left;
|
||||||
|
int top;
|
||||||
|
bool tile;
|
||||||
|
bool premultiplied;
|
||||||
|
|
||||||
|
Composite():
|
||||||
|
input(nullptr),
|
||||||
|
mode(VIPS_BLEND_MODE_OVER),
|
||||||
|
gravity(0),
|
||||||
|
left(-1),
|
||||||
|
top(-1),
|
||||||
|
tile(false),
|
||||||
|
premultiplied(false) {}
|
||||||
|
};
|
||||||
|
|
||||||
struct PipelineBaton {
|
struct PipelineBaton {
|
||||||
sharp::InputDescriptor *input;
|
sharp::InputDescriptor *input;
|
||||||
std::string iccProfilePath;
|
|
||||||
int limitInputPixels;
|
int limitInputPixels;
|
||||||
std::string formatOut;
|
std::string formatOut;
|
||||||
std::string fileOut;
|
std::string fileOut;
|
||||||
void *bufferOut;
|
void *bufferOut;
|
||||||
size_t bufferOutLength;
|
size_t bufferOutLength;
|
||||||
sharp::InputDescriptor *overlay;
|
std::vector<Composite *> composite;
|
||||||
int overlayGravity;
|
|
||||||
int overlayXOffset;
|
|
||||||
int overlayYOffset;
|
|
||||||
bool overlayTile;
|
|
||||||
bool overlayCutout;
|
|
||||||
std::vector<sharp::InputDescriptor *> joinChannelIn;
|
std::vector<sharp::InputDescriptor *> joinChannelIn;
|
||||||
int topOffsetPre;
|
int topOffsetPre;
|
||||||
int leftOffsetPre;
|
int leftOffsetPre;
|
||||||
@@ -75,6 +88,9 @@ struct PipelineBaton {
|
|||||||
std::vector<double> flattenBackground;
|
std::vector<double> flattenBackground;
|
||||||
bool negate;
|
bool negate;
|
||||||
double blurSigma;
|
double blurSigma;
|
||||||
|
double brightness;
|
||||||
|
double saturation;
|
||||||
|
int hue;
|
||||||
int medianSize;
|
int medianSize;
|
||||||
double sharpenSigma;
|
double sharpenSigma;
|
||||||
double sharpenFlat;
|
double sharpenFlat;
|
||||||
@@ -87,6 +103,7 @@ struct PipelineBaton {
|
|||||||
double linearA;
|
double linearA;
|
||||||
double linearB;
|
double linearB;
|
||||||
double gamma;
|
double gamma;
|
||||||
|
double gammaOut;
|
||||||
bool greyscale;
|
bool greyscale;
|
||||||
bool normalise;
|
bool normalise;
|
||||||
bool useExifOrientation;
|
bool useExifOrientation;
|
||||||
@@ -114,16 +131,29 @@ struct PipelineBaton {
|
|||||||
bool pngProgressive;
|
bool pngProgressive;
|
||||||
int pngCompressionLevel;
|
int pngCompressionLevel;
|
||||||
bool pngAdaptiveFiltering;
|
bool pngAdaptiveFiltering;
|
||||||
|
bool pngPalette;
|
||||||
|
int pngQuality;
|
||||||
|
int pngColours;
|
||||||
|
double pngDither;
|
||||||
int webpQuality;
|
int webpQuality;
|
||||||
int webpAlphaQuality;
|
int webpAlphaQuality;
|
||||||
bool webpNearLossless;
|
bool webpNearLossless;
|
||||||
bool webpLossless;
|
bool webpLossless;
|
||||||
|
bool webpSmartSubsample;
|
||||||
|
int webpReductionEffort;
|
||||||
int tiffQuality;
|
int tiffQuality;
|
||||||
VipsForeignTiffCompression tiffCompression;
|
VipsForeignTiffCompression tiffCompression;
|
||||||
VipsForeignTiffPredictor tiffPredictor;
|
VipsForeignTiffPredictor tiffPredictor;
|
||||||
|
bool tiffPyramid;
|
||||||
bool tiffSquash;
|
bool tiffSquash;
|
||||||
|
bool tiffTile;
|
||||||
|
int tiffTileHeight;
|
||||||
|
int tiffTileWidth;
|
||||||
double tiffXres;
|
double tiffXres;
|
||||||
double tiffYres;
|
double tiffYres;
|
||||||
|
int heifQuality;
|
||||||
|
int heifCompression; // TODO(libvips 8.9.0): VipsForeignHeifCompression
|
||||||
|
bool heifLossless;
|
||||||
std::string err;
|
std::string err;
|
||||||
bool withMetadata;
|
bool withMetadata;
|
||||||
int withMetadataOrientation;
|
int withMetadataOrientation;
|
||||||
@@ -137,6 +167,7 @@ struct PipelineBaton {
|
|||||||
VipsOperationBoolean bandBoolOp;
|
VipsOperationBoolean bandBoolOp;
|
||||||
int extractChannel;
|
int extractChannel;
|
||||||
bool removeAlpha;
|
bool removeAlpha;
|
||||||
|
bool ensureAlpha;
|
||||||
VipsInterpretation colourspace;
|
VipsInterpretation colourspace;
|
||||||
int tileSize;
|
int tileSize;
|
||||||
int tileOverlap;
|
int tileOverlap;
|
||||||
@@ -144,18 +175,14 @@ struct PipelineBaton {
|
|||||||
VipsForeignDzLayout tileLayout;
|
VipsForeignDzLayout tileLayout;
|
||||||
std::string tileFormat;
|
std::string tileFormat;
|
||||||
int tileAngle;
|
int tileAngle;
|
||||||
|
int tileSkipBlanks;
|
||||||
VipsForeignDzDepth tileDepth;
|
VipsForeignDzDepth tileDepth;
|
||||||
|
std::unique_ptr<double[]> recombMatrix;
|
||||||
|
|
||||||
PipelineBaton():
|
PipelineBaton():
|
||||||
input(nullptr),
|
input(nullptr),
|
||||||
limitInputPixels(0),
|
limitInputPixels(0),
|
||||||
bufferOutLength(0),
|
bufferOutLength(0),
|
||||||
overlay(nullptr),
|
|
||||||
overlayGravity(0),
|
|
||||||
overlayXOffset(-1),
|
|
||||||
overlayYOffset(-1),
|
|
||||||
overlayTile(false),
|
|
||||||
overlayCutout(false),
|
|
||||||
topOffsetPre(-1),
|
topOffsetPre(-1),
|
||||||
topOffsetPost(-1),
|
topOffsetPost(-1),
|
||||||
channels(0),
|
channels(0),
|
||||||
@@ -172,6 +199,9 @@ struct PipelineBaton {
|
|||||||
flattenBackground{ 0.0, 0.0, 0.0 },
|
flattenBackground{ 0.0, 0.0, 0.0 },
|
||||||
negate(false),
|
negate(false),
|
||||||
blurSigma(0.0),
|
blurSigma(0.0),
|
||||||
|
brightness(1.0),
|
||||||
|
saturation(1.0),
|
||||||
|
hue(0),
|
||||||
medianSize(0),
|
medianSize(0),
|
||||||
sharpenSigma(0.0),
|
sharpenSigma(0.0),
|
||||||
sharpenFlat(1.0),
|
sharpenFlat(1.0),
|
||||||
@@ -209,13 +239,29 @@ struct PipelineBaton {
|
|||||||
pngProgressive(false),
|
pngProgressive(false),
|
||||||
pngCompressionLevel(9),
|
pngCompressionLevel(9),
|
||||||
pngAdaptiveFiltering(false),
|
pngAdaptiveFiltering(false),
|
||||||
|
pngPalette(false),
|
||||||
|
pngQuality(100),
|
||||||
|
pngColours(256),
|
||||||
|
pngDither(1.0),
|
||||||
webpQuality(80),
|
webpQuality(80),
|
||||||
|
webpAlphaQuality(100),
|
||||||
|
webpNearLossless(false),
|
||||||
|
webpLossless(false),
|
||||||
|
webpSmartSubsample(false),
|
||||||
|
webpReductionEffort(4),
|
||||||
tiffQuality(80),
|
tiffQuality(80),
|
||||||
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
|
tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
|
||||||
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
||||||
|
tiffPyramid(false),
|
||||||
tiffSquash(false),
|
tiffSquash(false),
|
||||||
|
tiffTile(false),
|
||||||
|
tiffTileHeight(256),
|
||||||
|
tiffTileWidth(256),
|
||||||
tiffXres(1.0),
|
tiffXres(1.0),
|
||||||
tiffYres(1.0),
|
tiffYres(1.0),
|
||||||
|
heifQuality(80),
|
||||||
|
heifCompression(1), // TODO(libvips 8.9.0): VIPS_FOREIGN_HEIF_COMPRESSION_HEVC
|
||||||
|
heifLossless(false),
|
||||||
withMetadata(false),
|
withMetadata(false),
|
||||||
withMetadataOrientation(-1),
|
withMetadataOrientation(-1),
|
||||||
convKernelWidth(0),
|
convKernelWidth(0),
|
||||||
@@ -227,12 +273,14 @@ struct PipelineBaton {
|
|||||||
bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
|
bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
|
||||||
extractChannel(-1),
|
extractChannel(-1),
|
||||||
removeAlpha(false),
|
removeAlpha(false),
|
||||||
|
ensureAlpha(false),
|
||||||
colourspace(VIPS_INTERPRETATION_LAST),
|
colourspace(VIPS_INTERPRETATION_LAST),
|
||||||
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),
|
tileAngle(0),
|
||||||
|
tileSkipBlanks(-1),
|
||||||
tileDepth(VIPS_FOREIGN_DZ_DEPTH_LAST) {}
|
tileDepth(VIPS_FOREIGN_DZ_DEPTH_LAST) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -51,4 +51,4 @@ NAN_MODULE_INIT(init) {
|
|||||||
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(stats)).ToLocalChecked());
|
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(stats)).ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(sharp, init)
|
NAN_MODULE_WORKER_ENABLED(sharp, init)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -115,7 +115,7 @@ class StatsWorker : public Nan::AsyncWorker {
|
|||||||
|
|
||||||
std::vector<ChannelStats>::iterator it;
|
std::vector<ChannelStats>::iterator it;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (it=baton->channelStats.begin() ; it < baton->channelStats.end(); it++, i++) {
|
for (it = baton->channelStats.begin(); it < baton->channelStats.end(); it++, i++) {
|
||||||
v8::Local<v8::Object> channelStat = New<v8::Object>();
|
v8::Local<v8::Object> channelStat = New<v8::Object>();
|
||||||
Set(channelStat, New("min").ToLocalChecked(), New<v8::Number>(it->min));
|
Set(channelStat, New("min").ToLocalChecked(), New<v8::Number>(it->min));
|
||||||
Set(channelStat, New("max").ToLocalChecked(), New<v8::Number>(it->max));
|
Set(channelStat, New("max").ToLocalChecked(), New<v8::Number>(it->max));
|
||||||
@@ -127,7 +127,7 @@ class StatsWorker : public Nan::AsyncWorker {
|
|||||||
Set(channelStat, New("minY").ToLocalChecked(), New<v8::Number>(it->minY));
|
Set(channelStat, New("minY").ToLocalChecked(), New<v8::Number>(it->minY));
|
||||||
Set(channelStat, New("maxX").ToLocalChecked(), New<v8::Number>(it->maxX));
|
Set(channelStat, New("maxX").ToLocalChecked(), New<v8::Number>(it->maxX));
|
||||||
Set(channelStat, New("maxY").ToLocalChecked(), New<v8::Number>(it->maxY));
|
Set(channelStat, New("maxY").ToLocalChecked(), New<v8::Number>(it->maxY));
|
||||||
channels->Set(i, channelStat);
|
Set(channels, i, channelStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set(info, New("channels").ToLocalChecked(), channels);
|
Set(info, New("channels").ToLocalChecked(), channels);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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.
|
||||||
@@ -150,8 +150,9 @@ NAN_METHOD(format) {
|
|||||||
|
|
||||||
// Which load/save operations are available for each compressed format?
|
// Which load/save operations are available for each compressed format?
|
||||||
Local<Object> format = New<Object>();
|
Local<Object> format = New<Object>();
|
||||||
for (std::string f : {
|
for (std::string const f : {
|
||||||
"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz", "ppm", "fits", "gif", "svg", "pdf", "v"
|
"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
|
||||||
|
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips"
|
||||||
}) {
|
}) {
|
||||||
// Input
|
// Input
|
||||||
Local<Boolean> hasInputFile =
|
Local<Boolean> hasInputFile =
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013, 2014, 2015, 2016, 2017 Lovell Fuller and contributors.
|
// Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 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,17 +8,16 @@
|
|||||||
"test": "node perf && node random && node parallel"
|
"test": "node perf && node random && node parallel"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.6.1",
|
"async": "^3.1.0",
|
||||||
"benchmark": "^2.1.4",
|
"benchmark": "^2.1.4",
|
||||||
"gm": "^1.23.1",
|
"gm": "^1.23.1",
|
||||||
"imagemagick": "^0.1.3",
|
"imagemagick": "^0.1.3",
|
||||||
"imagemagick-native": "^1.9.3",
|
"jimp": "^0.8.4",
|
||||||
"jimp": "^0.5.3",
|
"mapnik": "^4.3.1",
|
||||||
"mapnik": "^4.0.1",
|
"semver": "^6.3.0"
|
||||||
"semver": "^5.5.1"
|
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=8.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,6 @@ const gm = require('gm');
|
|||||||
const imagemagick = require('imagemagick');
|
const imagemagick = require('imagemagick');
|
||||||
const mapnik = require('mapnik');
|
const mapnik = require('mapnik');
|
||||||
const jimp = require('jimp');
|
const jimp = require('jimp');
|
||||||
let imagemagickNative;
|
|
||||||
try {
|
|
||||||
imagemagickNative = require('imagemagick-native');
|
|
||||||
} catch (err) {
|
|
||||||
console.log('Excluding imagemagick-native');
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
@@ -28,7 +22,7 @@ const height = 588;
|
|||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
|
|
||||||
async.series({
|
async.series({
|
||||||
'jpeg': function (callback) {
|
jpeg: function (callback) {
|
||||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
const jpegSuite = new Benchmark.Suite('jpeg');
|
const jpegSuite = new Benchmark.Suite('jpeg');
|
||||||
// jimp
|
// jimp
|
||||||
@@ -126,29 +120,6 @@ async.series({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// imagemagick-native
|
|
||||||
if (typeof imagemagickNative !== 'undefined') {
|
|
||||||
jpegSuite.add('imagemagick-native-buffer-buffer', {
|
|
||||||
defer: true,
|
|
||||||
fn: function (deferred) {
|
|
||||||
imagemagickNative.convert({
|
|
||||||
srcData: inputJpgBuffer,
|
|
||||||
quality: 80,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
format: 'JPEG',
|
|
||||||
filter: 'Lanczos'
|
|
||||||
}, function (err, buffer) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
} else {
|
|
||||||
assert.notStrictEqual(null, buffer);
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// gm
|
// gm
|
||||||
jpegSuite.add('gm-buffer-file', {
|
jpegSuite.add('gm-buffer-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
@@ -289,6 +260,9 @@ async.series({
|
|||||||
.then(function (buffer) {
|
.then(function (buffer) {
|
||||||
assert.notStrictEqual(null, buffer);
|
assert.notStrictEqual(null, buffer);
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).on('cycle', function (event) {
|
}).on('cycle', function (event) {
|
||||||
@@ -698,22 +672,6 @@ async.series({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// imagemagick-native
|
|
||||||
if (typeof imagemagickNative !== 'undefined') {
|
|
||||||
pngSuite.add('imagemagick-native-buffer-buffer', {
|
|
||||||
defer: true,
|
|
||||||
fn: function (deferred) {
|
|
||||||
imagemagickNative.convert({
|
|
||||||
srcData: inputPngBuffer,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
format: 'PNG',
|
|
||||||
filter: 'Lanczos'
|
|
||||||
});
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// gm
|
// gm
|
||||||
pngSuite.add('gm-file-file', {
|
pngSuite.add('gm-file-file', {
|
||||||
defer: true,
|
defer: true,
|
||||||
|
|||||||
BIN
test/fixtures/alpha-layer-1-fill-low-alpha.png
vendored
|
Before Width: | Height: | Size: 222 KiB |
BIN
test/fixtures/alpha-layer-2-ink-low-alpha.png
vendored
|
Before Width: | Height: | Size: 89 KiB |
BIN
test/fixtures/alpha-layer-2-ink.png
vendored
|
Before Width: | Height: | Size: 80 KiB |
BIN
test/fixtures/expected/Landscape_1-recomb-saturation.jpg
vendored
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
test/fixtures/expected/Landscape_1-recomb-sepia.jpg
vendored
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
test/fixtures/expected/Landscape_1-recomb-sepia2.jpg
vendored
Normal file
|
After Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 234 KiB |
|
Before Width: | Height: | Size: 186 KiB |
BIN
test/fixtures/expected/alpha-layer-01-low-alpha.png
vendored
|
Before Width: | Height: | Size: 188 KiB |
BIN
test/fixtures/expected/alpha-layer-01.png
vendored
|
Before Width: | Height: | Size: 234 KiB |
|
Before Width: | Height: | Size: 259 KiB |
|
Before Width: | Height: | Size: 208 KiB |
BIN
test/fixtures/expected/alpha-layer-012-low-alpha.png
vendored
|
Before Width: | Height: | Size: 209 KiB |
BIN
test/fixtures/expected/alpha-layer-012.png
vendored
|
Before Width: | Height: | Size: 260 KiB |
|
Before Width: | Height: | Size: 221 KiB |
|
Before Width: | Height: | Size: 179 KiB |
BIN
test/fixtures/expected/alpha-layer-12-low-alpha.png
vendored
|
Before Width: | Height: | Size: 179 KiB |
BIN
test/fixtures/expected/alpha-layer-12.png
vendored
|
Before Width: | Height: | Size: 200 KiB |
BIN
test/fixtures/expected/alpha-recomb-sepia.png
vendored
Normal file
|
After Width: | Height: | Size: 209 KiB |
BIN
test/fixtures/expected/composite-cutout.png
vendored
Normal file
|
After Width: | Height: | Size: 175 KiB |
BIN
test/fixtures/expected/composite-multiple.png
vendored
Normal file
|
After Width: | Height: | Size: 222 B |
BIN
test/fixtures/expected/composite.blend.dest-over.png
vendored
Normal file
|
After Width: | Height: | Size: 197 B |
BIN
test/fixtures/expected/composite.blend.over.png
vendored
Normal file
|
After Width: | Height: | Size: 197 B |
BIN
test/fixtures/expected/composite.blend.saturate.png
vendored
Normal file
|
After Width: | Height: | Size: 194 B |
BIN
test/fixtures/expected/composite.blend.xor.png
vendored
Normal file
|
After Width: | Height: | Size: 192 B |
BIN
test/fixtures/expected/crop-strategy-attention.jpg
vendored
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.9 KiB |
BIN
test/fixtures/expected/expected.absent.composite.premultiplied.png
vendored
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/expected.false.composite.premultiplied.png
vendored
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/expected.true.composite.premultiplied.png
vendored
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
test/fixtures/expected/extend-equal-single.jpg
vendored
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
test/fixtures/expected/extract-rotate-45.jpg
vendored
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
test/fixtures/expected/flatten-rgb16-orange.jpg
vendored
|
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 824 B |
BIN
test/fixtures/expected/gamma-in-2.2-out-3.0.jpg
vendored
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
test/fixtures/expected/modulate-all.jpg
vendored
Normal file
|
After Width: | Height: | Size: 664 KiB |
BIN
test/fixtures/expected/modulate-brightness-0-5.jpg
vendored
Normal file
|
After Width: | Height: | Size: 426 KiB |
BIN
test/fixtures/expected/modulate-brightness-2.jpg
vendored
Normal file
|
After Width: | Height: | Size: 692 KiB |
BIN
test/fixtures/expected/modulate-hue-120.jpg
vendored
Normal file
|
After Width: | Height: | Size: 653 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-120.png
vendored
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-150.png
vendored
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-180.png
vendored
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-210.png
vendored
Normal file
|
After Width: | Height: | Size: 93 KiB |