Permalink
Browse files

Starting to add support for setting IPTC and XMP tags.

  • Loading branch information...
1 parent 149dc5b commit 568f0cdd31fef8cfae9c0d845365abf1953ec524 @drewish drewish committed Oct 16, 2012
Showing with 20 additions and 4 deletions.
  1. +15 −3 exiv2node.cc
  2. +5 −1 test/test.js
View
@@ -223,20 +223,32 @@ static Handle<Value> SetImageTags(const Arguments& args) {
static void SetImageTagsWorker(uv_work_t *req) {
Baton *thread_data = static_cast<Baton*> (req->data);
- // TODO: also handle IPTC and XMP data here.
try {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(thread_data->fileName);
assert(image.get() != 0);
+
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
+ Exiv2::IptcData &iptcData = image->iptcData();
+ Exiv2::XmpData &xmpData = image->xmpData();
// Assign the tags.
for (tag_map_t::iterator i = thread_data->tags->begin(); i != thread_data->tags->end(); ++i) {
- exifData[i->first].setValue(i->second);
+ if (i->first.compare(0, 5, "Exif.") == 0) {
+ exifData[i->first].setValue(i->second);
+ } else if (i->first.compare(0, 5, "Iptc.") == 0) {
+ iptcData[i->first].setValue(i->second);
+ } else if (i->first.compare(0, 4, "Xmp.") == 0) {
+ xmpData[i->first].setValue(i->second);
+ } else {
+ //std::cerr << "skipping unknown tag " << i->first << std::endl;
+ }
}
- // Write the Exif data to the image file.
+ // Write the tag data the image file.
image->setExifData(exifData);
+ image->setIptcData(iptcData);
+ image->setXmpData(xmpData);
image->writeMetadata();
} catch (std::exception& e) {
thread_data->exifException.append(e.what());
View
@@ -53,14 +53,18 @@ describe('exiv2', function(){
it('should write tags to image files', function(done) {
var tags = {
"Exif.Photo.UserComment" : "Some books..",
- "Exif.Canon.OwnerName" : "Damo's camera"
+ "Exif.Canon.OwnerName" : "Damo's camera",
+ "Iptc.Application2.RecordVersion" : "2",
+ "Xmp.dc.subject" : "A camera",
};
exiv.setImageTags(temp, tags, function(err){
should.not.exist(err);
exiv.getImageTags(temp, function(err, tags) {
tags.should.have.property('Exif.Photo.UserComment', "Some books..");
tags.should.have.property('Exif.Canon.OwnerName', "Damo's camera");
+ tags.should.have.property('Iptc.Application2.RecordVersion', "2");
+ tags.should.have.property('Xmp.dc.subject', "A camera");
done();
});
});

0 comments on commit 568f0cd

Please sign in to comment.