Image to text converter

This is simple script to convert image to text. User will upload image, set few options and then this image to text converter will print image using characters provided by the user. while googling i found a website where this same image to text converter was implemented, got some free time and made it. wide range of php GD library functions make it more easier to make this image to text converter. simple idea behind this script is to read the image using imagecreatefrompng and read all the pixels, loop through each and every pixel and print it again but not the pixel itself instead of that we will print character/ characters provided by user. while looping through each pixel i am using php gd function imagecolorat which extracts pixel properties and we print the user character with same properties. imagecolorat simply returns RGB values of the pixel.

			$rgb = imagecolorat($im, $j, $i);
			$a = ($rgb >> 24) & 0xFF;
			$r = ($rgb >> 16) & 0xFF;
			$g = ($rgb >> 8) & 0xFF;
			$b = $rgb & 0xFF;

Image to text converter

Source Image
image to text converter
Output Image
image to text conversion

     First version of this Image to text converter was too slow it was because i was reading the uploaded image as it is, so it was taking almost 1-2 minutes to convert image to text and i totally forgot about creating thumbnail :P, i wasted many hours minimizing execution time. Thanks to php thumbnail trick. Below is the code which i am using to create thumbnail, it automatically scales and adjusts image height and width, in case if someone find it useful.

	function imagecreatethumbnail($file,$output,$max_width = 150,$max_height = 150)
	{
			extract($_POST);
			$img = imagecreatefromstring(file_get_contents($file));
			list($width, $height, $type, $attr) = getimagesize($file);
			if($height > $max_height || $width > $max_width)
			{
					if($width > $height)
					{
							$thumb_width = $max_width;
							$thumb_height = ceil(($height * $thumb_width)/$width);
					}
					else
					{
							$thumb_height = $max_height;
							$thumb_width = ceil(($width * $thumb_height)/$height);
					}
			} else {
					$thumb_width = $width;
					$thumb_height = $height;
			}
			$thumb_width = $thumb_width + ($thumb_width * ($fontsize / 6) );
			imagesavealpha($img,true);
			$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
			imagesavealpha($thumb,true);
			imagealphablending($thumb,false);
			imagecopyresampled($thumb,$img,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
			$return = imagepng($thumb,$output);
			imagedestroy($img);
			imagedestroy($thumb);
			return $return;
	}

View Demo

About Amit

   Myself Amit Patil from Maharashtra (India). I have been working as a Web Application Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically i am a PHP developer but now a days exploring more in CSS and javascript.

Comments

  1. HI amit,
    I’m coming here first time. I realy impress your work.
    right now no enoughtime to me, I will be touch with you.
    Best luck Keep it up.

  2. hello amit,
    can u create a php search engine that will search through my different websites and provide results in a Google-like interface? If I have pdftotext installed in my server it will also display results from pdf files.

  3. Hi
    Amit can you send me above image to text converter code send me mail

  4. Joanne Suarez says:

    Nice work! Is there a way that you can send us the code? Thanks!

  5. good work…..can u send me the script?

  6. Sravanthi says:

    Hi Amit,

    I am trying to develop PHP code for Image to text conversion. Could you please help me with it

  7. Rishabh Agrawal says:

    Awesome Work… keep it up..
    can u send me it’s code ?

  8. thanks buddy.
    i tried this code in google chrome
    but some pics are processed whiles some not.
    can you please send me the whole script including the form.

    And can i again convert the converted text into jpeg file as looking in TEXT file.

  9. Hi amit,
    you have done fabulous work great,
    can u give me the code for this.if you have code that can extract text from the image and display the text to user please give me.

    • No buddy i dont have the code what you are looking for, its really a hard thing to do, what you are trying to develop is cracking captcha.

  10. may i knw hw to convert image content to text

  11. Basant Jain says:

    HI amit, I’m coming here first time.You have done realy a fab. work I realy impress your work. I will be touch with you. Best luck Keep it up. -

  12. bro can u provide me php script for converting image letters into text…………

  13. Janardhan says:

    good work amit ,
    Can u please send me code…

    • Amit one more help,
      How can i dispaly that test in a text box.

      • Its not possible to show that image in textbox as it doesnt print different colors in plain textbox, but if you can somehow manage to use wysiwyg editor then it might be possible.

  14. dude provide me captcha bypass php script

  15. Hi Amit

    one help
    html code converter to image with php code.

  16. Is there a way to convert an image (there are bunch of text on it) to text via PHP? I mean is there a PHP library or sth for optical character recognition?

  17. I need to read the text from png image, is that any tool I can use

Speak Your Mind

*


*

Notify me of followup comments via e-mail. You can also subscribe without commenting.

More in HTML, PHP (4 of 29 articles)


A good and successful web application must have good user interface to interact more users and increase its usability. Application ...