You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it'd be good to provide some more examples. One I'd thought about was dealing with dates, something like:
var fs = require('fs')
, path = require('path')
, exiv = require('exiv2')
, async = require('async');
/**
* Convert exiv2's date time strings into Date instances.
*
* The first parameter is the date string from exiv2, e.g. '2012:04:14 17:45:52'
* a tag like 'Exif.Photo.DateTimeOriginal'.
*
* The second parameter may be hundredths of a second (0-99) to add to the date,
* e.g. the Exif.Photo.SubSecTimeOriginal tag. This can be useful when sorting
* photos by time and photos may have may been taken in a single second.
*/
function makeDate(exivDate, subSec) {
// Date.parse() doesn't recognize the custom format so the easiest thing to
// do is convert it to ISO 8601 (e.g. "2012-04-14T17:45:52") which it
// recognizes. The colons in the date need to become hyphens and the space
// needs to become a 'T'.
// So split it into two...
var datetime = exivDate.split(' ');
// ...then change the colons in date into hyphens...
datetime[0] = datetime[0].replace(/:/g, '-');
// ...then join it back together with a 'T' and parse it.
var d = new Date(Date.parse(datetime.join('T')));
// If they provided sub-second data, scale it from hundredths of a second to
// thousands and apply it to the date.
if (subSec) d.setMilliseconds(subSec * 10)
return d;
}
var dirpath = '100EOS5D';
path.exists(dirpath, function (exists) {
if (exists) {
if (fs.statSync(dirpath).isDirectory()) {
var files = fs.readdirSync(dirpath);
// Use async to handle a all the delayed callbacks.
async.sortBy(files,
function iterate(filename, done) {
var filepath = path.join(dirpath, filename),
sequence = /^IMG_(\d{4})\.CR2$/i.exec(filename);
// Make sure it's one of my photos.
if (sequence) {
exiv.getImageTags(filepath, function(err, tags) {
var date = makeDate(tags['Exif.Photo.DateTimeOriginal'], tags['Exif.Photo.SubSecTimeOriginal']);
// console.log("%s: %s", filename, date);
done(err, date);
});
}
},
function complete(err, sorted) {
console.log(sorted);
}
);
}
}
});
But I need to debug this.
The text was updated successfully, but these errors were encountered:
I think it'd be good to provide some more examples. One I'd thought about was dealing with dates, something like:
But I need to debug this.
The text was updated successfully, but these errors were encountered: