diff --git a/lib/exif/ExifImage.js b/lib/exif/ExifImage.js index 75fc4be..bee398b 100644 --- a/lib/exif/ExifImage.js +++ b/lib/exif/ExifImage.js @@ -9,6 +9,17 @@ var debug = require('debug')('exif'); var DEFAULT_MAX_ENTRIES=128; +function base64ToArrayBuffer(base64) { + base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, ''); + var binary = atob(base64); + var len = binary.length; + var view = new Uint8Array(new ArrayBuffer(len)); + for (var i = 0; i < len; i++) { + view[i] = binary.charCodeAt(i); + } + return view.buffer; +} + /** * Represents an image with Exif information. When instantiating it you have to * provide an image and a callback function which is called once all metadata @@ -107,7 +118,20 @@ function ExifImage (options, callback) { // callback(new Error('You have to provide an image, it is pretty hard to extract Exif data from nothing...')); return; } - + + if (ops.hasOwnProperty('imageDataType')) { + switch (ops.imageDataType.toLowerCase()) { + case 'base64': + ops.image = new Buffer(base64ToArrayBuffer(ops.image)); + break; + case 'arraybuffer': + ops.image = new Buffer(ops.image); + break; + default: + break; + } + } + if (typeof callback !== 'function') { throw new Error('You have to provide a callback function.'); }