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.
Output Image
1 2 3 4 5 |
$im = imagecreatefrompng("php.png"); $rgb = imagecolorat($im, 10, 15); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; |
Image to text converter
Source ImageOutput Image
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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; } |
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.
Thanks buddy for the appreciation. And glad to know someone liked it. I wish i could develop more script that will make people come here again and again.
Hi Amit,
I am trying to develop PHP code for converting image to text. Could you please help me with this
Hi
Amit can you send me above image to text converter code. I am tried it,but not done yet.Thank you.
You can find the complete code here @ http://pastebin.com/5JtYsXeb
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.
If we have database access to all the sites then its possible and easy too.
Hi
Amit can you send me above image to text converter code send me mail
Send you the code.
Nice work! Is there a way that you can send us the code? Thanks!
Sent to your email.
good work…..can u send me the script?
Hi Amit,
I am trying to develop PHP code for Image to text conversion. Could you please help me with it
How can i help you ?
Awesome Work… keep it up..
can u send me it’s code ?
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.
What type of image it was ? There is no way to revert it back to original image.
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.
may i knw hw to convert image content to text
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. –
bro can u provide me php script for converting image letters into text…………
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.
dude provide me captcha bypass php script
Its not that easy 😛
Hi Amit
one help
html code converter to image with php code.
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?
I need to read the text from png image, is that any tool I can use
There are few tools but none of them reliable.
Hi Admin Great Work,
I need this image to text converter code script, can you able to send to me..
Sent to your email
i have an image in .gif type language is english but the font italian i using abbyy fine reader 12.0 even also cant convert the images into proper text it is converted in some junk words help me
May be because its not in a proper format.
Hi ….
nice work…:)
will u help me for PHP OCR code and or example ,if u any idea about this share with me.
i also show “php-tesseract” ocr but not use full for me,b’coz i cant not understand this.
plz halp me for this my query,
thank u.
Do u tell good php courses and good instittutt
I want to upload image and read text from that image using java scripts please help me
You have to read about file reader API.
I would like to read text in a character format not in a Binary format please help me soon
I dont have code for that, Please google and you should fine something.
Hello Amit
Can u help me in converting simple HTML page in image .
an u help me in converting simple HTML page in image in php code
Hello.
We are trying to do a similar project.
Could you please send the code for the above converter?
Hi,
I have to convert a business card to text in php . can you please help me .
Didnt notice your comment, sorry this script it not what you are looking for.
Hi,
Is it possible to use gdlib to extract text from image? Something like this image…?
https://docs.google.com/document/d/15K1yiVMdlM08PyTouGIr4ez8n5wNoGWph-5AAfGzqEQ/edit?usp=sharing
There are many online/offline tools that you can use for extracting text from the image.