bijou
bijou

Reputation: 51

How to extract text from an image using PHP

Let's say I have an image which consists of white background and black text. How to extract text from the file and save it as png with transparent backgorund using PHP?

Upvotes: 2

Views: 18826

Answers (2)

mario
mario

Reputation: 145482

If you already have an image using a color palette (gif or png) and assuming the top left pixel is white anyway, you could simply use:

$im = imagecreatefrompng($filename);    
imagecolortransparent($im,  imagecolorat($im, 0, 0));

Otherwise you'd have to iterate over pixels, find the whiteish ones (jpeg) and set them each. Some more examples are here: http://www.php.net/manual/en/function.imagecolortransparent.php

Upvotes: 3

Danilo
Danilo

Reputation: 2686

It is actually not so straight forward to extract a text from an image. The process of extracting text from images is called Optical Character Recognition (OCR), is kind of the same systems scanners use to "read" documents and import them directly as text.

For PHP there is a library that works with this kind of recognition, check it out: http://sourceforge.net/projects/phpocr/ .

Upvotes: 0

Related Questions