{"id":15637036,"url":"https://github.com/kaelzhang/penteract-ocr","last_synced_at":"2025-04-14T16:21:57.622Z","repository":{"id":49764319,"uuid":"101128549","full_name":"kaelzhang/penteract-ocr","owner":"kaelzhang","description":"⭐️ The native node.js bindings to the Tesseract OCR project.","archived":false,"fork":false,"pushed_at":"2018-09-10T09:40:00.000Z","size":1055,"stargazers_count":124,"open_issues_count":10,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T03:16:13.093Z","etag":null,"topics":["n-api","nodejs","ocr","ocr-engine","optical-character-recognition","penteract","tesseract"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-23T02:28:02.000Z","updated_at":"2025-03-11T16:23:07.000Z","dependencies_parsed_at":"2022-08-30T14:01:07.289Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/penteract-ocr","commit_stats":null,"previous_names":["kaelzhang/node-penteract"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fpenteract-ocr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fpenteract-ocr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fpenteract-ocr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Fpenteract-ocr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/penteract-ocr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248662358,"owners_count":21141562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["n-api","nodejs","ocr","ocr-engine","optical-character-recognition","penteract","tesseract"],"created_at":"2024-10-03T11:09:41.806Z","updated_at":"2025-04-14T16:21:57.599Z","avatar_url":"https://github.com/kaelzhang.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-penteract.svg?branch=master)](https://travis-ci.org/kaelzhang/node-penteract)\n[![Coverage](https://codecov.io/gh/kaelzhang/node-penteract/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/node-penteract)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-penteract?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/node-penteract)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/node-penteract.svg)](http://badge.fury.io/js/node-penteract)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/node-penteract.svg)](https://www.npmjs.org/package/node-penteract)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/node-penteract.svg)](https://david-dm.org/kaelzhang/node-penteract)\n--\u003e\n\n# penteract\n\n\u003cimg align=\"right\" alt=\"\" src=\"https://raw.githubusercontent.com/kaelzhang/node-penteract/master/penteract.gif\" /\u003e\n\nThe native Node.js bindings to the [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) project.\n\n- Using Node.js bindings, avoid spawning `tesseract` command line.  \n- Asynchronous I/O: Image reading and processing in insulated event loop backed by [libuv](https://github.com/libuv/libuv).\n- Support to read image data from JavaScript `buffer`s.\n\nContributions are welcome.\n\n## Install\n\nFirst of all, a g++ 4.9 compiler is required.\n\nBefore install `penteract`, the following dependencies should be installed\n\n```sh\n$ brew install pkg-config tesseract # mac os\n```\n\nThen npm install\n\n```sh\n$ npm install penteract\n```\n\n### To Use with Electron\n\nDue to the limitation of node native modules, if you want to use `penteract` with electron, add a `.npmrc` file to the root of your electron project, before `npm install`:\n\n```ini\nruntime = electron\n; The version of the local electron,\n; use `npm ls electron` to figure it out\ntarget = 1.7.5\ntarget_arch = x64\ndisturl = https://atom.io/download/atom-shell\n```\n\n\u003c!--\n\n### The N-API version of `penteract`\n\nThe N-API version of `penteract` (penteract@n-api) is and will be remaining experimental before the feature of N-API stabilized in Node.js 8.0 and ported to older Node.js LTS lines ([via](https://medium.com/the-node-js-collection/n-api-next-generation-node-js-apis-for-native-modules-169af5235b06)).\n\nFor now, it is recommended to use `penteract@latest`\n\n--\u003e\n\n## Usage\n\n### Recognize an Image Buffer\n\n```js\nimport {\n  recognize\n} from 'penteract'\n\nimport fs from 'fs-extra'\n\nconst filepath = path.join(__dirname, 'test', 'fixtures', 'penteract.jpg')\n\nfs.readFile(filepath).then(recognize).then(console.log) // 'penteract'\n```\n\n### Recognize a Local Image File\n\n```js\nimport {\n  fromFile\n} from 'penteract'\n\nfromFile(filepath, {lang: 'eng'}).then(console.log)     // 'penteract'\n```\n\n## recognize(image [, options])\n\n- **image** `Buffer` the content buffer of the image file.\n- **options** `PenteractOptions=` optional\n\nReturns `Promise.\u003cString\u003e` the recognized text if succeeded.\n\n## fromFile(filepath [, options])\n\n- **filepath** `Path` the file path of the image file.\n- **options** `PenteractOptions=`\n\nReturns `Promise.\u003cString\u003e`\n\n### `PenteractOptions` `Object`\n\n\n```js\n{\n  // @type `(String|Array.\u003cString\u003e)=eng`,\n  //\n  // Specifies language(s) used for OCR.\n  //   Run `tesseract --list-langs` in command line for all supported languages.\n  //   Defaults to `'eng'`.\n  //\n  // To specify multiple languages, use an array.\n  //   English and Simplified Chinese, for example:\n  // ```\n  // lang: ['eng', 'chi_sim']\n  // ```\n  lang: 'eng'\n}\n```\n\n## `Promise.reject(error)`\n\n- **error** `Error` The JavaScript `Error` instance\n  - **code** `String` Error code.\n  - **message** `String` Error message.\n  - other properties of `Error`.\n\n### code: `ERR_READ_IMAGE`\n\nRejects if it fails to read image data from file or buffer.\n\n### code: `ERR_INIT_TESSER`\n\nRejects if tesseract fails to initialize\n\n## Example of Using with Electron\n\n```js\n// For details of `mainWindow: BrowserWindow`, see\n// https://github.com/electron/electron/blob/master/docs/api/browser-window.md\nmainWindow.capturePage({\n  x: 10,\n  y: 10,\n  width: 100,\n  height: 10\n\n}, (data) =\u003e {\n  recognize(data.toPNG()).then(console.log)\n})\n```\n\n## Compiling Troubles\n\nFor Mac OS users, if you are experiencing trouble when compiling, run the following command:\n\n```sh\n$ xcode-select --install\n```\n\nwill resolve most problems.\n\nWarnings:\n\n```\nxcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance\n```\n\nresolver:\n\n```sh\n$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fpenteract-ocr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Fpenteract-ocr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Fpenteract-ocr/lists"}