laravelsmartocr/laravel-smart-ocr
Composer 安装命令:
composer require laravelsmartocr/laravel-smart-ocr
包简介
Laravel Smart OCR & Document Data Extractor - A powerful OCR and document parsing engine for Laravel
README 文档
README
A powerful Laravel package for OCR and intelligent document parsing with AI-powered data cleanup, reusable templates, and multi-language support.
Features
- Multi-Driver OCR Support: Tesseract (offline), Google Vision, AWS Textract, Azure OCR
- Template Matching System: Create and share reusable document templates
- AI-Powered Cleanup: Automatic typo correction and data structuring
- Multi-Language Support: Extract text in multiple languages
- Laravel Native: Seamless integration with Eloquent, Queues, and Blade
- Privacy-First: Full offline capability for sensitive documents
- Smart Data Extraction: Automatically extract dates, amounts, emails, phone numbers
- Document Preview: Interactive Blade components for reviewing extracted data
Installation
composer require laravelsmartocr/laravel-smart-ocr
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=smart-ocr-config
Run migrations:
php artisan migrate
Basic Usage
Simple OCR Extraction
use LaravelSmartOCR\Facades\SmartOCR; // Extract text from an image $result = SmartOCR::extract('path/to/document.jpg'); // Extract with specific language $result = SmartOCR::extract('path/to/document.jpg', [ 'language' => 'spa' // Spanish ]);
Using Templates
// Extract using a specific template $result = SmartOCR::extractWithTemplate('invoice.pdf', $templateId); // Auto-detect template $parser = app('smart-ocr.parser'); $result = $parser->parse('invoice.pdf', [ 'auto_detect_template' => true ]);
AI Cleanup
$parser = app('smart-ocr.parser'); $result = $parser->parse('receipt.jpg', [ 'use_ai_cleanup' => true, 'document_type' => 'receipt' ]);
Creating Templates
$templateManager = app('smart-ocr.templates'); $template = $templateManager->create([ 'name' => 'Standard Invoice', 'type' => 'invoice', 'fields' => [ [ 'key' => 'invoice_number', 'label' => 'Invoice Number', 'type' => 'string', 'pattern' => '/Invoice\s*#?\s*:\s*([A-Z0-9\-]+)/i', ], [ 'key' => 'total_amount', 'label' => 'Total Amount', 'type' => 'currency', 'pattern' => '/Total\s*:\s*\$?\s*([0-9,.]+)/i', ] ] ]);
Batch Processing
$documents = [ 'invoice1.pdf', 'invoice2.jpg', 'receipt.png' ]; $results = $parser->parseBatch($documents, [ 'use_ai_cleanup' => true, 'save_to_database' => true ]);
Blade Components
Display extracted document data with the included Blade component:
<x-smart-ocr::document-preview :document="$processedDocument" :show-overlay="true" :show-actions="true" />
Advanced Configuration
Configure OCR Drivers
# Tesseract (Default - Offline) SMART_OCR_DRIVER=tesseract TESSERACT_LANGUAGE=eng # Google Vision SMART_OCR_DRIVER=google_vision GOOGLE_VISION_KEY_FILE=/path/to/credentials.json GOOGLE_VISION_PROJECT_ID=your-project-id # AWS Textract SMART_OCR_DRIVER=aws_textract AWS_ACCESS_KEY_ID=your-key AWS_SECRET_ACCESS_KEY=your-secret AWS_DEFAULT_REGION=us-east-1 # Azure OCR SMART_OCR_DRIVER=azure AZURE_OCR_ENDPOINT=https://your-resource.cognitiveservices.azure.com/ AZURE_OCR_KEY=your-key
Enable AI Cleanup
SMART_OCR_AI_CLEANUP=true SMART_OCR_AI_PROVIDER=openai OPENAI_API_KEY=your-openai-key
Queue Processing
SMART_OCR_QUEUE_ENABLED=true SMART_OCR_QUEUE_NAME=ocr-processing
Workflows
Define custom workflows for specific document types:
// config/smart-ocr.php 'workflows' => [ 'invoice' => [ 'options' => [ 'use_ai_cleanup' => true, 'auto_detect_template' => true, 'extract_tables' => true, ], 'post_processors' => [ ['class' => 'App\OCR\Processors\InvoiceProcessor'], ], ], ] // Usage $result = $parser->parseWithWorkflow('invoice.pdf', 'invoice');
API Usage
// Field mapping with fuzzy matching $aiCleanup = app('smart-ocr.ai-cleanup'); $mapped = $aiCleanup->mapFields($extractedData, [ 'invoice_id' => [ 'alternatives' => ['invoice_number', 'inv_no', 'bill_number'], 'transform' => 'uppercase' ], 'amount' => [ 'field' => 'total', 'transform' => 'currency' ] ]);
Security
- Offline Mode: Use Tesseract for complete data privacy
- Encryption: Enable data encryption for stored documents
- Validation: Built-in MIME type and file size validation
- Sanitization: Automatic input sanitization
Pro Version
Upgrade to Pro for:
- Advanced AI cleanup with multiple providers
- Access to community template marketplace
- Priority support and updates
- Advanced language packs
- Custom OCR model training s
laravelsmartocr/laravel-smart-ocr 适用场景与选型建议
laravelsmartocr/laravel-smart-ocr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「pdf」 「document」 「invoice」 「Tesseract」 「OCR」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravelsmartocr/laravel-smart-ocr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravelsmartocr/laravel-smart-ocr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravelsmartocr/laravel-smart-ocr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Invalidity check of documents in the database of Ministry of the Interior of the Czech Republic
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
Document indexation and migration tool for Elasticsearch
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-31