mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Expose pages metadata for multi-page input images #1205
This commit is contained in:
parent
cc1d4c1a6d
commit
cc633589d9
@ -6,6 +6,9 @@ Requires libvips v8.7.0.
|
|||||||
|
|
||||||
#### v0.21.2 - TBD
|
#### v0.21.2 - TBD
|
||||||
|
|
||||||
|
* Expose `pages` and `pageHeight` metadata for multi-page input images.
|
||||||
|
[#1205](https://github.com/lovell/sharp/issues/1205)
|
||||||
|
|
||||||
* Prevent mutatation of options passed to `jpeg`.
|
* Prevent mutatation of options passed to `jpeg`.
|
||||||
[#1516](https://github.com/lovell/sharp/issues/1516)
|
[#1516](https://github.com/lovell/sharp/issues/1516)
|
||||||
|
|
||||||
|
@ -71,6 +71,12 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
if (image.get_typeof("palette-bit-depth") == G_TYPE_INT) {
|
if (image.get_typeof("palette-bit-depth") == G_TYPE_INT) {
|
||||||
baton->paletteBitDepth = image.get_int("palette-bit-depth");
|
baton->paletteBitDepth = image.get_int("palette-bit-depth");
|
||||||
}
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
||||||
|
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
||||||
|
}
|
||||||
|
if (image.get_typeof(VIPS_META_PAGE_HEIGHT) == G_TYPE_INT) {
|
||||||
|
baton->pageHeight = image.get_int(VIPS_META_PAGE_HEIGHT);
|
||||||
|
}
|
||||||
baton->hasProfile = sharp::HasProfile(image);
|
baton->hasProfile = sharp::HasProfile(image);
|
||||||
// Derived attributes
|
// Derived attributes
|
||||||
baton->hasAlpha = sharp::HasAlpha(image);
|
baton->hasAlpha = sharp::HasAlpha(image);
|
||||||
@ -146,6 +152,12 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
if (baton->paletteBitDepth > 0) {
|
if (baton->paletteBitDepth > 0) {
|
||||||
Set(info, New("paletteBitDepth").ToLocalChecked(), New<v8::Uint32>(baton->paletteBitDepth));
|
Set(info, New("paletteBitDepth").ToLocalChecked(), New<v8::Uint32>(baton->paletteBitDepth));
|
||||||
}
|
}
|
||||||
|
if (baton->pages > 0) {
|
||||||
|
Set(info, New("pages").ToLocalChecked(), New<v8::Uint32>(baton->pages));
|
||||||
|
}
|
||||||
|
if (baton->pageHeight > 0) {
|
||||||
|
Set(info, New("pageHeight").ToLocalChecked(), New<v8::Uint32>(baton->pageHeight));
|
||||||
|
}
|
||||||
Set(info, New("hasProfile").ToLocalChecked(), New<v8::Boolean>(baton->hasProfile));
|
Set(info, New("hasProfile").ToLocalChecked(), New<v8::Boolean>(baton->hasProfile));
|
||||||
Set(info, New("hasAlpha").ToLocalChecked(), New<v8::Boolean>(baton->hasAlpha));
|
Set(info, New("hasAlpha").ToLocalChecked(), New<v8::Boolean>(baton->hasAlpha));
|
||||||
if (baton->orientation > 0) {
|
if (baton->orientation > 0) {
|
||||||
|
@ -34,6 +34,8 @@ struct MetadataBaton {
|
|||||||
std::string chromaSubsampling;
|
std::string chromaSubsampling;
|
||||||
bool isProgressive;
|
bool isProgressive;
|
||||||
int paletteBitDepth;
|
int paletteBitDepth;
|
||||||
|
int pages;
|
||||||
|
int pageHeight;
|
||||||
bool hasProfile;
|
bool hasProfile;
|
||||||
bool hasAlpha;
|
bool hasAlpha;
|
||||||
int orientation;
|
int orientation;
|
||||||
@ -55,6 +57,8 @@ struct MetadataBaton {
|
|||||||
density(0),
|
density(0),
|
||||||
isProgressive(false),
|
isProgressive(false),
|
||||||
paletteBitDepth(0),
|
paletteBitDepth(0),
|
||||||
|
pages(0),
|
||||||
|
pageHeight(0),
|
||||||
hasProfile(false),
|
hasProfile(false),
|
||||||
hasAlpha(false),
|
hasAlpha(false),
|
||||||
orientation(0),
|
orientation(0),
|
||||||
|
@ -103,6 +103,30 @@ describe('Image metadata', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Multipage TIFF', function (done) {
|
||||||
|
sharp(fixtures.inputTiffMultipage).metadata(function (err, metadata) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log(metadata);
|
||||||
|
assert.strictEqual('tiff', metadata.format);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.size);
|
||||||
|
assert.strictEqual(2464, metadata.width);
|
||||||
|
assert.strictEqual(3248, metadata.height);
|
||||||
|
assert.strictEqual('b-w', metadata.space);
|
||||||
|
assert.strictEqual(1, metadata.channels);
|
||||||
|
assert.strictEqual('uchar', metadata.depth);
|
||||||
|
assert.strictEqual(300, metadata.density);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.chromaSubsampling);
|
||||||
|
assert.strictEqual(false, metadata.isProgressive);
|
||||||
|
assert.strictEqual(2, metadata.pages);
|
||||||
|
assert.strictEqual(false, metadata.hasProfile);
|
||||||
|
assert.strictEqual(false, metadata.hasAlpha);
|
||||||
|
assert.strictEqual(1, metadata.orientation);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.exif);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.icc);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('PNG', function (done) {
|
it('PNG', function (done) {
|
||||||
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
sharp(fixtures.inputPng).metadata(function (err, metadata) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user