Permalink
Browse files

Merge pull request #12 from drewish/previews

Adding support for extracting preview images.

Also includes some performance improvements for reading tags.
  • Loading branch information...
2 parents 523834c + e3c9c70 commit a252e69a4e49b1caa3676f91ff35814c630cfaa9 @drewish drewish committed May 24, 2012
Showing with 307 additions and 91 deletions.
  1. +35 −11 README.md
  2. +14 −2 examples/simple.js
  3. +212 −78 exiv2node.cc
  4. +46 −0 test/test.js
View
@@ -1,11 +1,17 @@
-##Exiv2
+#Exiv2
-Exiv2 is a native c++ extension for node.js that provides asynchronous support for reading & writing image metadata via Exiv2 (http://www.exiv2.org).
+Exiv2 is a native c++ extension for [node.js](http://nodejs.org/) that provides
+asynchronous support for reading & writing image metadata via
+[Exiv2 library](http://www.exiv2.org).
## Dependencies
-Needs Exiv2, see http://www.exiv2.org/download.html.
+To build this addon you'll need the Exiv2 library and headers, see
+[their download page](http://www.exiv2.org/download.html) for more information.
+
+The tests are written using [Mocha](https://github.com/visionmedia/mocha) and
+[Should](https://github.com/visionmedia/should.js).
## Installation Instructions
@@ -20,28 +26,46 @@ Install the module with npm:
## Sample Usage
+### Read tags:
+
var ex = require('exiv2');
ex.getImageTags('./photo.jpg', function(err, tags) {
- if (err) {
- console.log(err);
- } else {
- console.log(tags);
-
console.log("DateTime: " + tags["Exif.Image.DateTime"]);
console.log("DateTimeOriginal: " + tags["Exif.Photo.DateTimeOriginal"]);
- }
});
- ex.setImageTags('./photo.jpg', { "Exif.Photo.UserComment" : "Some Comment..", "Exif.Canon.OwnerName" : "My Camera"}, function(err){
+### Load preview images:
+
+ var ex = require('exiv2')
+ , fs = require('fs');
+
+ ex.getImagePreviews('./photo.jpg', function(err, previews) {
+ // Display information about the previews.
+ console.log(previews);
+
+ // Or you can save them--though you'll probably want to check the MIME
+ // type before picking an extension.
+ fs.writeFile('preview.jpg', previews[0].data);
+ });
+
+### Write tags:
+
+ var ex = require('exiv2')
+
+ var newTags = {
+ "Exif.Photo.UserComment" : "Some Comment..",
+ "Exif.Canon.OwnerName" : "My Camera"
+ };
+ ex.setImageTags('./photo.jpg', , function(err){
if (err) {
console.log(err);
} else {
console.log("setImageTags complete..");
}
});
-See `example/simple.js`.
+Take a look at the `examples/` and `test/` directories for more.
email: dberesford at gmail
twitter: @dberesford
View
@@ -4,15 +4,15 @@ var fs = require('fs')
var dir = __dirname + '/../test/images';
-// Test basic image with exif tags
+// Test basic image with exif tags:
ex.getImageTags(dir + '/books.jpg', function(err, tags) {
console.log(tags);
});
// Make a copy of our file so we don't polute the original.
fs.writeFileSync(dir + '/copy.jpg', fs.readFileSync(dir + '/books.jpg'));
-// Set some tags on the image
+// Set some tags on the image:
var tags = {
"Exif.Photo.UserComment" : "Some books..",
"Exif.Canon.OwnerName" : "Damo's camera"
@@ -24,3 +24,15 @@ ex.setImageTags(dir + '/copy.jpg', tags, function(err){
assert.equal("Damo's camera", tags["Exif.Canon.OwnerName"]);
});
});
+
+// Load the preview images:
+ex.getImagePreviews(dir + '/books.jpg', function(err, previews) {
+ // Display information about the previews.
+ console.log("Preview images:");
+ previews.forEach(function (p, index) {
+ console.log("%d: %s %dx%dpx %d bytes", index, p.mimeType, p.height, p.width, p.data.length);
+ });
+ // Or you can save them--though you'll probably want to check the MIME type
+ // before picking an extension.
+ fs.writeFile('preview.jpg', previews[0].data);
+});
Oops, something went wrong.

0 comments on commit a252e69

Please sign in to comment.