Hi!
i made this function at 2006 but still using it’s very usefull!

image.php;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
function createimg () {
session_start();
ini_set("session.gc_maxlifetime","36000");
	$fontnum=6;  //count of fonts
	$numbers = strtoupper(substr(rand(0,999999999999),-3)); 
	$_SESSION["guv"] = $numbers; 
	$im = imagecreatetruecolor(125, 75); 
	$white = imagecolorallocate($im, 255, 255, 255);
	imagefilledrectangle($im, 0, 0, 400, 200, $white); 
	for ($i=0;$i<strlen($numbers);$i++)
		{
			$font = "fonts/".rand(1,$fontnum).".TTF";
 
			if ((rand(2,6)%2)) { $angel=rand(0, 30); } else { $angel=rand(330, 360); }
			imagettfnumbers($im, 25, $angel, 10+$i*35, 49, imagecolorallocate($im, rand(1,250), rand(1,250), rand(1,250)), $font,$numbers[$i]);
		}
	$x=100; $y=100; $size=200;
	header("Content-type: image/png");
	imagepng($im);
	imagedestroy($im);
}
createimg();
?>

You need 6 fonts in ./fonts directory like;
1.TTF
2.TTF
3.TTF
4.TFF
5.TFF
6.TFF

usage example;

1
2
3
<img src="imgcode.php" alt="security" name="guv" id="guv"/>
<!-- and also i made a relod image button here it is; -->
<img src="images/reload.gif" width="16" height="16" border="0" alt="refresh" onclick="i=i+1; document.getElementById('guv').src='imgcode.php?id='+i"/>

Here is the a screen shot;
secimg