Compare commits

..

No commits in common. "94481a967ee9e4f925ee2acf078d36cc6464948f" and "0b5f131df8a632e57d891c7e7893e1bde10b3664" have entirely different histories.

6 changed files with 16 additions and 103 deletions

View File

@ -18,19 +18,10 @@ Requires libvips v8.16.1
[#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.

55
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; format?: keyof FormatEnum | undefined;
/** 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; width?: number | undefined;
/** Number of pixels high (EXIF orientation is not taken into consideration) */ /** Number of pixels high (EXIF orientation is not taken into consideration) */
height: number; height?: number | undefined;
/** 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; space?: keyof ColourspaceEnum | undefined;
/** Number of bands e.g. 3 for sRGB, 4 for CMYK */ /** Number of bands e.g. 3 for sRGB, 4 for CMYK */
channels: Channels; channels?: Channels | undefined;
/** Name of pixel depth format e.g. uchar, char, ushort, float ... */ /** Name of pixel depth format e.g. uchar, char, ushort, float ... */
depth: keyof DepthEnum; depth?: string | undefined;
/** 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; isProgressive?: boolean | undefined;
/** Boolean indicating whether the image is palette-based (GIF, PNG). */ /** Boolean indicating whether the image is palette-based (GIF, PNG). */
isPalette: boolean; isPalette?: boolean | undefined;
/** 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; hasProfile?: boolean | undefined;
/** Boolean indicating the presence of an alpha transparency channel */ /** Boolean indicating the presence of an alpha transparency channel */
hasAlpha: boolean; hasAlpha?: boolean | undefined;
/** 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,38 +1745,11 @@ declare namespace sharp {
} }
interface ColourspaceEnum { interface ColourspaceEnum {
'b-w': string;
cmc: string;
cmyk: string;
fourier: string;
grey16: string;
histogram: string;
hsv: string;
lab: string;
labq: string;
labs: string;
lch: string;
matrix: string;
multiband: string; multiband: string;
rgb: string; 'b-w': string;
rgb16: string; bw: string;
scrgb: string; cmyk: 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';
@ -1845,7 +1818,6 @@ 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;
@ -1859,7 +1831,6 @@ 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

@ -1001,11 +1001,9 @@ namespace sharp {
0.0722 * colour[2]) 0.0722 * colour[2])
}; };
} }
// Add alpha channel(s) to alphaColour colour // Add alpha channel to alphaColour colour
if (colour[3] < 255.0 || image.has_alpha()) { if (colour[3] < 255.0 || image.has_alpha()) {
do { alphaColour.push_back(colour[3] * multiplier);
alphaColour.push_back(colour[3] * multiplier);
} while (alphaColour.size() < static_cast<size_t>(image.bands()));
} }
// 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);

View File

@ -1359,8 +1359,7 @@ 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>( uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
std::filesystem::file_size(std::filesystem::u8path(baton->fileOut)));
info.Set("size", size); info.Set("size", size);
} catch (...) {} } catch (...) {}
} }

View File

@ -1036,21 +1036,4 @@ 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,33 +806,4 @@ 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);
});
}); });