Skip to content

Commit

Permalink
Removed exif auto-rotation for browser per #604 (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Aug 11, 2022
1 parent 75ddd63 commit a9ac00c
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/worker/browser/loadImage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const resolveURL = require('resolve-url');
const blueimpLoadImage = require('blueimp-load-image');

/**
* readFromBlobOrFile
Expand All @@ -21,19 +20,6 @@ const readFromBlobOrFile = (blob) => (
})
);

const fixOrientationFromUrlOrBlobOrFile = (blob) => (
new Promise((resolve) => {
blueimpLoadImage(
blob,
(img) => img.toBlob(resolve),
{
orientation: true,
canvas: true,
},
);
})
);

/**
* loadImage
*
Expand All @@ -48,18 +34,14 @@ const loadImage = async (image) => {
}

if (typeof image === 'string') {
if (image.endsWith('.pbm')) {
// Base64 Image
if (/data:image\/([a-zA-Z]*);base64,([^"]*)/.test(image)) {
data = atob(image.split(',')[1])
.split('')
.map((c) => c.charCodeAt(0));
} else {
const resp = await fetch(resolveURL(image));
data = await resp.arrayBuffer();
} else {
let img = image;
// If not Base64 Image
if (!/data:image\/([a-zA-Z]*);base64,([^"]*)/.test(image)) {
img = resolveURL(image);
}
data = await readFromBlobOrFile(
await fixOrientationFromUrlOrBlobOrFile(img),
);
}
} else if (image instanceof HTMLElement) {
if (image.tagName === 'IMG') {
Expand All @@ -77,11 +59,7 @@ const loadImage = async (image) => {
});
}
} else if (image instanceof File || image instanceof Blob) {
let img = image;
if (!image.name.endsWith('.pbm')) {
img = await fixOrientationFromUrlOrBlobOrFile(img);
}
data = await readFromBlobOrFile(img);
data = await readFromBlobOrFile(image);
}

return new Uint8Array(data);
Expand Down

0 comments on commit a9ac00c

Please sign in to comment.