So, I've managed to figure this out.
The date/time stamp along with a bunch of other information can be retrieved from the EXIF data tags inside the JPEG file. This can be done using this helpful JS library - https://github.com/jseidelin/exif-js
Unfortunately the Cordova camera plugin for Android doesn't copy EXIF tags when transforming an image selected from the gallery, only when taking an image using the camera, so this is a problem, but I will fix this by forking the plugin. The iOS version of the plugin seems to do this right thing.
Code for anyone interested -
var source = fromCamera
? Camera.PictureSourceType.CAMERA
: Camera.PictureSourceType.PHOTOLIBRARY;
var opts = {
encodingType: Camera.EncodingType.JPEG,
sourceType: source,
destinationType: Camera.DestinationType.NATIVE_URI
};
navigator.camera.getPicture(
function(imageURI) {
window.resolveLocalFileSystemURL(imageURI,
function(entry) {
entry.file(function(file) {
EXIF.getData(file, function() {
var datetime = EXIF.getTag(this, "DateTimeOriginal");
alert(datetime);
});
// do something useful....
}, standardErrorHandler);
},
function(e) {
alert('Unexpected error obtaining image file.');
standardErrorHandler(e);
});
},
function() {
// nada - cancelled
},
opts);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…