Skip to content

Commit

Permalink
feat: expose iptc and xmp in metadata if available
Browse files Browse the repository at this point in the history
  • Loading branch information
oaleynik committed Dec 28, 2017
1 parent 358b8fe commit 61f7590
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_ICC_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_ICC_NAME, &xmpLength);
baton->xmp = static_cast<char *>(g_malloc(xmpLength));
memcpy(baton->xmp, xmp, xmpLength);
baton->xmpLength = xmpLength;
}
}

// Clean up
Expand Down Expand 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;
}

Expand Down
10 changes: 9 additions & 1 deletion src/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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);
Expand Down

0 comments on commit 61f7590

Please sign in to comment.