Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/output to file #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const log = console.debug
function recognize(filename, config = {}) {
const options = getOptions(config)
const binary = config.binary || "tesseract"
const outputName = config.outputName || 'stdout'

const command = [binary, `"${filename}"`, "stdout", ...options].join(" ")
const command = [binary, `"${filename}"`, outputName, ...options].join(" ")
if (config.debug) log("command", command)

return new Promise((resolve, reject) => {
Expand All @@ -22,7 +23,7 @@ function getOptions(config) {

return Object.entries(config)
.map(([key, value]) => {
if (["debug", "presets", "binary"].includes(key)) return
if (["debug", "presets", "binary", "outputFile"].includes(key)) return
if (key === "lang") return `-l ${value}`
if (ocrOptions.includes(key)) return `--${key} ${value}`

Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm install node-tesseract-ocr
```js
const tesseract = require("node-tesseract-ocr")

// other options documented below
const config = {
lang: "eng",
oem: 1,
Expand All @@ -41,3 +42,18 @@ const result = await tesseract.recognize("image.jpg", {
presets: ["tsv"],
})
```

## Available Config Options
```js
config = {
// debug
// will output progress/results to console
// default = false
debug: true,

// outputName
// will produce file containing results, instead of returning results
// default = stdout, returns results
outputName: './output/fileName'
}
```