New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-tesseract

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-tesseract

A lightweight React hook for seamless integration of Tesseract.js OCR capabilities.

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

react-tesseract

A lightweight React Library for seamless integration of Tesseract.js OCR capabilities in your React applications.

Features

  • 🚀 Easy-to-use React hook
  • 🛠 Built-in error handling
  • 🎛 Flexible configuration options

Installation

Install the package using npm:

npm install react-tesseract

Basic Usage

import React, { useState } from 'react';
import { useTesseract } from 'react-tesseract';

const App = () => {
  const [imageUrl, setImageUrl] = useState('');
  const { recognize, error, result, isRecognizing } = useTesseract();

  const handleRecognize = async () => {
    if (imageUrl) {
      await recognize(imageUrl, {
        language: 'eng+ara',  // Use English and Arabic
        errorHandler: (err) => console.error(err),  // Custom error handler
        tessedit_ocr_engine_mode: 1,  // Use neural net LSTM engine only
        tessedit_pageseg_mode: 1,  // Assume a single uniform block of text
        // ... any other Tesseract.js options
      });
    }
  };

  const handleImageChange = (e) => {
    setImageUrl(URL.createObjectURL(e.target.files[0]));
  };

  return (
    <div>
      <input type="file" onChange={handleImageChange} />
      <button onClick={handleRecognize} disabled={!imageUrl || isRecognizing}>
        Recognize Text
      </button>
      {error && <p>Error: {error}</p>}
      {result && <pre>{result}</pre>}
    </div>
  );
};

export default App;

API

useTesseract()

recognize(image: string | File, options?: Object): Promise<string>

Initiates the OCR process on the provided image.

  • image: URL of the image or a File object.
  • options: (Optional) An object containing configuration options for Tesseract.js.
PropertyTypeDescription
errorstringThe error message if the OCR process fails
resultstringThe OCR result as a string
isRecognizingbooleanA boolean value indicating whether the OCR process is in progress

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License

Keywords

react-tesseract

FAQs

Package last updated on 25 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts