diff --git a/index.html b/index.html
index 8b44c9a..63a7d64 100644
--- a/index.html
+++ b/index.html
@@ -16,6 +16,7 @@
var tesseract = createTesseractWorker();
+ // tesseract.recognize('http://localhost:7355/westmorland.jpg')
tesseract.recognize(canvas, {
tessedit_char_blacklist: 'e'
})
diff --git a/src/browser/index.js b/src/browser/index.js
index b6260df..f54f584 100644
--- a/src/browser/index.js
+++ b/src/browser/index.js
@@ -8,11 +8,23 @@ module.exports = function createTesseractWorker(url=location.href+'build/tessera
var handlers = {}
function runAsync(action, args){
+
var jobId = jobCounter++
handlers[jobId] = {}
- var message = {jobId, action, args}
- console.log(message)
- worker.postMessage(message)
+
+ var waitingCount = 0
+ Object.getOwnPropertyNames(args).forEach(name => {
+ if(typeof args[name] === 'function'){
+ waitingCount++
+ args[name](value => {
+ args[name] = value
+ if(--waitingCount == 0) worker.postMessage({jobId, action, args})
+ })
+ }
+ })
+
+ if(waitingCount == 0) worker.postMessage({jobId, action, args})
+
return {
then (f){ handlers[jobId].result = f; return this},
error (f){ handlers[jobId].error = f; return this},
@@ -29,6 +41,16 @@ module.exports = function createTesseractWorker(url=location.href+'build/tessera
}
function convertToImageData(image){
+
+ if(image.match && image.match(/^https?:\/\//)) {
+ return function thunk(cb){
+ var img = new Image()
+ img.src = image
+ img.onload = () => cb(convertToImageData(img))
+ }
+ }
+
+ if(typeof image === 'string') image = document.querySelector(image)
if(image.getContext) image = image.getContext('2d');
else if(image.tagName == "IMG" || image.tagName == "VIDEO"){
var c = document.createElement('canvas');