Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/exif/ExifImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.');
}
Expand Down