PHP Text to Image
Change the settings and the click Create
Description
This script is a means to convert a string of text into an image. This has some simple uses such as displaying text such as email address that cannot be programmatically found. This can help to reduce the possibility of your email address being picked up by web crawlers and used for junk mail.
How To Use
To use the example interface above, simply modify or insert the string of text. You can edit any of the other settings, but this is optional.
Further Uses and Ideas:
How it Works:
The PHP Script
contact us for more information
Further Help
For anyone finding problems using this...
(1) Please test this example to ensure imagecreate works on your server...
header("Content-type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
(2) Make sure to use the example at the top of this page by sending POST variables from your form. For example msg,font,size ...
Relevant Links
- PHP Manual - http://php.net/manual/en/function.imagepng.php
- http://uk3.php.net/imagecreate
- PHP imagestring - http://php.net/manual/en/function.imagestring.php
Comments For This Page
Really amazing, Could you add a background image to the code to upload in the test ? That would be even more amazing!On 6th September 2019
Demo is working fine, but can you provide solution for marathi text that means i copied text from google input tool. eg. %u0935%u0921%u093F%u0932%u093E%u0902%u091A%u093E %u0928%u094B%u0915%u0930%u0940 %u0935%u094D%u092F%u0935%u0938%u093E%u092FBy Anil Choudhari on 24th May 2019
how to get utf-8 unicode text to image??On 9th March 2017
Wow, was looking for this. My previous test produced black background when rotated but this one works! big thanks!By diko on 25th November 2016
Not support persian!By Mohammad Mahdi Naderi on 8th July 2016
Works Fine for me but this not complete code for axample - text-shadow, opacity, align, background-color & etc.By sunil on 10th August 2015
hi..how can i add height based on content description? .. moreover your ex code is not workingBy gaja on 13th April 2015
hey this was awsm solution to my problem. but i m trying some changes in this. i m replacing simple text (hello) with HTML text(hello).
any one have any idea how to implement thisBy Parveen Kumar on 23rd May 2014
Hi Jeff, we don't want hot-links to the site and wont be able to guarantee they will always work.By Daft Logic on 25th April 2014
Very cool. Any way to create a unique url for the output so I can just link to the image on the fly instead of downloading/uploading the new image every time?By Jeff on 24th April 2014
converte html para png ???On 27th February 2014
Thank you so much. i tried by my self. but it is not work correct. :)On 6th August 2013
Thanks for this class! TIP: The text rendering from GD is ugly, not antialiased. One way to make it look much better is to simply render text at 2x the size you want, then set a height on the <img> tag that is 50% of that (shrinking it back down to the size you really want to display). In Chrome, firefox and recent IE, you'll get a nice, antialiased image of text.
By Jonathan Cross on 2012-11-16By Jonathan Cross on 16th November 2012
the small example code is working but the big code is not working...can anybody help plz?By pankaj on 4th June 2012
good oneOn 5th May 2012
Can you give me full example code?By Raisul on 29th April 2012
thank you indeed, I've taken just the example part to build a basic captcha system.By Luca on 4th April 2012
Duh people!!!
Replace the
header("Content-type: image/png");
with this:
$i = new textPNG;
$i->msg = "Your text here!!!";
header("Content-type: image/png");
$i->draw();
And you have a perfect script.By GodPleaseGiveGreekPoliticiansB on 21st February 2012
text quality is badBy ali on 29th November 2011
Not support utf-8 character ! :(By GaRic on 13th November 2011
20 out of 50 comments shown. See all comments.
Add your own comment below and let others know what you think: