mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose IPTC and XMP metadata when available (#1079)
This commit is contained in:
committed by
Lovell Fuller
parent
8afcb16d8e
commit
c4df115948
@@ -81,6 +81,22 @@ class MetadataWorker : public Nan::AsyncWorker {
|
||||
memcpy(baton->icc, icc, iccLength);
|
||||
baton->iccLength = iccLength;
|
||||
}
|
||||
// IPTC
|
||||
if (image.get_typeof(VIPS_META_IPCT_NAME) == VIPS_TYPE_BLOB) {
|
||||
size_t iptcLength;
|
||||
void const *iptc = image.get_blob(VIPS_META_IPCT_NAME, &iptcLength);
|
||||
baton->iptc = static_cast<char *>(g_malloc(iptcLength));
|
||||
memcpy(baton->iptc, iptc, iptcLength);
|
||||
baton->iptcLength = iptcLength;
|
||||
}
|
||||
// XMP
|
||||
if (image.get_typeof(VIPS_META_XMP_NAME) == VIPS_TYPE_BLOB) {
|
||||
size_t xmpLength;
|
||||
void const *xmp = image.get_blob(VIPS_META_XMP_NAME, &xmpLength);
|
||||
baton->xmp = static_cast<char *>(g_malloc(xmpLength));
|
||||
memcpy(baton->xmp, xmp, xmpLength);
|
||||
baton->xmpLength = xmpLength;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
@@ -123,6 +139,16 @@ class MetadataWorker : public Nan::AsyncWorker {
|
||||
New("icc").ToLocalChecked(),
|
||||
Nan::NewBuffer(baton->icc, baton->iccLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||
}
|
||||
if (baton->iptcLength > 0) {
|
||||
Set(info,
|
||||
New("iptc").ToLocalChecked(),
|
||||
Nan::NewBuffer(baton->iptc, baton->iptcLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||
}
|
||||
if (baton->xmpLength > 0) {
|
||||
Set(info,
|
||||
New("xmp").ToLocalChecked(),
|
||||
Nan::NewBuffer(baton->xmp, baton->xmpLength, sharp::FreeCallback, nullptr).ToLocalChecked());
|
||||
}
|
||||
argv[1] = info;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ struct MetadataBaton {
|
||||
size_t exifLength;
|
||||
char *icc;
|
||||
size_t iccLength;
|
||||
char *iptc;
|
||||
size_t iptcLength;
|
||||
char *xmp;
|
||||
size_t xmpLength;
|
||||
std::string err;
|
||||
|
||||
MetadataBaton():
|
||||
@@ -52,7 +56,11 @@ struct MetadataBaton {
|
||||
exif(nullptr),
|
||||
exifLength(0),
|
||||
icc(nullptr),
|
||||
iccLength(0) {}
|
||||
iccLength(0),
|
||||
iptc(nullptr),
|
||||
iptcLength(0),
|
||||
xmp(nullptr),
|
||||
xmpLength(0) {}
|
||||
};
|
||||
|
||||
NAN_METHOD(metadata);
|
||||
|
||||
Reference in New Issue
Block a user