Compare commits
24 Commits
v0.33.5-rc
...
b7ff2645c4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7ff2645c4 | ||
|
|
79ac524262 | ||
|
|
92083ea64c | ||
|
|
82dc859a49 | ||
|
|
bee1fbaa34 | ||
|
|
eba82a8ba5 | ||
|
|
06b08bf10f | ||
|
|
7bdf419eb1 | ||
|
|
04e7f58cea | ||
|
|
3796dd8a87 | ||
|
|
8afec170ed | ||
|
|
3154af776e | ||
|
|
6480a94181 | ||
|
|
9582b5036f | ||
|
|
1533bf995a | ||
|
|
a53d7cb6bf | ||
|
|
b249357732 | ||
|
|
807d9241bd | ||
|
|
9bfaca2857 | ||
|
|
c26b77683a | ||
|
|
7ee54810d4 | ||
|
|
fc32e0bd3f | ||
|
|
0546e48467 | ||
|
|
ab65b7a0f1 |
55
.github/workflows/ci.yml
vendored
@@ -14,39 +14,54 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
container: rockylinux:8
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: linux-x64
|
||||
prebuild: true
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
container: rockylinux:8
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: linux-x64
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
container: rockylinux:8
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^22.9.0"
|
||||
nodejs_version_major: 22
|
||||
platform: linux-x64
|
||||
- os: ubuntu-24.04
|
||||
container: node:18-alpine3.17
|
||||
nodejs_version_major: 18
|
||||
platform: linuxmusl-x64
|
||||
prebuild: true
|
||||
- os: ubuntu-22.04
|
||||
- os: ubuntu-24.04
|
||||
container: node:20-alpine3.18
|
||||
nodejs_version_major: 20
|
||||
platform: linuxmusl-x64
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
container: node:22-alpine3.20
|
||||
nodejs_version_major: 22
|
||||
platform: linuxmusl-x64
|
||||
- os: macos-13
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: darwin-x64
|
||||
prebuild: true
|
||||
- os: macos-12
|
||||
- os: macos-13
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: darwin-x64
|
||||
- os: macos-13
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^22.9.0"
|
||||
nodejs_version_major: 22
|
||||
platform: darwin-x64
|
||||
- os: macos-14
|
||||
nodejs_arch: arm64
|
||||
nodejs_version: "^18.17.0"
|
||||
@@ -58,6 +73,11 @@ jobs:
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: darwin-arm64
|
||||
- os: macos-14
|
||||
nodejs_arch: arm64
|
||||
nodejs_version: "^22.9.0"
|
||||
nodejs_version_major: 22
|
||||
platform: darwin-arm64
|
||||
- os: windows-2019
|
||||
nodejs_arch: x86
|
||||
nodejs_version: "18.18.2" # pinned to avoid 18.19.0 and npm 10
|
||||
@@ -69,6 +89,11 @@ jobs:
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: win32-ia32
|
||||
- os: windows-2019
|
||||
nodejs_arch: x86
|
||||
nodejs_version: "^22.9.0"
|
||||
nodejs_version_major: 22
|
||||
platform: win32-ia32
|
||||
- os: windows-2019
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
@@ -80,6 +105,11 @@ jobs:
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: win32-x64
|
||||
- os: windows-2019
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^22.9.0"
|
||||
nodejs_version_major: 22
|
||||
platform: win32-x64
|
||||
steps:
|
||||
- name: Dependencies (Rocky Linux glibc)
|
||||
if: contains(matrix.container, 'rockylinux')
|
||||
@@ -125,7 +155,7 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} - prebuild
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -144,6 +174,13 @@ jobs:
|
||||
nodejs_hostname: nodejs.org
|
||||
nodejs_version: "18.17.0"
|
||||
nodejs_version_major: 18
|
||||
- platform: linux-ppc64
|
||||
distro: bullseye
|
||||
run_on_arch: ppc64le
|
||||
nodejs_arch: ppc64le
|
||||
nodejs_hostname: nodejs.org
|
||||
nodejs_version: "18.17.0"
|
||||
nodejs_version_major: 18
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: uraimo/run-on-arch-action@v2
|
||||
@@ -170,8 +207,8 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
name: wasm32 - prebuild
|
||||
runs-on: ubuntu-22.04
|
||||
container: "emscripten/emsdk:3.1.64"
|
||||
runs-on: ubuntu-24.04
|
||||
container: "emscripten/emsdk:3.1.70"
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
28
.github/workflows/npm.yml
vendored
@@ -16,57 +16,57 @@ jobs:
|
||||
matrix:
|
||||
include:
|
||||
- name: linux-x64-node-npm
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: node
|
||||
package-manager: npm
|
||||
- name: linux-x64-node-pnpm
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: node
|
||||
package-manager: pnpm
|
||||
- name: linux-x64-node-yarn
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: node
|
||||
package-manager: yarn
|
||||
- name: linux-x64-node-yarn-pnp
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: node
|
||||
package-manager: yarn-pnp
|
||||
- name: linux-x64-node-yarn-v1
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: node
|
||||
package-manager: yarn-v1
|
||||
- name: linux-x64-deno
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: deno
|
||||
- name: linux-x64-bun
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-24.04
|
||||
runtime: bun
|
||||
|
||||
- name: darwin-x64-node-npm
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: node
|
||||
package-manager: npm
|
||||
- name: darwin-x64-node-pnpm
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: node
|
||||
package-manager: pnpm
|
||||
- name: darwin-x64-node-yarn
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: node
|
||||
package-manager: yarn
|
||||
- name: darwin-x64-node-yarn-pnp
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: node
|
||||
package-manager: yarn-pnp
|
||||
- name: darwin-x64-node-yarn-v1
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: node
|
||||
package-manager: yarn-v1
|
||||
- name: darwin-x64-deno
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: deno
|
||||
- name: darwin-x64-bun
|
||||
runs-on: macos-12
|
||||
runs-on: macos-13
|
||||
runtime: bun
|
||||
|
||||
- name: win32-x64-node-npm
|
||||
|
||||
@@ -27,9 +27,9 @@ const output = await sharp(input)
|
||||
|
||||
Convert to 8-bit greyscale; 256 shades of grey.
|
||||
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||
By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
||||
By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
||||
This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
||||
which will produce an output image containing one color channel.
|
||||
which will produce an output image containing one colour channel.
|
||||
An alpha channel may be present, and will be unchanged by the operation.
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ Composite image(s) over the processed (resized, extracted etc.) image.
|
||||
The images to composite must be the same size or smaller than the processed image.
|
||||
If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||
|
||||
Any resize, rotate or extract operations in the same processing pipeline
|
||||
will always be applied to the input image before composition.
|
||||
Other operations in the same processing pipeline (e.g. resize, rotate, flip,
|
||||
flop, extract) will always be applied to the input image before composition.
|
||||
|
||||
The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||
`dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||
|
||||
@@ -40,6 +40,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages`
|
||||
| [options.page] | <code>number</code> | <code>0</code> | Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based. |
|
||||
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
|
||||
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
|
||||
| [options.pdfBackground] | <code>string</code> \| <code>Object</code> | | Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. |
|
||||
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`. |
|
||||
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
|
||||
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
|
||||
|
||||
@@ -22,15 +22,16 @@ A `Promise` is returned when `callback` is not provided.
|
||||
- `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
|
||||
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||
- `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
||||
- `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
||||
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||
- `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
||||
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||
- `pagePrimary`: Number of the primary page in a HEIF image
|
||||
- `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||
- `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images
|
||||
- `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||
|
||||
@@ -104,7 +104,7 @@ const output = await sharp(input).flop().toBuffer();
|
||||
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||
|
||||
You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||
By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||
By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
||||
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||
|
||||
In the case of a 2x2 matrix, the transform is:
|
||||
|
||||
@@ -439,6 +439,7 @@ Use these WebP options for output image.
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression mode |
|
||||
| [options.nearLossless] | <code>boolean</code> | <code>false</code> | use near_lossless compression mode |
|
||||
| [options.smartSubsample] | <code>boolean</code> | <code>false</code> | use high quality chroma subsampling |
|
||||
| [options.smartDeblock] | <code>boolean</code> | <code>false</code> | auto-adjust the deblocking filter, can improve low contrast edges (slow) |
|
||||
| [options.preset] | <code>string</code> | <code>"'default'"</code> | named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text |
|
||||
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 6 (slowest) |
|
||||
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||
@@ -694,8 +695,6 @@ Requires libvips compiled with support for libjxl.
|
||||
The prebuilt binaries do not include this - see
|
||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||
|
||||
Image metadata (EXIF, XMP) is unsupported.
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
@@ -710,7 +709,9 @@ Image metadata (EXIF, XMP) is unsupported.
|
||||
| [options.quality] | <code>number</code> | | calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified |
|
||||
| [options.decodingTier] | <code>number</code> | <code>0</code> | target decode speed tier, between 0 (highest quality) and 4 (lowest quality) |
|
||||
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 3 (fastest) and 9 (slowest) |
|
||||
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 9 (slowest) |
|
||||
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||
| [options.delay] | <code>number</code> \| <code>Array.<number></code> | | delay(s) between animation frames (in milliseconds) |
|
||||
|
||||
|
||||
|
||||
@@ -761,10 +762,6 @@ Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed arc
|
||||
|
||||
The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
||||
|
||||
Requires libvips compiled with support for libgsf.
|
||||
The prebuilt binaries do not include this - see
|
||||
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||
|
||||
|
||||
**Throws**:
|
||||
|
||||
|
||||
@@ -1,10 +1,38 @@
|
||||
# Changelog
|
||||
|
||||
## v0.34 - *hat*
|
||||
|
||||
Requires libvips v8.16.0
|
||||
|
||||
### v0.34.0 - TBD
|
||||
|
||||
* Breaking: Support `info.size` on wide-character systems via upgrade to C++17.
|
||||
[#3943](https://github.com/lovell/sharp/issues/3943)
|
||||
|
||||
* Breaking: Ensure `background` metadata can be parsed by `color` package.
|
||||
[#4090](https://github.com/lovell/sharp/issues/4090)
|
||||
|
||||
* Add `isPalette` and `bitsPerSample` to metadata, deprecate `paletteBitDepth`.
|
||||
|
||||
* Expose WebP `smartDeblock` output option.
|
||||
|
||||
* TypeScript: Ensure channel counts use the correct range.
|
||||
[#4197](https://github.com/lovell/sharp/pull/4197)
|
||||
[@DavidVaness](https://github.com/DavidVaness)
|
||||
|
||||
* Improve support for ppc64le architecture.
|
||||
[#4203](https://github.com/lovell/sharp/pull/4203)
|
||||
[@sumitd2](https://github.com/sumitd2)
|
||||
|
||||
* Add `pdfBackground` constructor property.
|
||||
[#4207](https://github.com/lovell/sharp/pull/4207)
|
||||
[@calebmer](https://github.com/calebmer)
|
||||
|
||||
## v0.33 - *gauge*
|
||||
|
||||
Requires libvips v8.15.3
|
||||
|
||||
### v0.33.5 - TBD
|
||||
### v0.33.5 - 16th August 2024
|
||||
|
||||
* Upgrade to libvips v8.15.3 for upstream bug fixes.
|
||||
|
||||
@@ -37,6 +65,10 @@ Requires libvips v8.15.3
|
||||
* Ensure `keepIccProfile` avoids colour transformation where possible.
|
||||
[#4186](https://github.com/lovell/sharp/issues/4186)
|
||||
|
||||
* TypeScript: `chromaSubsampling` metadata is optional.
|
||||
[#4191](https://github.com/lovell/sharp/pull/4191)
|
||||
[@DavidVaness](https://github.com/DavidVaness)
|
||||
|
||||
### v0.33.4 - 16th May 2024
|
||||
|
||||
* Remove experimental status from `pipelineColourspace`.
|
||||
|
||||
@@ -302,3 +302,9 @@ GitHub: https://github.com/ton11797
|
||||
|
||||
Name: Nathan Keynes
|
||||
GitHub: https://github.com/nkeynes
|
||||
|
||||
Name: Sumit D
|
||||
GitHub: https://github.com/sumitd2
|
||||
|
||||
Name: Caleb Meredith
|
||||
GitHub: https://github.com/calebmer
|
||||
|
||||
@@ -36,10 +36,11 @@ deno run --allow-ffi ...
|
||||
|
||||
Ready-compiled sharp and libvips binaries are provided for use on the most common platforms:
|
||||
|
||||
* macOS x64 (>= 10.13)
|
||||
* macOS x64 (>= 10.15)
|
||||
* macOS ARM64
|
||||
* Linux ARM (glibc >= 2.28)
|
||||
* Linux ARM (glibc >= 2.31)
|
||||
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
|
||||
* Linux ppc64 (glibc >= 2.31)
|
||||
* Linux s390x (glibc >= 2.31)
|
||||
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
|
||||
* Windows x64
|
||||
@@ -110,7 +111,7 @@ environment variables.
|
||||
|
||||
Building from source requires:
|
||||
|
||||
* C++11 compiler
|
||||
* C++17 compiler
|
||||
* [node-addon-api](https://www.npmjs.com/package/node-addon-api) version 7+
|
||||
* [node-gyp](https://github.com/nodejs/node-gyp#installation) version 9+ and its dependencies
|
||||
|
||||
@@ -134,6 +135,8 @@ Use in web browsers is unsupported.
|
||||
|
||||
Native text rendering is unsupported.
|
||||
|
||||
[Tile-based output](/api-output#tile) is unsupported.
|
||||
|
||||
```sh
|
||||
npm install --cpu=wasm32 sharp
|
||||
```
|
||||
@@ -235,8 +238,10 @@ custom:
|
||||
|
||||
### electron
|
||||
|
||||
#### electron-builder
|
||||
|
||||
Ensure `sharp` is unpacked from the ASAR archive file using the
|
||||
[asarUnpack](https://www.electron.build/configuration/configuration.html)
|
||||
[asarUnpack](https://www.electron.build/app-builder-lib.interface.platformspecificbuildoptions#asarunpack)
|
||||
option.
|
||||
|
||||
```json
|
||||
@@ -251,6 +256,22 @@ option.
|
||||
}
|
||||
```
|
||||
|
||||
#### electron-forge
|
||||
|
||||
Ensure `sharp` is unpacked from the ASAR archive file using the
|
||||
[unpack](https://js.electronforge.io/interfaces/_electron_forge_maker_squirrel.InternalOptions.Options.html#asar)
|
||||
option.
|
||||
|
||||
```json
|
||||
{
|
||||
"packagerConfig": {
|
||||
"asar": {
|
||||
"unpack": "**/node_modules/{sharp,@img}/**/*"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### vite
|
||||
|
||||
Ensure `sharp` is excluded from bundling via the
|
||||
|
||||
@@ -158,6 +158,7 @@ function bandbool (boolOp) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with channel-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -39,9 +39,9 @@ function tint (tint) {
|
||||
/**
|
||||
* Convert to 8-bit greyscale; 256 shades of grey.
|
||||
* This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
||||
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
||||
* This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
||||
* which will produce an output image containing one color channel.
|
||||
* which will produce an output image containing one colour channel.
|
||||
* An alpha channel may be present, and will be unchanged by the operation.
|
||||
*
|
||||
* @example
|
||||
@@ -159,6 +159,7 @@ function _setBackgroundColourOption (key, value) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with colour-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -46,8 +46,8 @@ const blend = {
|
||||
* The images to composite must be the same size or smaller than the processed image.
|
||||
* If both `top` and `left` options are provided, they take precedence over `gravity`.
|
||||
*
|
||||
* Any resize, rotate or extract operations in the same processing pipeline
|
||||
* will always be applied to the input image before composition.
|
||||
* Other operations in the same processing pipeline (e.g. resize, rotate, flip,
|
||||
* flop, extract) will always be applied to the input image before composition.
|
||||
*
|
||||
* The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
||||
* `dest`, `dest-over`, `dest-in`, `dest-out`, `dest-atop`,
|
||||
@@ -202,6 +202,7 @@ function composite (images) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with composite-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -139,6 +139,7 @@ const debuglog = util.debuglog('sharp');
|
||||
* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
|
||||
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
|
||||
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
|
||||
* @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
|
||||
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
|
||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||
* @param {number} [options.raw.width] - integral number of pixels wide.
|
||||
@@ -299,6 +300,7 @@ const Sharp = function (input, options) {
|
||||
webpLossless: false,
|
||||
webpNearLossless: false,
|
||||
webpSmartSubsample: false,
|
||||
webpSmartDeblock: false,
|
||||
webpPreset: 'default',
|
||||
webpEffort: 4,
|
||||
webpMinSize: false,
|
||||
@@ -348,6 +350,7 @@ const Sharp = function (input, options) {
|
||||
timeoutSeconds: 0,
|
||||
linearA: [],
|
||||
linearB: [],
|
||||
pdfBackground: [255, 255, 255, 255],
|
||||
// Function to notify of libvips warnings
|
||||
debuglog: warning => {
|
||||
this.emit('warning', warning);
|
||||
@@ -447,6 +450,7 @@ Object.assign(Sharp.prototype, { clone });
|
||||
|
||||
/**
|
||||
* Export constructor.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = Sharp;
|
||||
|
||||
51
lib/index.d.ts
vendored
@@ -244,14 +244,14 @@ declare namespace sharp {
|
||||
* @param tint Parsed by the color module.
|
||||
* @returns A sharp instance that can be used to chain operations
|
||||
*/
|
||||
tint(tint: Color): Sharp;
|
||||
tint(tint: Colour | Color): Sharp;
|
||||
|
||||
/**
|
||||
* Convert to 8-bit greyscale; 256 shades of grey.
|
||||
* This is a linear operation.
|
||||
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
|
||||
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
||||
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
|
||||
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
|
||||
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel.
|
||||
* An alpha channel may be present, and will be unchanged by the operation.
|
||||
* @param greyscale true to enable and false to disable (defaults to true)
|
||||
* @returns A sharp instance that can be used to chain operations
|
||||
@@ -401,7 +401,7 @@ declare namespace sharp {
|
||||
/**
|
||||
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
||||
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||
*
|
||||
* In the case of a 2x2 matrix, the transform is:
|
||||
@@ -799,8 +799,6 @@ declare namespace sharp {
|
||||
* Use tile-based deep zoom (image pyramid) output.
|
||||
* Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
|
||||
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
|
||||
*
|
||||
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
||||
* @param tile tile options
|
||||
* @throws {Error} Invalid options
|
||||
* @returns A sharp instance that can be used to chain operations
|
||||
@@ -935,6 +933,8 @@ declare namespace sharp {
|
||||
subifd?: number | undefined;
|
||||
/** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
|
||||
level?: number | undefined;
|
||||
/** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
|
||||
pdfBackground?: Colour | Color | undefined;
|
||||
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
|
||||
animated?: boolean | undefined;
|
||||
/** Describes raw pixel input image data. See raw() for pixel ordering. */
|
||||
@@ -969,7 +969,7 @@ declare namespace sharp {
|
||||
interface Raw {
|
||||
width: number;
|
||||
height: number;
|
||||
channels: 1 | 2 | 3 | 4;
|
||||
channels: Channels;
|
||||
}
|
||||
|
||||
interface CreateRaw extends Raw {
|
||||
@@ -977,15 +977,17 @@ declare namespace sharp {
|
||||
premultiplied?: boolean | undefined;
|
||||
}
|
||||
|
||||
type CreateChannels = 3 | 4;
|
||||
|
||||
interface Create {
|
||||
/** Number of pixels wide. */
|
||||
width: number;
|
||||
/** Number of pixels high. */
|
||||
height: number;
|
||||
/** Number of bands e.g. 3 for RGB, 4 for RGBA */
|
||||
channels: Channels;
|
||||
/** Number of bands, 3 for RGB, 4 for RGBA */
|
||||
channels: CreateChannels;
|
||||
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
|
||||
background: Color;
|
||||
background: Colour | Color;
|
||||
/** Describes a noise to be created. */
|
||||
noise?: Noise | undefined;
|
||||
}
|
||||
@@ -1069,9 +1071,13 @@ declare namespace sharp {
|
||||
/** Number of pixels per inch (DPI), if present */
|
||||
density?: number | undefined;
|
||||
/** String containing JPEG chroma subsampling, 4:2:0 or 4:4:4 for RGB, 4:2:0:4 or 4:4:4:4 for CMYK */
|
||||
chromaSubsampling: string;
|
||||
chromaSubsampling?: string | undefined;
|
||||
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
||||
isProgressive?: boolean | undefined;
|
||||
/** Boolean indicating whether the image is palette-based (GIF, PNG). */
|
||||
isPalette?: boolean | undefined;
|
||||
/** Number of bits per sample for each channel (GIF, PNG). */
|
||||
bitsPerSample?: number | undefined;
|
||||
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
||||
pages?: number | undefined;
|
||||
/** Number of pixels high each page in a multi-page image will be. */
|
||||
@@ -1098,8 +1104,8 @@ declare namespace sharp {
|
||||
tifftagPhotoshop?: Buffer | undefined;
|
||||
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
||||
compression?: 'av1' | 'hevc';
|
||||
/** Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value */
|
||||
background?: { r: number; g: number; b: number } | number;
|
||||
/** Default background colour, if present, for PNG (bKGD) and GIF images */
|
||||
background?: { r: number; g: number; b: number } | { gray: number };
|
||||
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
|
||||
levels?: LevelMetadata[] | undefined;
|
||||
/** Number of Sub Image File Directories in an OME-TIFF image */
|
||||
@@ -1339,7 +1345,7 @@ declare namespace sharp {
|
||||
|
||||
interface RotateOptions {
|
||||
/** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
|
||||
background?: Color | undefined;
|
||||
background?: Colour | Color | undefined;
|
||||
}
|
||||
|
||||
type Precision = 'integer' | 'float' | 'approximate';
|
||||
@@ -1355,7 +1361,7 @@ declare namespace sharp {
|
||||
|
||||
interface FlattenOptions {
|
||||
/** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
|
||||
background?: Color | undefined;
|
||||
background?: Colour | Color | undefined;
|
||||
}
|
||||
|
||||
interface NegateOptions {
|
||||
@@ -1380,7 +1386,7 @@ declare namespace sharp {
|
||||
/** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
|
||||
position?: number | string | undefined;
|
||||
/** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
||||
background?: Color | undefined;
|
||||
background?: Colour | Color | undefined;
|
||||
/** The kernel to use for image reduction. (optional, default 'lanczos3') */
|
||||
kernel?: keyof KernelEnum | undefined;
|
||||
/** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
|
||||
@@ -1423,14 +1429,14 @@ declare namespace sharp {
|
||||
/** single pixel count to right edge (optional, default 0) */
|
||||
right?: number | undefined;
|
||||
/** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
|
||||
background?: Color | undefined;
|
||||
background?: Colour | Color | undefined;
|
||||
/** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
|
||||
extendWith?: ExtendWith | undefined;
|
||||
}
|
||||
|
||||
interface TrimOptions {
|
||||
/** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
|
||||
background?: Color | undefined;
|
||||
background?: Colour | Color | undefined;
|
||||
/** Allowed difference from the above colour, a positive number. (optional, default 10) */
|
||||
threshold?: number | undefined;
|
||||
/** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
|
||||
@@ -1441,8 +1447,8 @@ declare namespace sharp {
|
||||
depth?: 'char' | 'uchar' | 'short' | 'ushort' | 'int' | 'uint' | 'float' | 'complex' | 'double' | 'dpcomplex';
|
||||
}
|
||||
|
||||
/** 3 for sRGB, 4 for CMYK */
|
||||
type Channels = 3 | 4;
|
||||
/** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
|
||||
type Channels = 1 | 2 | 3 | 4;
|
||||
|
||||
interface RGBA {
|
||||
r?: number | undefined;
|
||||
@@ -1451,7 +1457,8 @@ declare namespace sharp {
|
||||
alpha?: number | undefined;
|
||||
}
|
||||
|
||||
type Color = string | RGBA;
|
||||
type Colour = string | RGBA;
|
||||
type Color = Colour;
|
||||
|
||||
interface Kernel {
|
||||
/** width of the kernel in pixels. */
|
||||
@@ -1576,7 +1583,7 @@ declare namespace sharp {
|
||||
size: number;
|
||||
width: number;
|
||||
height: number;
|
||||
channels: 1 | 2 | 3 | 4;
|
||||
channels: Channels;
|
||||
/** indicating if premultiplication was used */
|
||||
premultiplied: boolean;
|
||||
/** Only defined when using a crop strategy */
|
||||
|
||||
18
lib/input.js
@@ -8,7 +8,7 @@ const is = require('./is');
|
||||
const sharp = require('./sharp');
|
||||
|
||||
/**
|
||||
* Justication alignment
|
||||
* Justification alignment
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
@@ -24,9 +24,9 @@ const align = {
|
||||
* @private
|
||||
*/
|
||||
function _inputOptionsFromObject (obj) {
|
||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd } = obj;
|
||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd].some(is.defined)
|
||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd }
|
||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground } = obj;
|
||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground].some(is.defined)
|
||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -222,6 +222,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
|
||||
}
|
||||
}
|
||||
// PDF background colour
|
||||
if (is.defined(inputOptions.pdfBackground)) {
|
||||
this._setBackgroundColourOption('pdfBackground', inputOptions.pdfBackground);
|
||||
}
|
||||
// Create new image
|
||||
if (is.defined(inputOptions.create)) {
|
||||
if (
|
||||
@@ -430,15 +434,16 @@ function _isStreamInput () {
|
||||
* - `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
|
||||
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||
* - `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
||||
* - `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
||||
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||
* - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
||||
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||
* - `pagePrimary`: Number of the primary page in a HEIF image
|
||||
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images
|
||||
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||
@@ -639,6 +644,7 @@ function stats (callback) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with input-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -128,7 +128,7 @@ function flop (flop) {
|
||||
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||
*
|
||||
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
|
||||
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
|
||||
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
|
||||
*
|
||||
* In the case of a 2x2 matrix, the transform is:
|
||||
@@ -930,6 +930,7 @@ function modulate (options) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with operation-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -623,6 +623,7 @@ function png (options) {
|
||||
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
||||
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
||||
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
||||
* @param {boolean} [options.smartDeblock=false] - auto-adjust the deblocking filter, can improve low contrast edges (slow)
|
||||
* @param {string} [options.preset='default'] - named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text
|
||||
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)
|
||||
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||
@@ -658,6 +659,9 @@ function webp (options) {
|
||||
if (is.defined(options.smartSubsample)) {
|
||||
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
|
||||
}
|
||||
if (is.defined(options.smartDeblock)) {
|
||||
this._setBooleanOption('webpSmartDeblock', options.smartDeblock);
|
||||
}
|
||||
if (is.defined(options.preset)) {
|
||||
if (is.string(options.preset) && is.inArray(options.preset, ['default', 'photo', 'picture', 'drawing', 'icon', 'text'])) {
|
||||
this.options.webpPreset = options.preset;
|
||||
@@ -1123,8 +1127,6 @@ function heif (options) {
|
||||
* The prebuilt binaries do not include this - see
|
||||
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
||||
*
|
||||
* Image metadata (EXIF, XMP) is unsupported.
|
||||
*
|
||||
* @since 0.31.3
|
||||
*
|
||||
* @param {Object} [options] - output options
|
||||
@@ -1132,7 +1134,9 @@ function heif (options) {
|
||||
* @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
|
||||
* @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality)
|
||||
* @param {boolean} [options.lossless=false] - use lossless compression
|
||||
* @param {number} [options.effort=7] - CPU effort, between 3 (fastest) and 9 (slowest)
|
||||
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 9 (slowest)
|
||||
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid options
|
||||
*/
|
||||
@@ -1169,13 +1173,14 @@ function jxl (options) {
|
||||
}
|
||||
}
|
||||
if (is.defined(options.effort)) {
|
||||
if (is.integer(options.effort) && is.inRange(options.effort, 3, 9)) {
|
||||
if (is.integer(options.effort) && is.inRange(options.effort, 1, 9)) {
|
||||
this.options.jxlEffort = options.effort;
|
||||
} else {
|
||||
throw is.invalidParameterError('effort', 'integer between 3 and 9', options.effort);
|
||||
throw is.invalidParameterError('effort', 'integer between 1 and 9', options.effort);
|
||||
}
|
||||
}
|
||||
}
|
||||
trySetAnimationOptions(options, this.options);
|
||||
return this._updateFormatOut('jxl', options);
|
||||
}
|
||||
|
||||
@@ -1227,10 +1232,6 @@ function raw (options) {
|
||||
*
|
||||
* The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
||||
*
|
||||
* Requires libvips compiled with support for libgsf.
|
||||
* The prebuilt binaries do not include this - see
|
||||
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
||||
*
|
||||
* @example
|
||||
* sharp('input.tiff')
|
||||
* .png()
|
||||
@@ -1551,6 +1552,7 @@ function _pipeline (callback, stack) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with output-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -72,7 +72,9 @@ const kernel = {
|
||||
cubic: 'cubic',
|
||||
mitchell: 'mitchell',
|
||||
lanczos2: 'lanczos2',
|
||||
lanczos3: 'lanczos3'
|
||||
lanczos3: 'lanczos3',
|
||||
mks2013: 'mks2013',
|
||||
mks2021: 'mks2021'
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -569,6 +571,7 @@ function trim (options) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp prototype with resize-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -280,6 +280,7 @@ function unblock (options) {
|
||||
|
||||
/**
|
||||
* Decorate the Sharp class with utility-related functions.
|
||||
* @module Sharp
|
||||
* @private
|
||||
*/
|
||||
module.exports = function (Sharp) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-darwin-arm64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with macOS 64-bit ARM",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-darwin-arm64": "1.0.4"
|
||||
"@img/sharp-libvips-darwin-arm64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-darwin-x64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with macOS x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-darwin-x64": "1.0.4"
|
||||
"@img/sharp-libvips-darwin-x64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-arm",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-arm": "1.0.5"
|
||||
"@img/sharp-libvips-linux-arm": "1.1.0-rc3.1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
@@ -32,7 +32,7 @@
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"config": {
|
||||
"glibc": ">=2.28"
|
||||
"glibc": ">=2.31"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-arm64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-arm64": "1.0.4"
|
||||
"@img/sharp-libvips-linux-arm64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
46
npm/linux-ppc64/package.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-ppc64",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) ppc64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lovell/sharp.git",
|
||||
"directory": "npm/linux-ppc64"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-ppc64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
"./sharp.node": "./lib/sharp-linux-ppc64.node",
|
||||
"./package": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"config": {
|
||||
"glibc": ">=2.31"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-s390x",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) s390x",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-s390x": "1.0.4"
|
||||
"@img/sharp-libvips-linux-s390x": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-linux-x64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (glibc) x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-x64": "1.0.4"
|
||||
"@img/sharp-libvips-linux-x64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-linuxmusl-arm64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4"
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-linuxmusl-x64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Linux (musl) x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"preferUnplugged": true,
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.0.4"
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.1.0-rc3"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
{
|
||||
"name": "@img/sharp",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"private": "true",
|
||||
"workspaces": [
|
||||
"darwin-arm64",
|
||||
"darwin-x64",
|
||||
"linux-arm",
|
||||
"linux-arm64",
|
||||
"linux-ppc64",
|
||||
"linux-s390x",
|
||||
"linux-x64",
|
||||
"linuxmusl-arm64",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-wasm32",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with wasm32",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
@@ -31,7 +31,7 @@
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emnapi/runtime": "^1.2.0"
|
||||
"@emnapi/runtime": "^1.3.1"
|
||||
},
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-win32-ia32",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Windows x86 (32-bit)",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@img/sharp-win32-x64",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"description": "Prebuilt sharp for use with Windows x64",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
|
||||
66
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "sharp",
|
||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
||||
"version": "0.33.5-rc.1",
|
||||
"version": "0.33.5",
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"homepage": "https://sharp.pixelplumbing.com",
|
||||
"contributors": [
|
||||
@@ -142,55 +142,55 @@
|
||||
"semver": "^7.6.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-darwin-arm64": "0.33.5-rc.1",
|
||||
"@img/sharp-darwin-x64": "0.33.5-rc.1",
|
||||
"@img/sharp-libvips-darwin-arm64": "1.0.4",
|
||||
"@img/sharp-libvips-darwin-x64": "1.0.4",
|
||||
"@img/sharp-libvips-linux-arm": "1.0.5",
|
||||
"@img/sharp-libvips-linux-arm64": "1.0.4",
|
||||
"@img/sharp-libvips-linux-s390x": "1.0.4",
|
||||
"@img/sharp-libvips-linux-x64": "1.0.4",
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4",
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.0.4",
|
||||
"@img/sharp-linux-arm": "0.33.5-rc.1",
|
||||
"@img/sharp-linux-arm64": "0.33.5-rc.1",
|
||||
"@img/sharp-linux-s390x": "0.33.5-rc.1",
|
||||
"@img/sharp-linux-x64": "0.33.5-rc.1",
|
||||
"@img/sharp-linuxmusl-arm64": "0.33.5-rc.1",
|
||||
"@img/sharp-linuxmusl-x64": "0.33.5-rc.1",
|
||||
"@img/sharp-wasm32": "0.33.5-rc.1",
|
||||
"@img/sharp-win32-ia32": "0.33.5-rc.1",
|
||||
"@img/sharp-win32-x64": "0.33.5-rc.1"
|
||||
"@img/sharp-darwin-arm64": "0.33.5",
|
||||
"@img/sharp-darwin-x64": "0.33.5",
|
||||
"@img/sharp-libvips-darwin-arm64": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-darwin-x64": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-linux-arm": "1.1.0-rc3.1",
|
||||
"@img/sharp-libvips-linux-arm64": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-linux-ppc64": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-linux-s390x": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-linux-x64": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.1.0-rc3",
|
||||
"@img/sharp-linux-arm": "0.33.5",
|
||||
"@img/sharp-linux-arm64": "0.33.5",
|
||||
"@img/sharp-linux-s390x": "0.33.5",
|
||||
"@img/sharp-linux-x64": "0.33.5",
|
||||
"@img/sharp-linuxmusl-arm64": "0.33.5",
|
||||
"@img/sharp-linuxmusl-x64": "0.33.5",
|
||||
"@img/sharp-wasm32": "0.33.5",
|
||||
"@img/sharp-win32-ia32": "0.33.5",
|
||||
"@img/sharp-win32-x64": "0.33.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@emnapi/runtime": "^1.2.0",
|
||||
"@img/sharp-libvips-dev": "1.0.4",
|
||||
"@img/sharp-libvips-dev-wasm32": "1.0.5",
|
||||
"@img/sharp-libvips-win32-ia32": "1.0.4",
|
||||
"@img/sharp-libvips-win32-x64": "1.0.4",
|
||||
"@emnapi/runtime": "^1.3.1",
|
||||
"@img/sharp-libvips-dev": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-dev-wasm32": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-win32-ia32": "1.1.0-rc3",
|
||||
"@img/sharp-libvips-win32-x64": "1.1.0-rc3",
|
||||
"@types/node": "*",
|
||||
"async": "^3.2.5",
|
||||
"cc": "^3.0.1",
|
||||
"emnapi": "^1.2.0",
|
||||
"emnapi": "^1.3.1",
|
||||
"exif-reader": "^2.0.1",
|
||||
"extract-zip": "^2.0.1",
|
||||
"icc": "^3.0.0",
|
||||
"jsdoc-to-markdown": "^8.0.3",
|
||||
"jsdoc-to-markdown": "^9.1.1",
|
||||
"license-checker": "^25.0.1",
|
||||
"mocha": "^10.7.3",
|
||||
"node-addon-api": "^8.1.0",
|
||||
"nyc": "^17.0.0",
|
||||
"mocha": "^11.0.1",
|
||||
"node-addon-api": "^8.3.0",
|
||||
"nyc": "^17.1.0",
|
||||
"prebuild": "^13.0.1",
|
||||
"semistandard": "^17.0.0",
|
||||
"tar-fs": "^3.0.6",
|
||||
"tsd": "^0.31.1"
|
||||
"tsd": "^0.31.2"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"config": {
|
||||
"libvips": ">=8.15.3"
|
||||
"libvips": ">=8.16.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
|
||||
},
|
||||
'targets': [{
|
||||
'target_name': 'libvips-cpp',
|
||||
'target_name': 'libvips-cpp-<(vips_version)',
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
||||
'type': 'shared_library',
|
||||
'defines': [
|
||||
'VIPS_CPLUSPLUS_EXPORTS',
|
||||
'_VIPS_PUBLIC=__declspec(dllexport)',
|
||||
'_ALLOW_KEYWORD_MACROS'
|
||||
],
|
||||
'sources': [
|
||||
@@ -45,6 +45,9 @@
|
||||
'Release': {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
"AdditionalOptions": [
|
||||
"/std:c++17"
|
||||
],
|
||||
'ExceptionHandling': 1,
|
||||
'Optimization': 1,
|
||||
'WholeProgramOptimization': 'true'
|
||||
@@ -83,7 +86,7 @@
|
||||
],
|
||||
'dependencies': [
|
||||
'<!(node -p "require(\'node-addon-api\').gyp")',
|
||||
'libvips-cpp'
|
||||
'libvips-cpp-<(vips_version)'
|
||||
],
|
||||
'variables': {
|
||||
'conditions': [
|
||||
@@ -149,7 +152,7 @@
|
||||
['OS == "mac"', {
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
'libvips-cpp.42.dylib'
|
||||
'libvips-cpp.<(vips_version).dylib'
|
||||
]
|
||||
},
|
||||
'xcode_settings': {
|
||||
@@ -169,9 +172,10 @@
|
||||
],
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
'-l:libvips-cpp.so.42'
|
||||
'-l:libvips-cpp.so.<(vips_version)'
|
||||
],
|
||||
'ldflags': [
|
||||
'-lstdc++fs',
|
||||
'-Wl,-s',
|
||||
'-Wl,--disable-new-dtags',
|
||||
'-Wl,-z,nodelete',
|
||||
@@ -207,14 +211,14 @@
|
||||
}]
|
||||
],
|
||||
'cflags_cc': [
|
||||
'-std=c++0x',
|
||||
'-std=c++17',
|
||||
'-fexceptions',
|
||||
'-Wall',
|
||||
'-Os'
|
||||
],
|
||||
'xcode_settings': {
|
||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
||||
'MACOSX_DEPLOYMENT_TARGET': '10.13',
|
||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
|
||||
'MACOSX_DEPLOYMENT_TARGET': '10.15',
|
||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
||||
'GCC_ENABLE_CPP_RTTI': 'YES',
|
||||
'OTHER_CPLUSPLUSFLAGS': [
|
||||
@@ -234,6 +238,9 @@
|
||||
['OS == "win"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
"AdditionalOptions": [
|
||||
"/std:c++17"
|
||||
],
|
||||
'ExceptionHandling': 1,
|
||||
'Optimization': 1,
|
||||
'WholeProgramOptimization': 'true'
|
||||
|
||||
@@ -109,6 +109,10 @@ namespace sharp {
|
||||
if (HasAttr(input, "subifd")) {
|
||||
descriptor->subifd = AttrAsInt32(input, "subifd");
|
||||
}
|
||||
// // PDF background color
|
||||
if (HasAttr(input, "pdfBackground")) {
|
||||
descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
|
||||
}
|
||||
// Create new image
|
||||
if (HasAttr(input, "createChannels")) {
|
||||
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
||||
@@ -402,6 +406,9 @@ namespace sharp {
|
||||
if (imageType == ImageType::TIFF) {
|
||||
option->set("subifd", descriptor->subifd);
|
||||
}
|
||||
if (imageType == ImageType::PDF) {
|
||||
option->set("background", descriptor->pdfBackground);
|
||||
}
|
||||
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||
image = SetDensity(image, descriptor->density);
|
||||
@@ -506,6 +513,9 @@ namespace sharp {
|
||||
if (imageType == ImageType::TIFF) {
|
||||
option->set("subifd", descriptor->subifd);
|
||||
}
|
||||
if (imageType == ImageType::PDF) {
|
||||
option->set("background", descriptor->pdfBackground);
|
||||
}
|
||||
image = VImage::new_from_file(descriptor->file.data(), option);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||
image = SetDensity(image, descriptor->density);
|
||||
|
||||
20
src/common.h
@@ -15,18 +15,14 @@
|
||||
// Verify platform and compiler compatibility
|
||||
|
||||
#if (VIPS_MAJOR_VERSION < 8) || \
|
||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 15) || \
|
||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 15 && VIPS_MICRO_VERSION < 3)
|
||||
#error "libvips version 8.15.3+ is required - please see https://sharp.pixelplumbing.com/install"
|
||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 16) || \
|
||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 16 && VIPS_MICRO_VERSION < 0)
|
||||
#error "libvips version 8.16.0+ is required - please see https://sharp.pixelplumbing.com/install"
|
||||
#endif
|
||||
|
||||
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
|
||||
#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
|
||||
#endif
|
||||
|
||||
#if (defined(__clang__) && defined(__has_feature))
|
||||
#if (!__has_feature(cxx_range_for))
|
||||
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
|
||||
#if defined(__has_include)
|
||||
#if !__has_include(<filesystem>)
|
||||
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -74,6 +70,7 @@ namespace sharp {
|
||||
int textSpacing;
|
||||
VipsTextWrap textWrap;
|
||||
int textAutofitDpi;
|
||||
std::vector<double> pdfBackground;
|
||||
|
||||
InputDescriptor():
|
||||
buffer(nullptr),
|
||||
@@ -108,7 +105,8 @@ namespace sharp {
|
||||
textRgba(false),
|
||||
textSpacing(0),
|
||||
textWrap(VIPS_TEXT_WRAP_WORD),
|
||||
textAutofitDpi(0) {}
|
||||
textAutofitDpi(0),
|
||||
pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
|
||||
};
|
||||
|
||||
// Convenience methods to access the attributes of a Napi::Object
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
#include <napi.h>
|
||||
#include <vips/vips8>
|
||||
@@ -47,8 +48,11 @@ class MetadataWorker : public Napi::AsyncWorker {
|
||||
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
||||
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_PALETTE) == G_TYPE_INT) {
|
||||
baton->isPalette = image.get_int(VIPS_META_PALETTE);
|
||||
}
|
||||
if (image.get_typeof(VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT) {
|
||||
baton->bitsPerSample = image.get_int(VIPS_META_BITS_PER_SAMPLE);
|
||||
}
|
||||
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
||||
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
||||
@@ -171,8 +175,13 @@ class MetadataWorker : public Napi::AsyncWorker {
|
||||
info.Set("chromaSubsampling", baton->chromaSubsampling);
|
||||
}
|
||||
info.Set("isProgressive", baton->isProgressive);
|
||||
if (baton->paletteBitDepth > 0) {
|
||||
info.Set("paletteBitDepth", baton->paletteBitDepth);
|
||||
info.Set("isPalette", baton->isPalette);
|
||||
if (baton->bitsPerSample > 0) {
|
||||
info.Set("bitsPerSample", baton->bitsPerSample);
|
||||
if (baton->isPalette) {
|
||||
// Deprecated, remove with libvips 8.17.0
|
||||
info.Set("paletteBitDepth", baton->bitsPerSample);
|
||||
}
|
||||
}
|
||||
if (baton->pages > 0) {
|
||||
info.Set("pages", baton->pages);
|
||||
@@ -218,15 +227,15 @@ class MetadataWorker : public Napi::AsyncWorker {
|
||||
info.Set("subifds", baton->subifds);
|
||||
}
|
||||
if (!baton->background.empty()) {
|
||||
Napi::Object background = Napi::Object::New(env);
|
||||
if (baton->background.size() == 3) {
|
||||
Napi::Object background = Napi::Object::New(env);
|
||||
background.Set("r", baton->background[0]);
|
||||
background.Set("g", baton->background[1]);
|
||||
background.Set("b", baton->background[2]);
|
||||
info.Set("background", background);
|
||||
} else {
|
||||
info.Set("background", baton->background[0]);
|
||||
background.Set("gray", round(baton->background[0] * 100 / 255));
|
||||
}
|
||||
info.Set("background", background);
|
||||
}
|
||||
info.Set("hasProfile", baton->hasProfile);
|
||||
info.Set("hasAlpha", baton->hasAlpha);
|
||||
|
||||
@@ -24,7 +24,8 @@ struct MetadataBaton {
|
||||
int density;
|
||||
std::string chromaSubsampling;
|
||||
bool isProgressive;
|
||||
int paletteBitDepth;
|
||||
bool isPalette;
|
||||
int bitsPerSample;
|
||||
int pages;
|
||||
int pageHeight;
|
||||
int loop;
|
||||
@@ -59,7 +60,8 @@ struct MetadataBaton {
|
||||
channels(0),
|
||||
density(0),
|
||||
isProgressive(false),
|
||||
paletteBitDepth(0),
|
||||
isPalette(false),
|
||||
bitsPerSample(0),
|
||||
pages(0),
|
||||
pageHeight(0),
|
||||
loop(-1),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
@@ -20,17 +21,6 @@
|
||||
#include "operations.h"
|
||||
#include "pipeline.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define STAT64_STRUCT __stat64
|
||||
#define STAT64_FUNCTION _stat64
|
||||
#elif defined(_LARGEFILE64_SOURCE)
|
||||
#define STAT64_STRUCT stat64
|
||||
#define STAT64_FUNCTION stat64
|
||||
#else
|
||||
#define STAT64_STRUCT stat
|
||||
#define STAT64_FUNCTION stat
|
||||
#endif
|
||||
|
||||
class PipelineWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
|
||||
@@ -929,6 +919,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
->set("lossless", baton->webpLossless)
|
||||
->set("near_lossless", baton->webpNearLossless)
|
||||
->set("smart_subsample", baton->webpSmartSubsample)
|
||||
->set("smart_deblock", baton->webpSmartDeblock)
|
||||
->set("preset", baton->webpPreset)
|
||||
->set("effort", baton->webpEffort)
|
||||
->set("min_size", baton->webpMinSize)
|
||||
@@ -1136,6 +1127,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
->set("lossless", baton->webpLossless)
|
||||
->set("near_lossless", baton->webpNearLossless)
|
||||
->set("smart_subsample", baton->webpSmartSubsample)
|
||||
->set("smart_deblock", baton->webpSmartDeblock)
|
||||
->set("preset", baton->webpPreset)
|
||||
->set("effort", baton->webpEffort)
|
||||
->set("min_size", baton->webpMinSize)
|
||||
@@ -1304,9 +1296,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
Callback().Call(Receiver().Value(), { env.Null(), data, info });
|
||||
} else {
|
||||
// Add file size to info
|
||||
struct STAT64_STRUCT st;
|
||||
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
|
||||
info.Set("size", static_cast<uint32_t>(st.st_size));
|
||||
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
|
||||
try {
|
||||
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
|
||||
info.Set("size", size);
|
||||
} catch (...) {}
|
||||
}
|
||||
Callback().Call(Receiver().Value(), { env.Null(), info });
|
||||
}
|
||||
@@ -1419,6 +1413,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
{"lossless", baton->webpLossless ? "true" : "false"},
|
||||
{"near_lossless", baton->webpNearLossless ? "true" : "false"},
|
||||
{"smart_subsample", baton->webpSmartSubsample ? "true" : "false"},
|
||||
{"smart_deblock", baton->webpSmartDeblock ? "true" : "false"},
|
||||
{"preset", vips_enum_nick(VIPS_TYPE_FOREIGN_WEBP_PRESET, baton->webpPreset)},
|
||||
{"min_size", baton->webpMinSize ? "true" : "false"},
|
||||
{"mixed", baton->webpMixed ? "true" : "false"},
|
||||
@@ -1676,6 +1671,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
||||
baton->webpLossless = sharp::AttrAsBool(options, "webpLossless");
|
||||
baton->webpNearLossless = sharp::AttrAsBool(options, "webpNearLossless");
|
||||
baton->webpSmartSubsample = sharp::AttrAsBool(options, "webpSmartSubsample");
|
||||
baton->webpSmartDeblock = sharp::AttrAsBool(options, "webpSmartDeblock");
|
||||
baton->webpPreset = sharp::AttrAsEnum<VipsForeignWebpPreset>(options, "webpPreset", VIPS_TYPE_FOREIGN_WEBP_PRESET);
|
||||
baton->webpEffort = sharp::AttrAsUint32(options, "webpEffort");
|
||||
baton->webpMinSize = sharp::AttrAsBool(options, "webpMinSize");
|
||||
|
||||
@@ -157,6 +157,7 @@ struct PipelineBaton {
|
||||
bool webpNearLossless;
|
||||
bool webpLossless;
|
||||
bool webpSmartSubsample;
|
||||
bool webpSmartDeblock;
|
||||
VipsForeignWebpPreset webpPreset;
|
||||
int webpEffort;
|
||||
bool webpMinSize;
|
||||
@@ -328,6 +329,7 @@ struct PipelineBaton {
|
||||
webpNearLossless(false),
|
||||
webpLossless(false),
|
||||
webpSmartSubsample(false),
|
||||
webpSmartDeblock(false),
|
||||
webpPreset(VIPS_FOREIGN_WEBP_PRESET_DEFAULT),
|
||||
webpEffort(4),
|
||||
webpMinSize(false),
|
||||
|
||||
@@ -15,7 +15,6 @@ const width = 720;
|
||||
const height = 480;
|
||||
|
||||
sharp.concurrency(1);
|
||||
sharp.simd(true);
|
||||
|
||||
const timer = setInterval(function () {
|
||||
console.dir(sharp.counters());
|
||||
|
||||
@@ -12,7 +12,6 @@ const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(false);
|
||||
sharp.simd(true);
|
||||
|
||||
const min = 320;
|
||||
const max = 960;
|
||||
|
||||
BIN
test/fixtures/bgbn4a08.png
vendored
Normal file
|
After Width: | Height: | Size: 140 B |
BIN
test/fixtures/bggn4a16.png
vendored
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
test/fixtures/expected/gravity-center-width.webp
vendored
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 9.3 KiB |
BIN
test/fixtures/expected/tint-blue.jpg
vendored
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/tint-cmyk.jpg
vendored
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
BIN
test/fixtures/expected/tint-green.jpg
vendored
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
test/fixtures/expected/tint-red.jpg
vendored
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/tint-sepia.jpg
vendored
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/webp-alpha-80.webp
vendored
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 152 KiB |
2
test/fixtures/index.js
vendored
@@ -80,6 +80,8 @@ module.exports = {
|
||||
inputPngWithGreyAlpha: getPath('grey-8bit-alpha.png'),
|
||||
inputPngWithOneColor: getPath('2x2_fdcce6.png'),
|
||||
inputPngWithTransparency16bit: getPath('tbgn2c16.png'), // http://www.schaik.com/pngsuite/tbgn2c16.png
|
||||
inputPng8BitGreyBackground: getPath('bgbn4a08.png'), // http://www.schaik.com/pngsuite/bgbn4a08.png
|
||||
inputPng16BitGreyBackground: getPath('bggn4a16.png'), // http://www.schaik.com/pngsuite/bggn4a16.png
|
||||
inputPng16BitGreyAlpha: getPath('16-bit-grey-alpha.png'), // CC-BY-NC-SA florc http://www.colourlovers.com/pattern/50713/pat
|
||||
inputPngOverlayLayer0: getPath('alpha-layer-0-background.png'),
|
||||
inputPngOverlayLayer1: getPath('alpha-layer-1-fill.png'),
|
||||
|
||||
@@ -713,4 +713,9 @@ sharp(input).composite([
|
||||
density: 72,
|
||||
failOn: "truncated"
|
||||
}
|
||||
])
|
||||
])
|
||||
|
||||
const colour: sharp.Colour = '#fff';
|
||||
const color: sharp.Color = '#fff';
|
||||
sharp({ pdfBackground: colour });
|
||||
sharp({ pdfBackground: color });
|
||||
|
||||
@@ -34,6 +34,7 @@ describe('AVIF', () => {
|
||||
// Math.round(13.40625) = 13
|
||||
height: 13,
|
||||
isProgressive: false,
|
||||
isPalette: false,
|
||||
space: 'srgb',
|
||||
width: 32
|
||||
});
|
||||
@@ -55,6 +56,8 @@ describe('AVIF', () => {
|
||||
hasProfile: false,
|
||||
height: 26,
|
||||
isProgressive: false,
|
||||
isPalette: false,
|
||||
bitsPerSample: 8,
|
||||
pagePrimary: 0,
|
||||
pages: 1,
|
||||
space: 'srgb',
|
||||
@@ -77,6 +80,8 @@ describe('AVIF', () => {
|
||||
hasProfile: false,
|
||||
height: 13,
|
||||
isProgressive: false,
|
||||
isPalette: false,
|
||||
bitsPerSample: 8,
|
||||
pagePrimary: 0,
|
||||
pages: 1,
|
||||
space: 'srgb',
|
||||
@@ -100,6 +105,8 @@ describe('AVIF', () => {
|
||||
hasProfile: false,
|
||||
height: 300,
|
||||
isProgressive: false,
|
||||
isPalette: false,
|
||||
bitsPerSample: 8,
|
||||
pagePrimary: 0,
|
||||
pages: 1,
|
||||
space: 'srgb',
|
||||
@@ -124,6 +131,8 @@ describe('AVIF', () => {
|
||||
hasProfile: false,
|
||||
height: 26,
|
||||
isProgressive: false,
|
||||
isPalette: false,
|
||||
bitsPerSample: 8,
|
||||
pagePrimary: 0,
|
||||
pages: 1,
|
||||
space: 'srgb',
|
||||
|
||||
@@ -72,7 +72,7 @@ describe('failOn', () => {
|
||||
|
||||
it('returns errors to callback for truncated JPEG', function (done) {
|
||||
sharp(fixtures.inputJpgTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
|
||||
assert.ok(err.message.includes('VipsJpeg: Premature end of'), err);
|
||||
assert.ok(err.message.includes('VipsJpeg: premature end of'), err);
|
||||
assert.strictEqual(data, undefined);
|
||||
assert.strictEqual(info, undefined);
|
||||
done();
|
||||
@@ -95,7 +95,7 @@ describe('failOn', () => {
|
||||
throw new Error('Expected rejection');
|
||||
})
|
||||
.catch(err => {
|
||||
done(err.message.includes('VipsJpeg: Premature end of') ? undefined : err);
|
||||
done(err.message.includes('VipsJpeg: premature end of') ? undefined : err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -893,6 +893,27 @@ describe('Input/output', function () {
|
||||
sharp({ subifd: 1.2 });
|
||||
}, /Expected integer between -1 and 100000 for subifd but received 1.2 of type number/);
|
||||
});
|
||||
it('Valid pdfBackground property (string)', function () {
|
||||
sharp({ pdfBackground: '#00ff00' });
|
||||
});
|
||||
it('Valid pdfBackground property (object)', function () {
|
||||
sharp({ pdfBackground: { r: 0, g: 255, b: 0 } });
|
||||
});
|
||||
it('Invalid pdfBackground property (string) throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp({ pdfBackground: '00ff00' });
|
||||
}, /Unable to parse color from string/);
|
||||
});
|
||||
it('Invalid pdfBackground property (number) throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp({ pdfBackground: 255 });
|
||||
}, /Expected object or string for background/);
|
||||
});
|
||||
it('Invalid pdfBackground property (object)', function () {
|
||||
assert.throws(function () {
|
||||
sharp({ pdfBackground: { red: 0, green: 255, blue: 0 } });
|
||||
}, /Unable to parse color from object/);
|
||||
});
|
||||
});
|
||||
|
||||
it('Fails when writing to missing directory', async () => {
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('libvips binaries', function () {
|
||||
});
|
||||
it('arch', () => {
|
||||
const [, arch] = libvips.runtimePlatformArch().split('-');
|
||||
assert.strict(['arm', 'arm64', 'ia32', 'x64'].includes(arch));
|
||||
assert.strict(['arm', 'arm64', 'ia32', 'x64', 'ppc64'].includes(arch));
|
||||
});
|
||||
it('isUnsupportedNodeRuntime', () => {
|
||||
assert.strictEqual(libvips.isUnsupportedNodeRuntime(), undefined);
|
||||
@@ -179,7 +179,7 @@ describe('libvips binaries', function () {
|
||||
process.env.npm_config_arch = 's390x';
|
||||
process.env.npm_config_libc = '';
|
||||
const locatorHash = libvips.yarnLocator();
|
||||
assert.strictEqual(locatorHash, 'c4ea54fdc1');
|
||||
assert.strictEqual(locatorHash, '9b2ea457de');
|
||||
delete process.env.npm_config_platform;
|
||||
delete process.env.npm_config_arch;
|
||||
delete process.env.npm_config_libc;
|
||||
|
||||
@@ -201,6 +201,48 @@ describe('Image metadata', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with greyscale bKGD chunk - 8 bit', async () => {
|
||||
const data = await sharp(fixtures.inputPng8BitGreyBackground).metadata();
|
||||
assert.deepStrictEqual(data, {
|
||||
background: {
|
||||
gray: 0
|
||||
},
|
||||
bitsPerSample: 8,
|
||||
channels: 2,
|
||||
density: 72,
|
||||
depth: 'uchar',
|
||||
format: 'png',
|
||||
hasAlpha: true,
|
||||
hasProfile: false,
|
||||
height: 32,
|
||||
isPalette: false,
|
||||
isProgressive: false,
|
||||
space: 'b-w',
|
||||
width: 32
|
||||
});
|
||||
});
|
||||
|
||||
it('PNG with greyscale bKGD chunk - 16 bit', async () => {
|
||||
const data = await sharp(fixtures.inputPng16BitGreyBackground).metadata();
|
||||
assert.deepStrictEqual(data, {
|
||||
background: {
|
||||
gray: 67
|
||||
},
|
||||
bitsPerSample: 16,
|
||||
channels: 2,
|
||||
density: 72,
|
||||
depth: 'ushort',
|
||||
format: 'png',
|
||||
hasAlpha: true,
|
||||
hasProfile: false,
|
||||
height: 32,
|
||||
isPalette: false,
|
||||
isProgressive: false,
|
||||
space: 'grey16',
|
||||
width: 32
|
||||
});
|
||||
});
|
||||
|
||||
it('WebP', function (done) {
|
||||
sharp(fixtures.inputWebP).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
@@ -878,6 +920,8 @@ describe('Image metadata', function () {
|
||||
channels: 3,
|
||||
depth: 'uchar',
|
||||
isProgressive: false,
|
||||
isPalette: false,
|
||||
bitsPerSample: 8,
|
||||
pages: 1,
|
||||
pagePrimary: 0,
|
||||
compression: 'av1',
|
||||
@@ -931,7 +975,7 @@ describe('Image metadata', function () {
|
||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||
.metadata(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
assert.ok(err.message.includes('Input file has corrupt header: VipsJpeg: Premature end of'), err);
|
||||
assert.ok(err.message.includes('Input file has corrupt header: VipsJpeg: premature end of'), err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -940,7 +984,7 @@ describe('Image metadata', function () {
|
||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||
.metadata(function (err) {
|
||||
assert.strictEqual(true, !!err);
|
||||
assert.ok(err.message.includes('Input buffer has corrupt header: VipsJpeg: Premature end of'), err);
|
||||
assert.ok(err.message.includes('Input buffer has corrupt header: VipsJpeg: premature end of'), err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,8 +15,8 @@ const assertNormalized = function (data) {
|
||||
min = Math.min(min, data[i]);
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.ok([254, 255].includes(max));
|
||||
assert.strictEqual(0, min, 'min too high');
|
||||
assert.ok(max > 248, 'max too low');
|
||||
};
|
||||
|
||||
describe('Normalization', function () {
|
||||
|
||||
@@ -146,6 +146,8 @@ describe('PNG', function () {
|
||||
density: 72,
|
||||
depth: 'uchar',
|
||||
isProgressive: false,
|
||||
isPalette: true,
|
||||
bitsPerSample: 8,
|
||||
paletteBitDepth: 8,
|
||||
hasProfile: false,
|
||||
hasAlpha: false
|
||||
@@ -218,8 +220,10 @@ describe('PNG', function () {
|
||||
.png({ colours: 2, palette: false })
|
||||
.toBuffer();
|
||||
|
||||
const { channels, paletteBitDepth, size, space } = await sharp(data).metadata();
|
||||
const { channels, isPalette, bitsPerSample, paletteBitDepth, size, space } = await sharp(data).metadata();
|
||||
assert.strictEqual(channels, 1);
|
||||
assert.strictEqual(isPalette, false);
|
||||
assert.strictEqual(bitsPerSample, 1);
|
||||
assert.strictEqual(paletteBitDepth, undefined);
|
||||
assert.strictEqual(size, 89);
|
||||
assert.strictEqual(space, 'b-w');
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('Image Stats', function () {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.332915340666659));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.7883011147075762));
|
||||
|
||||
const { r, g, b } = stats.dominant;
|
||||
@@ -272,7 +272,7 @@ describe('Image Stats', function () {
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.51758075132966));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 9.959951636662941));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 9.971384105278734));
|
||||
|
||||
const { r, g, b } = stats.dominant;
|
||||
assert.strictEqual(40, r);
|
||||
@@ -336,8 +336,8 @@ describe('Image Stats', function () {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 6.087309412541799));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 2.9250574456255682));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 6.08118048729375));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 2.936767879098001));
|
||||
|
||||
const { r, g, b } = stats.dominant;
|
||||
assert.strictEqual(120, r);
|
||||
@@ -484,7 +484,7 @@ describe('Image Stats', function () {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.332915340666659));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||
|
||||
const { r, g, b } = stats.dominant;
|
||||
@@ -552,7 +552,7 @@ describe('Image Stats', function () {
|
||||
|
||||
return pipeline.stats().then(function (stats) {
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.332915340666659));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||
|
||||
const { r, g, b } = stats.dominant;
|
||||
@@ -615,7 +615,7 @@ describe('Image Stats', function () {
|
||||
it('File in, Promise out', function () {
|
||||
return sharp(fixtures.inputJpg).stats().then(function (stats) {
|
||||
assert.strictEqual(true, stats.isOpaque);
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.332915340666659));
|
||||
assert.strictEqual(true, isInAcceptableRange(stats.sharpness, 0.788301114707569));
|
||||
|
||||
const { r, g, b } = stats.dominant;
|
||||
@@ -682,8 +682,8 @@ describe('Image Stats', function () {
|
||||
return Promise
|
||||
.all([original, blurred])
|
||||
.then(([original, blurred]) => {
|
||||
assert.strictEqual(true, isInAcceptableRange(original.sharpness, 0.7883011147075476));
|
||||
assert.strictEqual(true, isInAcceptableRange(blurred.sharpness, 0.4791559805997398));
|
||||
assert.strictEqual(true, isInAcceptableRange(original.sharpness, 0.789046400439488));
|
||||
assert.strictEqual(true, isInAcceptableRange(blurred.sharpness, 0.47985138441709047));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const eachLimit = require('async/eachLimit');
|
||||
const extractZip = require('extract-zip');
|
||||
|
||||
const sharp = require('../../');
|
||||
@@ -31,11 +30,10 @@ const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, d
|
||||
});
|
||||
});
|
||||
// Verify each tile is <= expectedSize
|
||||
eachLimit(tiles, 8, function (tile, done) {
|
||||
sharp(tile).metadata(function (err, metadata) {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
Promise.all(tiles.map(function (tile) {
|
||||
return sharp(tile)
|
||||
.metadata()
|
||||
.then(function (metadata) {
|
||||
assert.strictEqual('jpeg', metadata.format);
|
||||
assert.strictEqual('srgb', metadata.space);
|
||||
assert.strictEqual(3, metadata.channels);
|
||||
@@ -43,10 +41,10 @@ const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, d
|
||||
assert.strictEqual(false, metadata.hasAlpha);
|
||||
assert.strictEqual(true, metadata.width <= expectedSize);
|
||||
assert.strictEqual(true, metadata.height <= expectedSize);
|
||||
done();
|
||||
}
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
}))
|
||||
.then(() => done())
|
||||
.catch(done);
|
||||
};
|
||||
|
||||
const assertZoomifyTiles = function (directory, expectedTileSize, expectedLevels, done) {
|
||||
@@ -485,7 +483,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
@@ -511,7 +509,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 1, done);
|
||||
});
|
||||
});
|
||||
@@ -532,7 +530,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 5, done);
|
||||
});
|
||||
});
|
||||
@@ -553,7 +551,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 13, done);
|
||||
});
|
||||
});
|
||||
@@ -577,7 +575,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2048, info.width);
|
||||
assert.strictEqual(1536, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertZoomifyTiles(directory, 256, 4, done);
|
||||
});
|
||||
});
|
||||
@@ -596,7 +594,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, stat.isFile());
|
||||
@@ -623,7 +621,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.jpg');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
@@ -660,7 +658,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.png');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
@@ -698,7 +696,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const sample = path.join(directory, '0', '0', '0.webp');
|
||||
sharp(sample).metadata(function (err, metadata) {
|
||||
if (err) throw err;
|
||||
@@ -734,8 +732,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertGoogleTiles(directory, 256, 1, done);
|
||||
});
|
||||
});
|
||||
@@ -756,8 +753,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertGoogleTiles(directory, 256, 5, done);
|
||||
});
|
||||
});
|
||||
@@ -781,8 +777,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2809, info.width);
|
||||
assert.strictEqual(2074, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
|
||||
assert.strictEqual(undefined, info.size);
|
||||
assertGoogleTiles(directory, 256, 5, done);
|
||||
});
|
||||
});
|
||||
@@ -802,7 +797,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
fixtures.assertSimilar(fixtures.expected('tile_centered.jpg'), fs.readFileSync(path.join(directory, '0', '0', '0.jpg')), done);
|
||||
});
|
||||
});
|
||||
@@ -822,7 +817,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
fixtures.assertSimilar(fixtures.expected('tile_centered.jpg'), fs.readFileSync(path.join(directory, '0', '0', '0.jpg')), done);
|
||||
});
|
||||
});
|
||||
@@ -844,7 +839,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const infoJson = require(path.join(directory, 'info.json'));
|
||||
assert.strictEqual('http://iiif.io/api/image/2/context.json', infoJson['@context']);
|
||||
assert.strictEqual(`${id}/${name}`, infoJson['@id']);
|
||||
@@ -874,7 +869,7 @@ describe('Tile', function () {
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
assert.strictEqual(3, info.channels);
|
||||
assert.strictEqual('number', typeof info.size);
|
||||
assert.strictEqual(undefined, info.size);
|
||||
const infoJson = require(path.join(directory, 'info.json'));
|
||||
assert.strictEqual('http://iiif.io/api/image/3/context.json', infoJson['@context']);
|
||||
assert.strictEqual('ImageService3', infoJson.type);
|
||||
|
||||
@@ -102,6 +102,29 @@ describe('WebP', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can produce a different file size using smartDeblock', () =>
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.resize(320, 240)
|
||||
.webp({ quality: 30, smartDeblock: false })
|
||||
.toBuffer()
|
||||
.then(withoutSmartDeblock =>
|
||||
sharp(fixtures.inputPngOverlayLayer0)
|
||||
.resize(320, 240)
|
||||
.webp({ quality: 30, smartDeblock: true })
|
||||
.toBuffer()
|
||||
.then(withSmartDeblock => {
|
||||
assert.strictEqual(true, withSmartDeblock.length !== withoutSmartDeblock.length);
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
it('invalid smartDeblock throws', () => {
|
||||
assert.throws(
|
||||
() => sharp().webp({ smartDeblock: 1 }),
|
||||
/Expected boolean for webpSmartDeblock but received 1 of type number/
|
||||
);
|
||||
});
|
||||
|
||||
it('should produce a different file size with specific preset', () =>
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
|
||||