mirror of
https://github.com/lovell/sharp.git
synced 2026-02-05 14:16:17 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ff84b20b7 | ||
|
|
97655d2dfd | ||
|
|
d10d7b02d4 | ||
|
|
2ffdae2914 | ||
|
|
342de36973 | ||
|
|
b33231d4bd |
@@ -379,6 +379,8 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these TIFF options for output image.
|
Use these TIFF options for output image.
|
||||||
|
|
||||||
|
The `density` can be set in pixels/inch via [withMetadata][1] instead of providing `xres` and `yres` in pixels/mm.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
* `options` **[Object][6]?** output options
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
Requires libvips v8.11.3
|
Requires libvips v8.11.3
|
||||||
|
|
||||||
|
### v0.29.3 - 14th November 2021
|
||||||
|
|
||||||
|
* Ensure correct dimensions when containing image resized to 1px.
|
||||||
|
[#2951](https://github.com/lovell/sharp/issues/2951)
|
||||||
|
|
||||||
|
* Impute TIFF `xres`/`yres` from `density` provided to `withMetadata`.
|
||||||
|
[#2952](https://github.com/lovell/sharp/pull/2952)
|
||||||
|
[@mbklein](https://github.com/mbklein)
|
||||||
|
|
||||||
### v0.29.2 - 21st October 2021
|
### v0.29.2 - 21st October 2021
|
||||||
|
|
||||||
* Add `timeout` function to limit processing time.
|
* Add `timeout` function to limit processing time.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -637,6 +637,8 @@ function trySetAnimationOptions (source, target) {
|
|||||||
/**
|
/**
|
||||||
* Use these TIFF options for output image.
|
* Use these TIFF options for output image.
|
||||||
*
|
*
|
||||||
|
* The `density` can be set in pixels/inch via {@link withMetadata} instead of providing `xres` and `yres` in pixels/mm.
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
* // Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
* sharp('input.svg')
|
* sharp('input.svg')
|
||||||
|
|||||||
10
package.json
10
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images",
|
||||||
"version": "0.29.2",
|
"version": "0.29.3",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -127,14 +127,14 @@
|
|||||||
"color": "^4.0.1",
|
"color": "^4.0.1",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"node-addon-api": "^4.2.0",
|
"node-addon-api": "^4.2.0",
|
||||||
"prebuild-install": "^6.1.4",
|
"prebuild-install": "^7.0.0",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
"simple-get": "^3.1.0",
|
"simple-get": "^4.0.0",
|
||||||
"tar-fs": "^2.1.1",
|
"tar-fs": "^2.1.1",
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^3.2.1",
|
"async": "^3.2.2",
|
||||||
"cc": "^3.0.1",
|
"cc": "^3.0.1",
|
||||||
"decompress-zip": "^0.3.3",
|
"decompress-zip": "^0.3.3",
|
||||||
"documentation": "^13.2.5",
|
"documentation": "^13.2.5",
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
"icc": "^2.0.0",
|
"icc": "^2.0.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^9.1.3",
|
"mocha": "^9.1.3",
|
||||||
"mock-fs": "^5.1.1",
|
"mock-fs": "^5.1.2",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"prebuild": "^11.0.0",
|
"prebuild": "^11.0.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
|||||||
@@ -382,11 +382,15 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Ensure shortest edge is at least 1 pixel
|
// Ensure shortest edge is at least 1 pixel
|
||||||
if (image.width() / xfactor < 0.5) {
|
if (image.width() / xfactor < 0.5) {
|
||||||
xfactor = 2 * image.width();
|
xfactor = 2 * image.width();
|
||||||
baton->width = 1;
|
if (baton->canvas != Canvas::EMBED) {
|
||||||
|
baton->width = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (image.height() / yfactor < 0.5) {
|
if (image.height() / yfactor < 0.5) {
|
||||||
yfactor = 2 * image.height();
|
yfactor = 2 * image.height();
|
||||||
baton->height = 1;
|
if (baton->canvas != Canvas::EMBED) {
|
||||||
|
baton->height = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
image = image.resize(1.0 / xfactor, VImage::option()
|
image = image.resize(1.0 / xfactor, VImage::option()
|
||||||
->set("vscale", 1.0 / yfactor)
|
->set("vscale", 1.0 / yfactor)
|
||||||
@@ -1492,6 +1496,9 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|||||||
baton->tiffTileHeight = sharp::AttrAsUint32(options, "tiffTileHeight");
|
baton->tiffTileHeight = sharp::AttrAsUint32(options, "tiffTileHeight");
|
||||||
baton->tiffXres = sharp::AttrAsDouble(options, "tiffXres");
|
baton->tiffXres = sharp::AttrAsDouble(options, "tiffXres");
|
||||||
baton->tiffYres = sharp::AttrAsDouble(options, "tiffYres");
|
baton->tiffYres = sharp::AttrAsDouble(options, "tiffYres");
|
||||||
|
if (baton->tiffXres == 1.0 && baton->tiffYres == 1.0 && baton->withMetadataDensity > 0) {
|
||||||
|
baton->tiffXres = baton->tiffYres = baton->withMetadataDensity / 25.4;
|
||||||
|
}
|
||||||
// tiff compression options
|
// tiff compression options
|
||||||
baton->tiffCompression = static_cast<VipsForeignTiffCompression>(
|
baton->tiffCompression = static_cast<VipsForeignTiffCompression>(
|
||||||
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_TIFF_COMPRESSION,
|
vips_enum_from_nick(nullptr, VIPS_TYPE_FOREIGN_TIFF_COMPRESSION,
|
||||||
|
|||||||
@@ -605,6 +605,40 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Ensure embedded shortest edge (height) is at least 1 pixel', function () {
|
||||||
|
return sharp({
|
||||||
|
create: {
|
||||||
|
width: 200,
|
||||||
|
height: 1,
|
||||||
|
channels: 3,
|
||||||
|
background: 'red'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.resize({ width: 50, height: 50, fit: sharp.fit.contain })
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(function (output) {
|
||||||
|
assert.strictEqual(50, output.info.width);
|
||||||
|
assert.strictEqual(50, output.info.height);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Ensure embedded shortest edge (width) is at least 1 pixel', function () {
|
||||||
|
return sharp({
|
||||||
|
create: {
|
||||||
|
width: 1,
|
||||||
|
height: 200,
|
||||||
|
channels: 3,
|
||||||
|
background: 'red'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.resize({ width: 50, height: 50, fit: sharp.fit.contain })
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(function (output) {
|
||||||
|
assert.strictEqual(50, output.info.width);
|
||||||
|
assert.strictEqual(50, output.info.height);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Skip shrink-on-load where one dimension <4px', async () => {
|
it('Skip shrink-on-load where one dimension <4px', async () => {
|
||||||
const jpeg = await sharp({
|
const jpeg = await sharp({
|
||||||
create: {
|
create: {
|
||||||
|
|||||||
@@ -188,6 +188,26 @@ describe('TIFF', function () {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('TIFF imputes xres and yres from withMetadataDensity if not explicitly provided', async () => {
|
||||||
|
const data = await sharp(fixtures.inputTiff)
|
||||||
|
.resize(8, 8)
|
||||||
|
.tiff()
|
||||||
|
.withMetadata({ density: 600 })
|
||||||
|
.toBuffer();
|
||||||
|
const { density } = await sharp(data).metadata();
|
||||||
|
assert.strictEqual(600, density);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('TIFF uses xres and yres over withMetadataDensity if explicitly provided', async () => {
|
||||||
|
const data = await sharp(fixtures.inputTiff)
|
||||||
|
.resize(8, 8)
|
||||||
|
.tiff({ xres: 1000, yres: 1000 })
|
||||||
|
.withMetadata({ density: 600 })
|
||||||
|
.toBuffer();
|
||||||
|
const { density } = await sharp(data).metadata();
|
||||||
|
assert.strictEqual(25400, density);
|
||||||
|
});
|
||||||
|
|
||||||
it('TIFF invalid xres value should throw an error', function () {
|
it('TIFF invalid xres value should throw an error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().tiff({ xres: '1000.0' });
|
sharp().tiff({ xres: '1000.0' });
|
||||||
|
|||||||
Reference in New Issue
Block a user