Compare commits

..

14 Commits

Author SHA1 Message Date
Lovell Fuller
6d04b7c1fa Release v0.34.2 2025-05-20 14:36:42 +01:00
Harshal Bhakta
d4b30b7392 Docs: Update pnpm settings documentation URLs 2025-05-20 13:57:15 +01:00
Lovell Fuller
7f03502003 Docs: upgrade to latest Astro Starlight 2025-05-20 12:57:28 +01:00
Lovell Fuller
63b0a11b5b Tests: remove a possible race condition 2025-05-19 23:21:55 +01:00
Lovell Fuller
c4d6aec48c Docs: Highlight that Windows ARM64 support is experimental 2025-05-19 22:04:08 +01:00
Lovell Fuller
e75ae970ed Ensure PDF scale-on-load optimisation uses background #4398 2025-05-16 14:38:00 +01:00
Lovell Fuller
956d72ddc0 Prerelease v0.34.2-rc.0 2025-05-14 12:37:15 +01:00
Lovell Fuller
00e66efbee Bump deps 2025-05-14 12:37:08 +01:00
Kleis Auke Wolthuizen
db3a4528eb Simplify 94481a9 2025-05-13 19:22:36 +01:00
Kleis Auke Wolthuizen
d36fd5064d Prefer use of bandjoin_const() and list-initialization 2025-05-13 19:22:36 +01:00
Kleis Auke Wolthuizen
8e17c6f518 Prefer use of vips_interpretation_max_alpha()
This also ensures we handle scRGB correctly, see:
e9c5a31552
2025-05-13 19:22:36 +01:00
Lovell Fuller
94481a967e Ensure fit=contain resizing supports multiple alpha channels #4382 2025-05-13 14:31:51 +01:00
Lovell Fuller
32872ef840 TypeScript: ensure metadata response matches reality #4383 2025-05-13 14:26:25 +01:00
Lovell Fuller
7c7f960b60 Ensure support for wide-char filenames on Windows #4391 2025-05-13 08:53:37 +01:00
29 changed files with 171 additions and 92 deletions

View File

@@ -70,10 +70,10 @@ export default defineConfig({
{ label: 'Performance', slug: 'performance' }, { label: 'Performance', slug: 'performance' },
{ label: 'Changelog', slug: 'changelog' } { label: 'Changelog', slug: 'changelog' }
], ],
social: { social: [
openCollective: 'https://opencollective.com/libvips', { icon: 'openCollective', label: 'Open Collective', href: 'https://opencollective.com/libvips' },
github: 'https://github.com/lovell/sharp' { icon: 'github', label: 'GitHub', href: 'https://github.com/lovell/sharp' }
} ]
}) })
] ]
}); });

View File

@@ -11,7 +11,7 @@
"astro": "astro" "astro": "astro"
}, },
"dependencies": { "dependencies": {
"@astrojs/starlight": "^0.32.3", "@astrojs/starlight": "^0.34.3",
"astro": "^5.5.3" "astro": "^5.7.13"
} }
} }

View File

@@ -626,6 +626,9 @@ Use these AVIF options for output image.
AVIF image sequences are not supported. AVIF image sequences are not supported.
Prebuilt binaries support a bitdepth of 8 only. Prebuilt binaries support a bitdepth of 8 only.
This feature is experimental on the Windows ARM64 platform
and requires a CPU with ARM64v8.4 or later.
**Throws**: **Throws**:

View File

@@ -6,22 +6,32 @@ title: Changelog
Requires libvips v8.16.1 Requires libvips v8.16.1
### v0.34.2 - TBD ### v0.34.2 - 20th May 2025
* Ensure animated GIF to WebP conversion retains loop (regression in 0.34.0). * Ensure animated GIF to WebP conversion retains loop (regression in 0.34.0).
[#3394](https://github.com/lovell/sharp/issues/3394) [#3394](https://github.com/lovell/sharp/issues/3394)
* Ensure `pdfBackground` constructor property is used. * Ensure `pdfBackground` constructor property is used.
[#4207](https://github.com/lovell/sharp/pull/4207) [#4207](https://github.com/lovell/sharp/pull/4207)
[#4398](https://github.com/lovell/sharp/issues/4398)
* Add support for prebuilt Windows ARM64 binaries. * Add experimental support for prebuilt Windows ARM64 binaries.
[#4375](https://github.com/lovell/sharp/pull/4375) [#4375](https://github.com/lovell/sharp/pull/4375)
[@hans00](https://github.com/hans00) [@hans00](https://github.com/hans00)
* Ensure resizing with a `fit` of `contain` supports multiple alpha channels.
[#4382](https://github.com/lovell/sharp/issues/4382)
* TypeScript: Ensure `metadata` response more closely matches reality.
[#4383](https://github.com/lovell/sharp/issues/4383)
* TypeScript: Ensure `smartDeblock` property is included in WebP definition. * TypeScript: Ensure `smartDeblock` property is included in WebP definition.
[#4387](https://github.com/lovell/sharp/pull/4387) [#4387](https://github.com/lovell/sharp/pull/4387)
[@Stephen-X](https://github.com/Stephen-X) [@Stephen-X](https://github.com/Stephen-X)
* Ensure support for wide-character filenames on Windows (regression in 0.34.0).
[#4391](https://github.com/lovell/sharp/issues/4391)
### v0.34.1 - 7th April 2025 ### v0.34.1 - 7th April 2025
* TypeScript: Ensure new `autoOrient` property is optional. * TypeScript: Ensure new `autoOrient` property is optional.

View File

@@ -21,7 +21,7 @@ pnpm add sharp
``` ```
When using `pnpm`, you may need to add `sharp` to When using `pnpm`, you may need to add `sharp` to
[ignoredBuiltDependencies](https://pnpm.io/package_json#pnpmignoredbuiltdependencies) [ignoredBuiltDependencies](https://pnpm.io/settings#ignoredbuiltdependencies)
to silence warnings. to silence warnings.
```sh ```sh
@@ -53,7 +53,7 @@ Ready-compiled sharp and libvips binaries are provided for use on the most commo
* Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2) * Linux x64 (glibc >= 2.26, musl >= 1.2.2, CPU with SSE4.2)
* Windows x64 * Windows x64
* Windows x86 * Windows x86
* Windows ARM64 * Windows ARM64 (experimental, CPU with ARMv8.4 required for all features)
This provides support for the This provides support for the
JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats. JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats.
@@ -94,7 +94,7 @@ Use the [supportedArchitectures](https://yarnpkg.com/configuration/yarnrc#suppor
### pnpm v8+ ### pnpm v8+
Use the [supportedArchitectures](https://pnpm.io/package_json#pnpmsupportedarchitectures) configuration. Use the [supportedArchitectures](https://pnpm.io/settings#supportedarchitectures) configuration.
## Custom libvips ## Custom libvips
@@ -134,7 +134,7 @@ npm install --save node-addon-api node-gyp
``` ```
When using `pnpm`, you may need to add `sharp` to When using `pnpm`, you may need to add `sharp` to
[onlyBuiltDependencies](https://pnpm.io/package_json#pnpmonlybuiltdependencies) [onlyBuiltDependencies](https://pnpm.io/settings#onlybuiltdependencies)
to ensure the installation script can be run. to ensure the installation script can be run.
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags

53
lib/index.d.ts vendored
View File

@@ -1146,13 +1146,13 @@ declare namespace sharp {
/** Number value of the EXIF Orientation header, if present */ /** Number value of the EXIF Orientation header, if present */
orientation?: number | undefined; orientation?: number | undefined;
/** Name of decoder used to decompress image data e.g. jpeg, png, webp, gif, svg */ /** Name of decoder used to decompress image data e.g. jpeg, png, webp, gif, svg */
format?: keyof FormatEnum | undefined; format: keyof FormatEnum;
/** Total size of image in bytes, for Stream and Buffer input only */ /** Total size of image in bytes, for Stream and Buffer input only */
size?: number | undefined; size?: number | undefined;
/** Number of pixels wide (EXIF orientation is not taken into consideration) */ /** Number of pixels wide (EXIF orientation is not taken into consideration) */
width?: number | undefined; width: number;
/** Number of pixels high (EXIF orientation is not taken into consideration) */ /** Number of pixels high (EXIF orientation is not taken into consideration) */
height?: number | undefined; height: number;
/** Any changed metadata after the image orientation is applied. */ /** Any changed metadata after the image orientation is applied. */
autoOrient: { autoOrient: {
/** Number of pixels wide (EXIF orientation is taken into consideration) */ /** Number of pixels wide (EXIF orientation is taken into consideration) */
@@ -1161,19 +1161,19 @@ declare namespace sharp {
height: number; height: number;
}; };
/** Name of colour space interpretation */ /** Name of colour space interpretation */
space?: keyof ColourspaceEnum | undefined; space: keyof ColourspaceEnum;
/** Number of bands e.g. 3 for sRGB, 4 for CMYK */ /** Number of bands e.g. 3 for sRGB, 4 for CMYK */
channels?: Channels | undefined; channels: Channels;
/** Name of pixel depth format e.g. uchar, char, ushort, float ... */ /** Name of pixel depth format e.g. uchar, char, ushort, float ... */
depth?: string | undefined; depth: keyof DepthEnum;
/** Number of pixels per inch (DPI), if present */ /** Number of pixels per inch (DPI), if present */
density?: number | undefined; 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 */ /** 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 | undefined; chromaSubsampling?: string | undefined;
/** Boolean indicating whether the image is interlaced using a progressive scan */ /** Boolean indicating whether the image is interlaced using a progressive scan */
isProgressive?: boolean | undefined; isProgressive: boolean;
/** Boolean indicating whether the image is palette-based (GIF, PNG). */ /** Boolean indicating whether the image is palette-based (GIF, PNG). */
isPalette?: boolean | undefined; isPalette: boolean;
/** Number of bits per sample for each channel (GIF, PNG). */ /** Number of bits per sample for each channel (GIF, PNG). */
bitsPerSample?: number | undefined; bitsPerSample?: number | undefined;
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */ /** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
@@ -1187,9 +1187,9 @@ declare namespace sharp {
/** Number of the primary page in a HEIF image */ /** Number of the primary page in a HEIF image */
pagePrimary?: number | undefined; pagePrimary?: number | undefined;
/** Boolean indicating the presence of an embedded ICC profile */ /** Boolean indicating the presence of an embedded ICC profile */
hasProfile?: boolean | undefined; hasProfile: boolean;
/** Boolean indicating the presence of an alpha transparency channel */ /** Boolean indicating the presence of an alpha transparency channel */
hasAlpha?: boolean | undefined; hasAlpha: boolean;
/** Buffer containing raw EXIF data, if present */ /** Buffer containing raw EXIF data, if present */
exif?: Buffer | undefined; exif?: Buffer | undefined;
/** Buffer containing raw ICC profile data, if present */ /** Buffer containing raw ICC profile data, if present */
@@ -1745,11 +1745,38 @@ declare namespace sharp {
} }
interface ColourspaceEnum { interface ColourspaceEnum {
multiband: string;
'b-w': string; 'b-w': string;
bw: string; cmc: string;
cmyk: string; cmyk: string;
fourier: string;
grey16: string;
histogram: string;
hsv: string;
lab: string;
labq: string;
labs: string;
lch: string;
matrix: string;
multiband: string;
rgb: string;
rgb16: string;
scrgb: string;
srgb: string; srgb: string;
xyz: string;
yxy: string;
}
interface DepthEnum {
char: string;
complex: string;
double: string;
dpcomplex: string;
float: string;
int: string;
short: string;
uchar: string;
uint: string;
ushort: string;
} }
type FailOnOptions = 'none' | 'truncated' | 'error' | 'warning'; type FailOnOptions = 'none' | 'truncated' | 'error' | 'warning';
@@ -1818,6 +1845,7 @@ declare namespace sharp {
interface FormatEnum { interface FormatEnum {
avif: AvailableFormatInfo; avif: AvailableFormatInfo;
dz: AvailableFormatInfo; dz: AvailableFormatInfo;
exr: AvailableFormatInfo;
fits: AvailableFormatInfo; fits: AvailableFormatInfo;
gif: AvailableFormatInfo; gif: AvailableFormatInfo;
heif: AvailableFormatInfo; heif: AvailableFormatInfo;
@@ -1831,6 +1859,7 @@ declare namespace sharp {
pdf: AvailableFormatInfo; pdf: AvailableFormatInfo;
png: AvailableFormatInfo; png: AvailableFormatInfo;
ppm: AvailableFormatInfo; ppm: AvailableFormatInfo;
rad: AvailableFormatInfo;
raw: AvailableFormatInfo; raw: AvailableFormatInfo;
svg: AvailableFormatInfo; svg: AvailableFormatInfo;
tiff: AvailableFormatInfo; tiff: AvailableFormatInfo;

View File

@@ -1019,6 +1019,9 @@ function tiff (options) {
* AVIF image sequences are not supported. * AVIF image sequences are not supported.
* Prebuilt binaries support a bitdepth of 8 only. * Prebuilt binaries support a bitdepth of 8 only.
* *
* This feature is experimental on the Windows ARM64 platform
* and requires a CPU with ARM64v8.4 or later.
*
* @example * @example
* const data = await sharp(input) * const data = await sharp(input)
* .avif({ effort: 2 }) * .avif({ effort: 2 })

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-darwin-arm64", "name": "@img/sharp-darwin-arm64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with macOS 64-bit ARM", "description": "Prebuilt sharp for use with macOS 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-darwin-x64", "name": "@img/sharp-darwin-x64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with macOS x64", "description": "Prebuilt sharp for use with macOS x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-arm", "name": "@img/sharp-linux-arm",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)", "description": "Prebuilt sharp for use with Linux (glibc) ARM (32-bit)",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-arm64", "name": "@img/sharp-linux-arm64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM", "description": "Prebuilt sharp for use with Linux (glibc) 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-ppc64", "name": "@img/sharp-linux-ppc64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (glibc) ppc64", "description": "Prebuilt sharp for use with Linux (glibc) ppc64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-s390x", "name": "@img/sharp-linux-s390x",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (glibc) s390x", "description": "Prebuilt sharp for use with Linux (glibc) s390x",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linux-x64", "name": "@img/sharp-linux-x64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (glibc) x64", "description": "Prebuilt sharp for use with Linux (glibc) x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linuxmusl-arm64", "name": "@img/sharp-linuxmusl-arm64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM", "description": "Prebuilt sharp for use with Linux (musl) 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-linuxmusl-x64", "name": "@img/sharp-linuxmusl-x64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Linux (musl) x64", "description": "Prebuilt sharp for use with Linux (musl) x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp", "name": "@img/sharp",
"version": "0.34.1", "version": "0.34.2",
"private": "true", "private": "true",
"workspaces": [ "workspaces": [
"darwin-arm64", "darwin-arm64",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-wasm32", "name": "@img/sharp-wasm32",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with wasm32", "description": "Prebuilt sharp for use with wasm32",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",
@@ -31,7 +31,7 @@
"node": "^18.17.0 || ^20.3.0 || >=21.0.0" "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
}, },
"dependencies": { "dependencies": {
"@emnapi/runtime": "^1.4.0" "@emnapi/runtime": "^1.4.3"
}, },
"cpu": [ "cpu": [
"wasm32" "wasm32"

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-win32-arm64", "name": "@img/sharp-win32-arm64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Windows 64-bit ARM", "description": "Prebuilt sharp for use with Windows 64-bit ARM",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-win32-ia32", "name": "@img/sharp-win32-ia32",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Windows x86 (32-bit)", "description": "Prebuilt sharp for use with Windows x86 (32-bit)",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@img/sharp-win32-x64", "name": "@img/sharp-win32-x64",
"version": "0.34.1", "version": "0.34.2",
"description": "Prebuilt sharp for use with Windows x64", "description": "Prebuilt sharp for use with Windows x64",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",

View File

@@ -1,7 +1,7 @@
{ {
"name": "sharp", "name": "sharp",
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images", "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
"version": "0.34.1", "version": "0.34.2",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"homepage": "https://sharp.pixelplumbing.com", "homepage": "https://sharp.pixelplumbing.com",
"contributors": [ "contributors": [
@@ -138,12 +138,12 @@
], ],
"dependencies": { "dependencies": {
"color": "^4.2.3", "color": "^4.2.3",
"detect-libc": "^2.0.3", "detect-libc": "^2.0.4",
"semver": "^7.7.1" "semver": "^7.7.2"
}, },
"optionalDependencies": { "optionalDependencies": {
"@img/sharp-darwin-arm64": "0.34.1", "@img/sharp-darwin-arm64": "0.34.2",
"@img/sharp-darwin-x64": "0.34.1", "@img/sharp-darwin-x64": "0.34.2",
"@img/sharp-libvips-darwin-arm64": "1.1.0", "@img/sharp-libvips-darwin-arm64": "1.1.0",
"@img/sharp-libvips-darwin-x64": "1.1.0", "@img/sharp-libvips-darwin-x64": "1.1.0",
"@img/sharp-libvips-linux-arm": "1.1.0", "@img/sharp-libvips-linux-arm": "1.1.0",
@@ -153,19 +153,19 @@
"@img/sharp-libvips-linux-x64": "1.1.0", "@img/sharp-libvips-linux-x64": "1.1.0",
"@img/sharp-libvips-linuxmusl-arm64": "1.1.0", "@img/sharp-libvips-linuxmusl-arm64": "1.1.0",
"@img/sharp-libvips-linuxmusl-x64": "1.1.0", "@img/sharp-libvips-linuxmusl-x64": "1.1.0",
"@img/sharp-linux-arm": "0.34.1", "@img/sharp-linux-arm": "0.34.2",
"@img/sharp-linux-arm64": "0.34.1", "@img/sharp-linux-arm64": "0.34.2",
"@img/sharp-linux-s390x": "0.34.1", "@img/sharp-linux-s390x": "0.34.2",
"@img/sharp-linux-x64": "0.34.1", "@img/sharp-linux-x64": "0.34.2",
"@img/sharp-linuxmusl-arm64": "0.34.1", "@img/sharp-linuxmusl-arm64": "0.34.2",
"@img/sharp-linuxmusl-x64": "0.34.1", "@img/sharp-linuxmusl-x64": "0.34.2",
"@img/sharp-wasm32": "0.34.1", "@img/sharp-wasm32": "0.34.2",
"@img/sharp-win32-arm64": "0.34.1", "@img/sharp-win32-arm64": "0.34.2",
"@img/sharp-win32-ia32": "0.34.1", "@img/sharp-win32-ia32": "0.34.2",
"@img/sharp-win32-x64": "0.34.1" "@img/sharp-win32-x64": "0.34.2"
}, },
"devDependencies": { "devDependencies": {
"@emnapi/runtime": "^1.4.0", "@emnapi/runtime": "^1.4.3",
"@img/sharp-libvips-dev": "1.1.0", "@img/sharp-libvips-dev": "1.1.0",
"@img/sharp-libvips-dev-wasm32": "1.1.0", "@img/sharp-libvips-dev-wasm32": "1.1.0",
"@img/sharp-libvips-win32-arm64": "1.1.0", "@img/sharp-libvips-win32-arm64": "1.1.0",
@@ -173,19 +173,19 @@
"@img/sharp-libvips-win32-x64": "1.1.0", "@img/sharp-libvips-win32-x64": "1.1.0",
"@types/node": "*", "@types/node": "*",
"cc": "^3.0.1", "cc": "^3.0.1",
"emnapi": "^1.4.0", "emnapi": "^1.4.3",
"exif-reader": "^2.0.2", "exif-reader": "^2.0.2",
"extract-zip": "^2.0.1", "extract-zip": "^2.0.1",
"icc": "^3.0.0", "icc": "^3.0.0",
"jsdoc-to-markdown": "^9.1.1", "jsdoc-to-markdown": "^9.1.1",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"mocha": "^11.1.0", "mocha": "^11.4.0",
"node-addon-api": "^8.3.1", "node-addon-api": "^8.3.1",
"nyc": "^17.1.0", "nyc": "^17.1.0",
"prebuild": "^13.0.1", "prebuild": "^13.0.1",
"semistandard": "^17.0.0", "semistandard": "^17.0.0",
"tar-fs": "^3.0.8", "tar-fs": "^3.0.8",
"tsd": "^0.31.2" "tsd": "^0.32.0"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"engines": { "engines": {

View File

@@ -951,14 +951,6 @@ namespace sharp {
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16; return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
} }
/*
Return the image alpha maximum. Useful for combining alpha bands. scRGB
images are 0 - 1 for image data, but the alpha is 0 - 255.
*/
double MaximumImageAlpha(VipsInterpretation const interpretation) {
return Is16Bit(interpretation) ? 65535.0 : 255.0;
}
/* /*
Convert RGBA value to another colourspace Convert RGBA value to another colourspace
*/ */
@@ -1001,16 +993,16 @@ namespace sharp {
0.0722 * colour[2]) 0.0722 * colour[2])
}; };
} }
// Add alpha channel to alphaColour colour // Add alpha channel(s) to alphaColour colour
if (colour[3] < 255.0 || image.has_alpha()) { if (colour[3] < 255.0 || image.has_alpha()) {
alphaColour.push_back(colour[3] * multiplier); int extraBands = image.bands() > 4 ? image.bands() - 3 : 1;
alphaColour.insert(alphaColour.end(), extraBands, colour[3] * multiplier);
} }
// Ensure alphaColour colour uses correct colourspace // Ensure alphaColour colour uses correct colourspace
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply); alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
// Add non-transparent alpha channel, if required // Add non-transparent alpha channel, if required
if (colour[3] < 255.0 && !image.has_alpha()) { if (colour[3] < 255.0 && !image.has_alpha()) {
image = image.bandjoin( image = image.bandjoin_const({ 255 * multiplier });
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format()));
} }
return std::make_tuple(image, alphaColour); return std::make_tuple(image, alphaColour);
} }
@@ -1030,9 +1022,7 @@ namespace sharp {
*/ */
VImage EnsureAlpha(VImage image, double const value) { VImage EnsureAlpha(VImage image, double const value) {
if (!image.has_alpha()) { if (!image.has_alpha()) {
std::vector<double> alpha; image = image.bandjoin_const({ value * vips_interpretation_max_alpha(image.interpretation()) });
alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));
image = image.bandjoin_const(alpha);
} }
return image; return image;
} }

View File

@@ -357,12 +357,6 @@ namespace sharp {
*/ */
bool Is16Bit(VipsInterpretation const interpretation); bool Is16Bit(VipsInterpretation const interpretation);
/*
Return the image alpha maximum. Useful for combining alpha bands. scRGB
images are 0 - 1 for image data, but the alpha is 0 - 255.
*/
double MaximumImageAlpha(VipsInterpretation const interpretation);
/* /*
Convert RGBA value to another colourspace Convert RGBA value to another colourspace
*/ */

View File

@@ -294,6 +294,7 @@ class PipelineWorker : public Napi::AsyncWorker {
option->set("n", baton->input->pages); option->set("n", baton->input->pages);
option->set("page", baton->input->page); option->set("page", baton->input->page);
option->set("dpi", baton->input->density); option->set("dpi", baton->input->density);
option->set("background", baton->input->pdfBackground);
if (baton->input->buffer != nullptr) { if (baton->input->buffer != nullptr) {
// Reload PDF buffer // Reload PDF buffer
@@ -1359,7 +1360,8 @@ class PipelineWorker : public Napi::AsyncWorker {
// Add file size to info // Add file size to info
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) { if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
try { try {
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut)); uint32_t const size = static_cast<uint32_t>(
std::filesystem::file_size(std::filesystem::u8path(baton->fileOut)));
info.Set("size", size); info.Set("size", size);
} catch (...) {} } catch (...) {}
} }

View File

@@ -60,7 +60,7 @@ class StatsWorker : public Napi::AsyncWorker {
// Image is not opaque when alpha layer is present and contains a non-mamixa value // Image is not opaque when alpha layer is present and contains a non-mamixa value
if (image.has_alpha()) { if (image.has_alpha()) {
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front()); double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) { if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) {
baton->isOpaque = false; baton->isOpaque = false;
} }
} }

View File

@@ -1036,4 +1036,21 @@ describe('Input/output', function () {
}); });
readable.pipe(inPipeline).pipe(badPipeline); readable.pipe(inPipeline).pipe(badPipeline);
}); });
it('supports wide-character filenames', async () => {
const filename = fixtures.path('output.图片.jpg');
const create = {
width: 8,
height: 8,
channels: 3,
background: 'green'
};
await sharp({ create }).toFile(filename);
const { width, height, channels, format } = await sharp(filename).metadata();
assert.strictEqual(width, 8);
assert.strictEqual(height, 8);
assert.strictEqual(channels, 3);
assert.strictEqual(format, 'jpeg');
});
}); });

View File

@@ -806,4 +806,33 @@ describe('Resize fit=contain', function () {
fixtures.assertSimilar(fixtures.expected('./embedgravitybird/9-c.png'), data, done); fixtures.assertSimilar(fixtures.expected('./embedgravitybird/9-c.png'), data, done);
}); });
}); });
it('multiple alpha channels', async () => {
const create = {
width: 20,
height: 12,
channels: 4,
background: 'green'
};
const multipleAlphaChannels = await sharp({ create })
.joinChannel({ create })
.tiff({ compression: 'deflate' })
.toBuffer();
const data = await sharp(multipleAlphaChannels)
.resize({
width: 8,
height: 8,
fit: 'contain',
background: 'blue'
})
.tiff({ compression: 'deflate' })
.toBuffer();
const { format, width, height, space, channels } = await sharp(data).metadata();
assert.deepStrictEqual(format, 'tiff');
assert.deepStrictEqual(width, 8);
assert.deepStrictEqual(height, 8);
assert.deepStrictEqual(space, 'srgb');
assert.deepStrictEqual(channels, 8);
});
}); });

View File

@@ -10,18 +10,20 @@ const sharp = require('../../');
describe('Utilities', function () { describe('Utilities', function () {
describe('Cache', function () { describe('Cache', function () {
it('Can be disabled', function (done) { it('Can be disabled', function (done) {
queueMicrotask(() => { const check = setInterval(() => {
sharp.cache(false);
const cache = sharp.cache(false); const cache = sharp.cache(false);
assert.strictEqual(cache.memory.current, 0); const empty =
assert.strictEqual(cache.memory.max, 0); cache.memory.current +
assert.strictEqual(typeof cache.memory.high, 'number'); cache.memory.max +
assert.strictEqual(cache.files.current, 0); cache.files.current +
assert.strictEqual(cache.files.max, 0); cache.files.max +
assert.strictEqual(cache.items.current, 0); cache.items.current +
assert.strictEqual(cache.items.max, 0); cache.items.max === 0;
done(); if (empty) {
}); clearInterval(check);
done();
}
}, 2000);
}); });
it('Can be enabled with defaults', function () { it('Can be enabled with defaults', function () {
const cache = sharp.cache(true); const cache = sharp.cache(true);