Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/naptha/tesseract.js.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Wu <jeromewus@gmail.com>2020-09-10 11:05:38 +0300
committerJerome Wu <jeromewus@gmail.com>2020-09-10 11:05:38 +0300
commit6481256f5eeecbfaaec7984415c24c1d075ba50f (patch)
tree509958ed70a7e0c4274b316b6eb0d2ca1407932e
parent5e295b75b6789ad2dab1d034df288b2f7539eb35 (diff)
Fix lint and test error
-rw-r--r--src/worker/browser/loadImage.js28
-rw-r--r--src/worker/node/loadImage.js5
2 files changed, 23 insertions, 10 deletions
diff --git a/src/worker/browser/loadImage.js b/src/worker/browser/loadImage.js
index 8cdc050..b1cc14f 100644
--- a/src/worker/browser/loadImage.js
+++ b/src/worker/browser/loadImage.js
@@ -1,5 +1,5 @@
const resolveURL = require('resolve-url');
-const blueimp = require('blueimp-load-image');
+const blueimpLoadImage = require('blueimp-load-image');
/**
* readFromBlobOrFile
@@ -23,9 +23,16 @@ const readFromBlobOrFile = blob => (
const fixOrientationFromUrlOrBlobOrFile = blob => (
new Promise((resolve) => {
- blueimp(blob, (img) => img.toBlob(resolve, 'image/jpeg'), {orientation: true})
+ blueimpLoadImage(
+ blob,
+ img => img.toBlob(resolve),
+ {
+ orientation: true,
+ canvas: true,
+ },
+ );
})
-)
+);
/**
* loadImage
@@ -46,9 +53,13 @@ const loadImage = async (image) => {
data = atob(image.split(',')[1])
.split('')
.map(c => c.charCodeAt(0));
+ } else if (image.endsWith('.pbm')) {
+ const resp = await fetch(resolveURL(image));
+ data = await resp.arrayBuffer();
} else {
- image = await fixOrientationFromUrlOrBlobOrFile(resolveURL(image));
- data = await readFromBlobOrFile(image);
+ data = await readFromBlobOrFile(
+ await fixOrientationFromUrlOrBlobOrFile(resolveURL(image)),
+ );
}
} else if (image instanceof HTMLElement) {
if (image.tagName === 'IMG') {
@@ -66,8 +77,11 @@ const loadImage = async (image) => {
});
}
} else if (image instanceof File || image instanceof Blob) {
- image = await fixOrientationFromUrlOrBlobOrFile(image);
- data = await readFromBlobOrFile(image);
+ let img = image;
+ if (!image.name.endsWith('.pbm')) {
+ img = await fixOrientationFromUrlOrBlobOrFile(img);
+ }
+ data = await readFromBlobOrFile(img);
}
return new Uint8Array(data);
diff --git a/src/worker/node/loadImage.js b/src/worker/node/loadImage.js
index af9fdc8..11eff72 100644
--- a/src/worker/node/loadImage.js
+++ b/src/worker/node/loadImage.js
@@ -33,9 +33,8 @@ module.exports = async (image) => {
}
try {
- data = (await jo.rotate(data, {quality: 100})).buffer
- } catch (_) {
- }
+ data = (await jo.rotate(data, { quality: 100 })).buffer;
+ } catch (_) {} /* eslint-disable-line */
return new Uint8Array(data);
};