PHP script to write email address into a image
I was after a php script that dynamically converts text to image and finally i decided to code on my own. It also does convert small length text to image like names, emails etc..
This script automatically calculates the width of text into pixels inserts the PNG or gif image.
this is a string to <
>
To call the script for dynamically generating an image just use the html code
<img src="txt2img.php?text=<? echo $str ?>" border="0">
and the code for the script is
//source for txt2img.php
<?
if(!isset($_GET['txt']))
{
exit();
}
header ("Content-type: image/png");
$string = $_GET['txt'];
$font = 4;
$width = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);
$im = @imagecreate ($width,$height);
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, 0, 0, $string, $text_color);
imagepng ($im);
?>
Download: txt2img.zip
Requirements:
Apache
PHP GD Library with PNG/GIF/JPEG support
Similar Posts:
- How to create a favicon?
- Free Markup TextArea HTML Editor in Javascript
- how to call a php script from javascript?
- Implementing Secure File Upload in PHP
- Free Markup BBCode Editor in Javascript
- Lightweight PHP WYSIWYG HTML Editor
- Fast loading and lightweight WYSIWYG html Editors for PHP
- iframe innerHTML value from textarea
- Implementing Secure File Upload in PHP
- CSS Tutorial: How to Design Round Corner Boxes


January 4, 2010
It seems there’s an error in the src attribute of the img tag shown as an example. The url should be txt2img.php?txt= or the php script will fail the first check and exit.