Browse Source

cors proxy

pull/12/head
Kevin Kwok 8 years ago
parent
commit
1a7429d022
  1. 2
      README.md
  2. 8
      dist/tesseract.js
  3. 2
      dist/worker.js
  4. 8
      src/browser/index.js
  5. 2
      src/browser/worker.js

2
README.md

@ -37,7 +37,7 @@ Or you can grab copies of `tesseract.js` and `worker.js` from the [dist folder]( @@ -37,7 +37,7 @@ Or you can grab copies of `tesseract.js` and `worker.js` from the [dist folder](
window.Tesseract = Tesseract.create({
workerPath: '/path/to/worker.js',
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/',
tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
})
</script>
```

8
dist/tesseract.js vendored

@ -271,7 +271,7 @@ process.umask = function() { return 0; }; @@ -271,7 +271,7 @@ process.umask = function() { return 0; };
var defaultOptions = {
workerPath: 'https://cdn.rawgit.com/naptha/tesseract.js/0.1.3/dist/worker.js',
tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/'
};
@ -328,6 +328,12 @@ function loadImage(image, cb) { @@ -328,6 +328,12 @@ function loadImage(image, cb) {
xhr.onload = function (e) {
return 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);
}
};
xhr.send(null);
return;
}

2
dist/worker.js vendored

@ -11944,7 +11944,7 @@ global.addEventListener('message', function (e) { @@ -11944,7 +11944,7 @@ global.addEventListener('message', function (e) {
exports.getCore = function (req, res) {
if (!global.TesseractCore) {
res.progress({ status: 'loading tesseract core' });
importScripts(req.workerOptions.tesseractPath);
importScripts(req.workerOptions.corePath);
res.progress({ status: 'loaded tesseract core' });
}
return TesseractCore;

8
src/browser/index.js

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
var defaultOptions = {
workerPath: 'https://cdn.rawgit.com/naptha/tesseract.js/0.1.3/dist/worker.js',
tesseractPath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
corePath: 'https://cdn.rawgit.com/naptha/tesseract.js-core/0.1.0/index.js',
langPath: 'https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/',
}
@ -56,6 +56,12 @@ function loadImage(image, cb){ @@ -56,6 +56,12 @@ function loadImage(image, cb){
xhr.open('GET', image, true)
xhr.responseType = "blob";
xhr.onload = e => 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)
}
}
xhr.send(null)
return
}

2
src/browser/worker.js

@ -12,7 +12,7 @@ global.addEventListener('message', function(e){ @@ -12,7 +12,7 @@ global.addEventListener('message', function(e){
exports.getCore = function(req, res){
if(!global.TesseractCore){
res.progress({ status: 'loading tesseract core' })
importScripts(req.workerOptions.tesseractPath)
importScripts(req.workerOptions.corePath)
res.progress({ status: 'loaded tesseract core' })
}
return TesseractCore

Loading…
Cancel
Save