Browse Source

Update README.md and add error handler in loadImage

support/1.x
Jerome Wu 6 years ago
parent
commit
1f497271b5
  1. 3
      README.md
  2. 27
      dist/tesseract.js
  3. 2
      dist/tesseract.min.js
  4. 2
      dist/tesseract.min.js.map
  5. 8
      src/browser/index.js

3
README.md

@ -24,6 +24,9 @@ Tesseract.js wraps an [emscripten](https://github.com/kripken/emscripten) [port] @@ -24,6 +24,9 @@ Tesseract.js wraps an [emscripten](https://github.com/kripken/emscripten) [port]
# Installation
**Tesseract.js v2 alpha is now available!! Check [HERE](https://github.com/naptha/tesseract.js) for more information.**
Tesseract.js works with a `<script>` tag via local copy or CDN, with webpack and Browserify via `npm`, and on Node.js via `npm`. [Check out the docs](#docs) for a full treatment of the API.
## &lt;script />

27
dist/tesseract.js vendored

@ -253,9 +253,11 @@ if (process.env.TESS_ENV === "development") { @@ -253,9 +253,11 @@ if (process.env.TESS_ENV === "development") {
exports.defaultOptions = defaultOptions;
exports.spawnWorker = function spawnWorker(instance, workerOptions) {
if (window.Blob && window.URL) {
var blob = new Blob(['importScripts("' + workerOptions.workerPath + '");']);
var worker = new Worker(window.URL.createObjectURL(blob));
if (Blob && URL) {
var blob = new Blob(['importScripts("' + workerOptions.workerPath + '");'], {
type: 'application/javascript'
});
var worker = new Worker(URL.createObjectURL(blob));
} else {
var worker = new Worker(workerOptions.workerPath);
}
@ -290,20 +292,26 @@ function loadImage(image, cb) { @@ -290,20 +292,26 @@ function loadImage(image, cb) {
im.onload = function (e) {
return loadImage(im, cb);
};
im.onerror = function (e) {
throw e;
};
return;
} else {
var xhr = new XMLHttpRequest();
xhr.open('GET', image, true);
xhr.responseType = "blob";
xhr.onload = function (e) {
return loadImage(xhr.response, cb);
if (xhr.status >= 400) {
throw new Error('Fail to get image as Blob');
} else {
loadImage(xhr.response, cb);
}
};
xhr.onerror = function (e) {
if (/^https?:\/\//.test(image) && !/^https:\/\/crossorigin.me/.test(image)) {
console.debug('Attempting to load image with CORS proxy');
loadImage('https://crossorigin.me/' + image, cb);
}
throw e;
};
xhr.send(null);
return;
}
@ -313,6 +321,9 @@ function loadImage(image, cb) { @@ -313,6 +321,9 @@ function loadImage(image, cb) {
fr.onload = function (e) {
return loadImage(fr.result, cb);
};
fr.onerror = function (e) {
throw e;
};
fr.readAsDataURL(image);
return;
} else if (image instanceof Blob) {

2
dist/tesseract.min.js vendored

File diff suppressed because one or more lines are too long

2
dist/tesseract.min.js.map vendored

File diff suppressed because one or more lines are too long

8
src/browser/index.js

@ -54,7 +54,7 @@ function loadImage(image, cb){ @@ -54,7 +54,7 @@ function loadImage(image, cb){
var im = new Image
im.src = image;
im.onload = e => loadImage(im, cb);
//im.onerror = e => ?; TODO handle error
im.onerror = e => { throw e; };
return
}else{
var xhr = new XMLHttpRequest();
@ -63,12 +63,12 @@ function loadImage(image, cb){ @@ -63,12 +63,12 @@ function loadImage(image, cb){
xhr.onload = e => {
if (xhr.status >= 400){
//TODO handle error
throw new Error('Fail to get image as Blob');
}else{
loadImage(xhr.response, cb);
}
};
//xhr.onerror = e => ?; TODO handle error
xhr.onerror = e => { throw e; };
xhr.send(null)
return
@ -77,7 +77,7 @@ function loadImage(image, cb){ @@ -77,7 +77,7 @@ function loadImage(image, cb){
// files
var fr = new FileReader()
fr.onload = e => loadImage(fr.result, cb);
//fr.onerror = e => ?; TODO handle error
fr.onerror = e => { throw e; };
fr.readAsDataURL(image)
return
}else if(image instanceof Blob){

Loading…
Cancel
Save