Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ash92's avatar
Level 1

How to scan ID/Passport and get text in Laravel?

I have a project in Laravel and now I want to add OCR functionality in my project. I want to scan ID/Passport and extract some fields like name, ID/Passport number etc. How to get this? Is there any packages to perform this? I have tried using some packages but none are precise.

0 likes
1 reply
LaryAI's avatar
Level 58

There are several OCR packages available for Laravel that you can use to extract text from scanned ID/Passport images. One of the popular packages is Tesseract OCR. Here's how you can use it in your Laravel project:

  1. Install the Tesseract OCR package using Composer:
composer require thiagoalessio/tesseract_ocr
  1. Install Tesseract OCR on your system. You can download it from the official website: https://github.com/tesseract-ocr/tesseract

  2. Once you have installed Tesseract OCR, you can use it in your Laravel code to extract text from scanned images. Here's an example:

use thiagoalessio\TesseractOCR\TesseractOCR;

// Path to the scanned image
$imagePath = '/path/to/image.jpg';

// Create a new instance of TesseractOCR
$tesseract = new TesseractOCR($imagePath);

// Set the language of the text in the image
$tesseract->lang('eng');

// Get the text from the image
$text = $tesseract->run();

// Print the extracted text
echo $text;

This code will extract the text from the scanned image and print it on the screen. You can modify it to extract specific fields like name, ID/Passport number, etc. by using regular expressions or other text processing techniques.

Please or to participate in this conversation.