mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 02:30:12 +02:00
Provide XMP as a string, as well as a Buffer, where possible
This commit is contained in:
parent
4e3f3792ad
commit
8ee8d273ee
@ -20,6 +20,8 @@ Requires libvips v8.17.0
|
|||||||
|
|
||||||
* Add support for RAW digital camera image input. Requires libvips compiled with libraw support.
|
* Add support for RAW digital camera image input. Requires libvips compiled with libraw support.
|
||||||
|
|
||||||
|
* Provide XMP metadata as a string, as well as a Buffer, where possible.
|
||||||
|
|
||||||
* Add `pageHeight` option to `create` and `raw` input for animated images.
|
* Add `pageHeight` option to `create` and `raw` input for animated images.
|
||||||
[#3236](https://github.com/lovell/sharp/issues/3236)
|
[#3236](https://github.com/lovell/sharp/issues/3236)
|
||||||
|
|
||||||
|
2
lib/index.d.ts
vendored
2
lib/index.d.ts
vendored
@ -1254,6 +1254,8 @@ declare namespace sharp {
|
|||||||
iptc?: Buffer | undefined;
|
iptc?: Buffer | undefined;
|
||||||
/** Buffer containing raw XMP data, if present */
|
/** Buffer containing raw XMP data, if present */
|
||||||
xmp?: Buffer | undefined;
|
xmp?: Buffer | undefined;
|
||||||
|
/** String containing XMP data, if valid UTF-8 */
|
||||||
|
xmpAsString?: string | undefined;
|
||||||
/** Buffer containing raw TIFFTAG_PHOTOSHOP data, if present */
|
/** Buffer containing raw TIFFTAG_PHOTOSHOP data, if present */
|
||||||
tifftagPhotoshop?: Buffer | undefined;
|
tifftagPhotoshop?: Buffer | undefined;
|
||||||
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
||||||
|
@ -605,6 +605,7 @@ function _isStreamInput () {
|
|||||||
* - `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
* - `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
||||||
* - `iptc`: Buffer containing raw IPTC data, if present
|
* - `iptc`: Buffer containing raw IPTC data, if present
|
||||||
* - `xmp`: Buffer containing raw XMP data, if present
|
* - `xmp`: Buffer containing raw XMP data, if present
|
||||||
|
* - `xmpAsString`: String containing XMP data, if valid UTF-8.
|
||||||
* - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
* - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||||
* - `formatMagick`: String containing format for images loaded via *magick
|
* - `formatMagick`: String containing format for images loaded via *magick
|
||||||
* - `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
|
* - `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
|
||||||
|
@ -262,6 +262,10 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
if (baton->xmpLength > 0) {
|
if (baton->xmpLength > 0) {
|
||||||
info.Set("xmp", Napi::Buffer<char>::NewOrCopy(env, baton->xmp, baton->xmpLength, sharp::FreeCallback));
|
info.Set("xmp", Napi::Buffer<char>::NewOrCopy(env, baton->xmp, baton->xmpLength, sharp::FreeCallback));
|
||||||
|
if (g_utf8_validate(static_cast<char const *>(baton->xmp), baton->xmpLength, nullptr)) {
|
||||||
|
info.Set("xmpAsString",
|
||||||
|
Napi::String::New(env, static_cast<char const *>(baton->xmp), baton->xmpLength));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (baton->tifftagPhotoshopLength > 0) {
|
if (baton->tifftagPhotoshopLength > 0) {
|
||||||
info.Set("tifftagPhotoshop",
|
info.Set("tifftagPhotoshop",
|
||||||
|
@ -82,6 +82,7 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual(true, metadata.xmp instanceof Buffer);
|
assert.strictEqual(true, metadata.xmp instanceof Buffer);
|
||||||
assert.strictEqual(12466, metadata.xmp.byteLength);
|
assert.strictEqual(12466, metadata.xmp.byteLength);
|
||||||
assert.strictEqual(metadata.xmp.indexOf(Buffer.from('<?xpacket begin="')), 0);
|
assert.strictEqual(metadata.xmp.indexOf(Buffer.from('<?xpacket begin="')), 0);
|
||||||
|
assert(metadata.xmpAsString.startsWith('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -106,6 +107,8 @@ describe('Image metadata', function () {
|
|||||||
assert.strictEqual(3248, metadata.autoOrient.height);
|
assert.strictEqual(3248, metadata.autoOrient.height);
|
||||||
assert.strictEqual('undefined', typeof metadata.exif);
|
assert.strictEqual('undefined', typeof metadata.exif);
|
||||||
assert.strictEqual('undefined', typeof metadata.icc);
|
assert.strictEqual('undefined', typeof metadata.icc);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.xmp);
|
||||||
|
assert.strictEqual('undefined', typeof metadata.xmpAsString);
|
||||||
assert.strictEqual('inch', metadata.resolutionUnit);
|
assert.strictEqual('inch', metadata.resolutionUnit);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user