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?
Asked
Active
Viewed 1.8k times
2 Answers
3
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

mario
- 144,265
- 20
- 237
- 291
0
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/ .

Danilo
- 2,676
- 7
- 32
- 36
-
Hi, i have already tried this URL http://sourceforge.net/projects/phpocr/ it read only the integer but not the character. Any way to read the image character? – Luke Jun 21 '16 at 06:05