Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed exif auto-rotation for browser per #604 #634

Merged
merged 1 commit into from
Aug 11, 2022
Merged
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
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