*/
loadFile: function (file) {
var exif = undefined;
+ var fileData = Promise.resolve(file);
if (file.type === 'image/jpeg') {
// Extract EXIF data
exif = ExifUtil.getExifBytesFromJpeg(file);
+
+ // Strip EXIF data
+ fileData = fileData.then(ExifUtil.removeExifData.bind(ExifUtil));
}
- var loader = new Promise(function (resolve, reject) {
- var reader = new FileReader();
- var image = new Image();
-
- reader.addEventListener('load', function () {
- image.src = reader.result;
- });
-
- reader.addEventListener('error', function () {
- reader.abort();
- reject(reader.error);
- });
-
- image.addEventListener('error', reject);
-
- image.addEventListener('load', function () {
- resolve(image);
+ var fileData = fileData
+ .then(function (blob) {
+ return new Promise(function (resolve, reject) {
+ var reader = new FileReader();
+ var image = new Image();
+
+ reader.addEventListener('load', function () {
+ image.src = reader.result;
+ });
+
+ reader.addEventListener('error', function () {
+ reader.abort();
+ reject(reader.error);
+ });
+
+ image.addEventListener('error', reject);
+
+ image.addEventListener('load', function () {
+ resolve(image);
+ });
+
+ reader.readAsDataURL(blob);
+ });
});
-
- reader.readAsDataURL(file);
- });
- return Promise.all([ exif, loader ])
+ return Promise.all([ exif, fileData ])
.then(function (result) {
return { exif: result[0], image: result[1] };
});