Browse Source

fix images' rotation based on exif data

pull/440/head
rogerxaic 5 years ago
parent
commit
a54dbc345b
  1. 5
      package-lock.json
  2. 1
      package.json
  3. 12
      src/worker/browser/loadImage.js

5
package-lock.json generated

@ -1785,6 +1785,11 @@
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==",
"dev": true "dev": true
}, },
"blueimp-load-image": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/blueimp-load-image/-/blueimp-load-image-3.0.0.tgz",
"integrity": "sha512-Q9rFbd4ZUNvzSFmRXx9MoG0RwWwJeMjjEUbG7WIOJgUg22Jgkow0wL5b35B6qwiBscxACW9OHdrP5s2vQ3x8DQ=="
},
"bmp-js": { "bmp-js": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz", "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz",

1
package.json

@ -58,6 +58,7 @@
"webpack-dev-middleware": "^3.7.2" "webpack-dev-middleware": "^3.7.2"
}, },
"dependencies": { "dependencies": {
"blueimp-load-image": "^3.0.0",
"bmp-js": "^0.1.0", "bmp-js": "^0.1.0",
"file-type": "^12.4.1", "file-type": "^12.4.1",
"idb-keyval": "^3.2.0", "idb-keyval": "^3.2.0",

12
src/worker/browser/loadImage.js

@ -1,4 +1,5 @@
const resolveURL = require('resolve-url'); const resolveURL = require('resolve-url');
const blueimp = require('blueimp-load-image');
/** /**
* readFromBlobOrFile * readFromBlobOrFile
@ -20,6 +21,12 @@ const readFromBlobOrFile = blob => (
}) })
); );
const fixOrientationFromUrlOrBlobOrFile = blob => (
new Promise((resolve) => {
blueimp(blob, (img) => img.toBlob(resolve, 'image/jpeg'), {orientation: true})
})
)
/** /**
* loadImage * loadImage
* *
@ -40,8 +47,8 @@ const loadImage = async (image) => {
.split('') .split('')
.map(c => c.charCodeAt(0)); .map(c => c.charCodeAt(0));
} else { } else {
const resp = await fetch(resolveURL(image)); image = await fixOrientationFromUrlOrBlobOrFile(resolveURL(image));
data = await resp.arrayBuffer(); data = await readFromBlobOrFile(image);
} }
} else if (image instanceof HTMLElement) { } else if (image instanceof HTMLElement) {
if (image.tagName === 'IMG') { if (image.tagName === 'IMG') {
@ -59,6 +66,7 @@ const loadImage = async (image) => {
}); });
} }
} else if (image instanceof File || image instanceof Blob) { } else if (image instanceof File || image instanceof Blob) {
image = await fixOrientationFromUrlOrBlobOrFile(image);
data = await readFromBlobOrFile(image); data = await readFromBlobOrFile(image);
} }

Loading…
Cancel
Save