mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 12:00:14 +02:00
Impute TIFF xres/yres from withMetadata({density})
This commit is contained in:
parent
b33231d4bd
commit
342de36973
@ -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
|
||||||
|
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')
|
||||||
|
@ -1496,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,
|
||||||
|
@ -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' });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user