How to extract a specific text from an image?

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?

  • Answer:

    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

bijou at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

Russell Dias

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

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.