mirror of
https://github.com/lovell/sharp.git
synced 2025-07-08 18:20:13 +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.
|
||||
|
||||
* Provide XMP metadata as a string, as well as a Buffer, where possible.
|
||||
|
||||
* Add `pageHeight` option to `create` and `raw` input for animated images.
|
||||
[#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;
|
||||
/** Buffer containing raw XMP data, if present */
|
||||
xmp?: Buffer | undefined;
|
||||
/** String containing XMP data, if valid UTF-8 */
|
||||
xmpAsString?: string | undefined;
|
||||
/** Buffer containing raw TIFFTAG_PHOTOSHOP data, if present */
|
||||
tifftagPhotoshop?: Buffer | undefined;
|
||||
/** 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
|
||||
* - `iptc`: Buffer containing raw IPTC 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
|
||||
* - `formatMagick`: String containing format for images loaded via *magick
|
||||
* - `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) {
|
||||
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) {
|
||||
info.Set("tifftagPhotoshop",
|
||||
|
@ -82,6 +82,7 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(true, metadata.xmp instanceof Buffer);
|
||||
assert.strictEqual(12466, metadata.xmp.byteLength);
|
||||
assert.strictEqual(metadata.xmp.indexOf(Buffer.from('<?xpacket begin="')), 0);
|
||||
assert(metadata.xmpAsString.startsWith('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -106,6 +107,8 @@ describe('Image metadata', function () {
|
||||
assert.strictEqual(3248, metadata.autoOrient.height);
|
||||
assert.strictEqual('undefined', typeof metadata.exif);
|
||||
assert.strictEqual('undefined', typeof metadata.icc);
|
||||
assert.strictEqual('undefined', typeof metadata.xmp);
|
||||
assert.strictEqual('undefined', typeof metadata.xmpAsString);
|
||||
assert.strictEqual('inch', metadata.resolutionUnit);
|
||||
done();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user