
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
@fnet/ocr-text-coords
Advanced tools
This project is designed to facilitate the extraction of text and their corresponding bounding box coordinates from images, using the Tesseract.js library. It supports various input formats such as file paths, URLs, or Base64 encoded strings and can handl
This project is designed to facilitate the extraction of text and their corresponding bounding box coordinates from images, using the Tesseract.js library. It supports various input formats such as file paths, URLs, or Base64 encoded strings and can handle multiple languages.
The project uses Tesseract.js to perform Optical Character Recognition (OCR) on a given image. You provide an image through a file path, URL, or Base64 string, along with a language specification. The project then processes the image, identifying text and marking each word's location with a bounding box. This information is returned as a structured object containing both the extracted text and coordinates.
This project offers a straightforward way to extract and locate text within images, applicable to a variety of formats and languages. It provides a simple interface to access Tesseract.js capabilities, returning structured results that can be easily integrated into further processing or analysis tasks.
The @fnet/ocr-text-coords
library is designed to help developers extract textual content from images along with their bounding box coordinates. Using Optical Character Recognition (OCR) powered by Tesseract.js, this library supports images provided via file paths, URLs, or Base64 strings. Developers can easily integrate this functionality into applications where text extraction from visual media is required.
You can install the @fnet/ocr-text-coords
library using either npm or yarn:
npm install @fnet/ocr-text-coords
Or with yarn:
yarn add @fnet/ocr-text-coords
The library provides a simple public function that you can use to extract text from images:
First, import the library into your project:
import extractTextWithCoords from '@fnet/ocr-text-coords';
You can then use the function to process an image:
(async () => {
try {
const result = await extractTextWithCoords({ imageInput: 'path/to/your/image.jpg', language: 'eng' });
console.log(result.text); // Outputs full extracted text
console.log(result.words); // Outputs array of words with bounding boxes
} catch (error) {
console.error('Error extracting text:', error.message);
}
})();
imageInput
: A string representing the image input. This can be a file path, a URL, or a Base64-encoded string.language
(optional): A string specifying the language(s) for OCR. The default is "eng"
. You can specify multiple languages by joining their codes with a plus sign (e.g., "eng+tur"
).Here are a few practical examples demonstrating typical use cases:
import extractTextWithCoords from '@fnet/ocr-text-coords';
// Process an image from a local file
(async () => {
const result = await extractTextWithCoords({ imageInput: './local-image.png' });
console.log(result);
})();
import extractTextWithCoords from '@fnet/ocr-text-coords';
// Process an image from a URL
(async () => {
const result = await extractTextWithCoords({ imageInput: 'https://example.com/image.jpg', language: 'eng+spa' });
console.log(result);
})();
import extractTextWithCoords from '@fnet/ocr-text-coords';
// Process an image from a Base64 string
(async () => {
const base64String = 'data:image/png;base64,iVBORw0KGgoAAAANS...';
const result = await extractTextWithCoords({ imageInput: base64String });
console.log(result);
})();
This library uses Tesseract.js for OCR processing. Tesseract.js is an open-source OCR engine supported by an active developer community.
$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
imageInput:
type: string
description: The path, URL, or Base64 string of the image to be processed.
language:
type: string
description: The language code(s) to use for OCR (e.g., "eng", "tur", or "eng+tur").
default: eng
required:
- imageInput
FAQs
This project is designed to facilitate the extraction of text and their corresponding bounding box coordinates from images, using the Tesseract.js library. It supports various input formats such as file paths, URLs, or Base64 encoded strings and can handl
The npm package @fnet/ocr-text-coords receives a total of 1,087 weekly downloads. As such, @fnet/ocr-text-coords popularity was classified as popular.
We found that @fnet/ocr-text-coords demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.