Browse Source

add babelrc, switch to createTesseractWorker

pull/12/head
Guillermo 8 years ago
parent
commit
1a6c9236bc
  1. 8
      .babelrc
  2. 4
      README.md
  3. 2
      dist/tesseract.js
  4. 2
      index.html
  5. 2
      src/browser/index.js
  6. 2
      webpack.config.dev.js
  7. 2
      webpack.config.prod.js

8
.babelrc

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
{
"presets": ["es2015","stage-1"],
"env": {
"development": {
"plugins": []
}
}
}

4
README.md

@ -10,9 +10,9 @@ Tesseract.js is a pure javascript version of the Tesseract OCR Engine that can r @@ -10,9 +10,9 @@ Tesseract.js is a pure javascript version of the Tesseract OCR Engine that can r
Tesseract.js works with a `<script>` tag, or with `npm` (if you're using webpack /browserify).
## `<script/>`
First grab copies of `tesseract.js` and `tesseract.worker.js` from the [dist folder](https://github.com/naptha/tesseract.js/tree/master/dist). Then include `tesseract.js on your page like this`:
```html
<script src='' />
<script src='/path/to/tesseract.js'></script>
```
## npm

2
dist/tesseract.js vendored

@ -1 +1 @@ @@ -1 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Tesseract=t():e.Tesseract=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t){"use strict";e.exports=function(){function e(e,t){var r=a++;s[r]={};var n={jobId:r,action:e,args:t};return console.log(n),o.postMessage(n),{then:function(e){return s[r].result=e,this},error:function(e){return s[r].error=e,this},progress:function(e){return s[r].progress=e,this}}}function t(e){if(e.getContext)e=e.getContext("2d");else if("IMG"==e.tagName||"VIDEO"==e.tagName){var t=document.createElement("canvas");t.width=e.naturalWidth||e.videoWidth,t.height=e.naturalHeight||e.videoHeight;var r=t.getContext("2d");r.drawImage(e,0,0),e=r}return e.getImageData&&(e=e.getImageData(0,0,e.canvas.width,e.canvas.height)),e}var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:location.href+"build/tesseract.worker.js",n=new Blob(["importScripts('"+r+"');"]),o=new Worker(window.URL.createObjectURL(n)),i=!1,a=0,s={};return o.onmessage=function(e){var t=e.data,r=t.jobId,n=t.progress,o=t.error,i=t.result,a=s[r];n&&a.progress&&a.progress(n),o&&a.error&&a.error(o),i&&a.result&&a.result(i)},e("init",{mem:100663296}),{detect:function(r){return e("detect",{image:t(r)})},recognize:function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"eng";return"string"==typeof n?n={lang:n}:n.lang=n.lang||"eng",i||["chi_sim","chi_tra","jpn"].indexOf(n.lang)==-1||(e("init",{mem:167772160}),i=!0),e("recognize",{options:n,image:t(r)})}}}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.createTesseractWorker=t():e.createTesseractWorker=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t){"use strict";e.exports=function(){function e(e,t){var r=a++;s[r]={};var n={jobId:r,action:e,args:t};return console.log(n),o.postMessage(n),{then:function(e){return s[r].result=e,this},error:function(e){return s[r].error=e,this},progress:function(e){return s[r].progress=e,this}}}function t(e){if(e.getContext)e=e.getContext("2d");else if("IMG"==e.tagName||"VIDEO"==e.tagName){var t=document.createElement("canvas");t.width=e.naturalWidth||e.videoWidth,t.height=e.naturalHeight||e.videoHeight;var r=t.getContext("2d");r.drawImage(e,0,0),e=r}return e.getImageData&&(e=e.getImageData(0,0,e.canvas.width,e.canvas.height)),e}var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:location.href+"build/tesseract.worker.js",n=new Blob(["importScripts('"+r+"');"]),o=new Worker(window.URL.createObjectURL(n)),i=!1,a=0,s={};return o.onmessage=function(e){var t=e.data,r=t.jobId,n=t.progress,o=t.error,i=t.result,a=s[r];n&&a.progress&&a.progress(n),o&&a.error&&a.error(o),i&&a.result&&a.result(i)},e("init",{mem:100663296}),{detect:function(r){return e("detect",{image:t(r)})},recognize:function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"eng";return"string"==typeof n?n={lang:n}:n.lang=n.lang||"eng",i||["chi_sim","chi_tra","jpn"].indexOf(n.lang)==-1||(e("init",{mem:167772160}),i=!0),e("recognize",{options:n,image:t(r)})}}}}])});

2
index.html

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
ctx.font = '30px sans-serif'
ctx.fillText('the Cosmic Void', 100, 120)
var tesseract = Tesseract();
var tesseract = createTesseractWorker();
tesseract.recognize(canvas, {
tessedit_char_blacklist: 'e'

2
src/browser/index.js

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
//TODO: replace with cdn url
module.exports = function Tesseract(url=location.href+'build/tesseract.worker.js'){
module.exports = function createTesseractWorker(url=location.href+'build/tesseract.worker.js'){
var blob = new Blob(["importScripts('"+url+"');"])
var worker = new Worker(window.URL.createObjectURL(blob));

2
webpack.config.dev.js

@ -29,7 +29,7 @@ module.exports = [{ @@ -29,7 +29,7 @@ module.exports = [{
entry: './src/browser/index.js',
output: {
filename: 'tesseract.js',
library: "Tesseract",
library: "createTesseractWorker",
libraryTarget: "umd"
},
include: [path.join(__dirname, 'src/browser')]

2
webpack.config.prod.js

@ -33,7 +33,7 @@ module.exports = [{ @@ -33,7 +33,7 @@ module.exports = [{
entry: './src/browser/index.js',
output: {
filename: 'tesseract.js',
library: "Tesseract",
library: "createTesseractWorker",
libraryTarget: "umd"
},
include: [path.join(__dirname, 'src/browser')]

Loading…
Cancel
Save