Package Exports
- wx-ocr
- wx-ocr/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wx-ocr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
wx-ocr
Super simple OCR for Node.js - One line to recognize text from images.
Features
- 🚀 Super simple API - just one function call
- 📦 No installation required - includes all necessary files
- 🎯 High accuracy OCR engine
- ⚡ Fast processing
- 🔧 Easy to use - no complex configuration
Installation
npm install wx-ocrQuick Start
const { ocr } = require('wx-ocr');
// Recognize text from image
const result = await ocr('image.png');
console.log(result);
// Get only text
const text = await ocr('image.png', { returnTextOnly: true });
console.log(text);
// Get formatted text with line breaks
const formatted = await ocr('image.png', {
returnTextOnly: true,
formatText: true
});
console.log(formatted);API
ocr(imagePath, options)
Recognize text from a single image.
Parameters:
imagePath(string): Path to image fileoptions(object, optional):returnTextOnly(boolean): Return only text array, default: falseformatText(boolean): Format text with line breaks, default: false
Returns: Promise<Array|string|Object>
Example:
// Full result with location info
const result = await ocr('image.png');
// {
// taskId: 1,
// ocrResult: [
// { text: 'Hello', location: { left: 10, top: 20, right: 100, bottom: 50 } },
// { text: 'World', location: { left: 10, top: 60, right: 100, bottom: 90 } }
// ]
// }
// Text only
const texts = await ocr('image.png', { returnTextOnly: true });
// ['Hello', 'World']
// Formatted text
const formatted = await ocr('image.png', { returnTextOnly: true, formatText: true });
// "Hello\nWorld"ocrBatch(imagePaths, options)
Recognize text from multiple images.
Parameters:
imagePaths(string[]): Array of image pathsoptions(object, optional): Same asocr()
Returns: Promise
Example:
const results = await ocrBatch(['img1.png', 'img2.png']);CLI Usage
# Single image
wx-ocr ocr image.png
# Text only
wx-ocr ocr image.png --text-only
# Formatted text
wx-ocr ocr image.png --text-only --format
# Batch processing
wx-ocr batch image1.png image2.pngExamples
Basic Usage
const { ocr } = require('wx-ocr');
async function main() {
const result = await ocr('screenshot.png');
console.log(result);
}
main();Batch Processing
const { ocrBatch } = require('wx-ocr');
async function main() {
const images = ['img1.png', 'img2.png', 'img3.png'];
const results = await ocrBatch(images, { returnTextOnly: true });
results.forEach((text, i) => {
console.log(`Image ${i + 1}:`, text);
});
}
main();With Express.js
const express = require('express');
const { ocr } = require('wx-ocr');
const multer = require('multer');
const app = express();
const upload = multer({ dest: 'uploads/' });
app.post('/ocr', upload.single('image'), async (req, res) => {
try {
const result = await ocr(req.file.path, { returnTextOnly: true });
res.json({ text: result });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000);How It Works
This package includes a high-performance OCR engine with all necessary data files. The engine runs as a separate process and communicates via IPC for optimal performance.
Requirements
- Windows OS
- Node.js 14+
License
MIT