Skip to content

Commit

Permalink
Fix image rotation for images which are not JPEGs
Browse files Browse the repository at this point in the history
* allow for every image type except SVGs
* if no orientation is read, default to 1 (means no rotation applied)
  • Loading branch information
Bruno Besson committed Apr 15, 2021
1 parent a4d340a commit 745c48e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/js/upload-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ const parseMetaData = (document, metaData) => {

const preProcess = async (file, document, orientation, onDataUrlReady) => {
let options = {};
// fix orientation for JPEGs, based on EXIF
if (file.type === 'image/jpeg' && orientation) {
// fix orientation
if (orientation) {
options = { ...options, orientation };
}

Expand Down Expand Up @@ -168,7 +168,8 @@ const uploadFile = async (file, angle, onDataUrlReady, onUploadProgress, onSucce
const metaData = await loadImage.parseMetaData(file);
let orientation = await parseMetaData(document, metaData);
if (angle) {
orientation = orientations[(orientations.indexOf(orientation) + angle / 90) % 4];
// if no orientation has been retrieved, consider value 1 (no rotation)
orientation = orientations[(orientations.indexOf(orientation || 1) + angle / 90) % 4];
}
const data = await preProcess(file, document, orientation, onDataUrlReady);
// do the upload
Expand Down

0 comments on commit 745c48e

Please sign in to comment.