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开发者_Go百科 the file and save it as png with transparent backgorund using PHP?
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
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/ .
精彩评论