How to extract text from image in php?

To Extract Text from Part of an Image using Aspose.OCR Java for PHP, simply invoke ExtractTextFromPartOfImage module. Here you can see example code.

Show

PHP Code

## Initialize an instance of OcrEngine

$ocr_engine = new OcrEngine();

\# Clear notifier list

$ocr_engine->clearNotifies();

\# Clear recognition blocks

$ocr_engine->getConfig()->clearRecognitionBlocks();

\# Add 2 rectangle blocks to user defined recognition blocks

$recognitionBlock = new RecognitionBlock();

$ocr_engine->getConfig()->addRecognitionBlock($recognitionBlock->createTextBlock(52, 48, 67, 74));

$ocr_engine->getConfig()->addRecognitionBlock($recognitionBlock->createTextBlock(100, 46, 38, 46));

\# Ignore everything else on the image other than the user defined recognition blocks

$ocr_engine->getConfig()->setDetectTextRegions(false);

\# Set Image property by loading an image from file path

$imageStream = new ImageStream();

$ocr_engine->setImage($imageStream->fromFile($dataDir . 'ocr.png'));

\# Run recognition process

if ($ocr_engine->process()) {

\# Retrieve an array of recognized text by parts

$text = $ocr_engine->getText()->getPartsInfo();

\# Iterate over the text parts

$i=0;

while ($i < sizeof($text)){

$info = $text[$i];

\# Display part information

print "Block: " . (string)$info->getBox() . " Text: " . (string)$info->getText().PHP_EOL;

$i+= 1;

}

}

Download Running Code

Download Extracting Text from Part of an Image (Aspose.OCR) from any of the below mentioned social coding sites:

  • GitHub
  • CodePlex

    1. Public
    2. Questions
    3. Collectives

    4. Explore Collectives
    1. Teams

      Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?

    2. Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Asked 12 years, 8 months ago

Viewed 79k times

I would like to try to read some of text from an image with PHP.

So if I have an image like this:

How to extract text from image in php?

How can I extract the text "Some text" into a string.

All help and suggestions are appreciated.

  • php
  • image

h2ooooooo

38.2k8 gold badges65 silver badges101 bronze badges

asked Jan 7, 2010 at 22:43

AdnanAdnan

25.2k18 gold badges78 silver badges110 bronze badges

1

3 Answers

answered Jan 7, 2010 at 22:48

David PfefferDavid Pfeffer

38.1k30 gold badges124 silver badges201 bronze badges

2

  • I have tried phpOCR but it is not working. The script has two functions imagecreatefrompng and imagecreatefromjpeg which are not defined and hence gives an error.

    Oct 26, 2017 at 12:46

  • @san you need to install php-gd library

    Nov 7, 2018 at 0:47

answered Sep 16, 2014 at 12:43

How to extract text from image in php?

answered Jan 7, 2010 at 22:49

2

  • This is a funny thing. Googling "php ocr image to text" brings this same question right on top of the results. So meta (or an oxymoron, if you prefer so)

    Apr 12, 2018 at 11:19

  • The captchas work so well that I can't read them

    Jun 25, 2018 at 11:57

  • The Overflow Blog
  • Featured on Meta

Linked

Related

Hot Network Questions

  • What is this component? White SMD part marked "W"
  • Living room breaker will not turn on after pressure wash
  • Why did 'scp 10.0.0.11:/home/someuser/.*' start copying from /home as well?
  • What does "2x and 4x with chorus" mean in music notation?
  • How to get from Watford to London and back to airport
  • How to copy a list of file creation dates from a Windows File Explorer to a spreadsheet
  • Are there countries in Europe where there's a 10% (or similar, but low) numeric threshold for minority language rights?
  • What's that crown over Splatoon nametag players?
  • Is there anything illegal about working for another party while on paid leave from one's job?
  • Why do swaps that aren't in fstab attempt to mount at boot
  • How do non-English speakers navigate through JFK airport?
  • Counterexample that the arbitrary union of compact sets is compact
  • Can prisoners of war be exchanged against their will?
  • Is DNDBeyond correct on the ranger bonus?
  • Does the key a piece is written in affect playability for piano?
  • Why do car blinkers flash at twice the speed when a blinker light has burned out
  • Is this a breathable atmosphere for human-like aliens that have more efficient oxygen-carrying blood? Normal humans would require a gas mask (oxygen)
  • Python decibel meter-accurate?
  • Is there a strong correlation between credit score and mortgage rate in the US?
  • Is there any aromatic system which doesn't contain any ring?
  • Not enough space between equation and equation number
  • Stochastic process with Student's t-distribution
  • What video game is being played in Spiderhead (2022)?
  • In Children of Dune, was Leto ever actually in danger from the assassination attempt with the cats?

more hot questions

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.