Wednesday, August 27, 2008

PHP RUNTIME IMG Generation

I hope this code will help you a lot. In order to generate runtime image. Its is now most widely used in web application to restrict users, to prevent the server overflow.
Here is a code give below and its description can be found on the source given below:


//random_number.php
$img_number = imagecreate(100,50);
$white = imagecolorallocate($img_number,255,255,255);
$black = imagecolorallocate($img_number,0,0,0);
$grey_shade = imagecolorallocate($img_number,204,204,204);

imagefill($img_number,0,0,$grey_shade);
ImageRectangle($img_number,5,5,94,44,$black);
ImageRectangle($img_number,0,0,99,49,$black);


$number = get_random();
Imagestring($img_number,9,30,15,$number,$black);

header("Content-type: image/jpeg");
imagejpeg($img_number);

function get_random()
{
srand(time());
$max = getrandmax();
return rand(1,$max) + rand(1,$max) ;
}

?>


Source:
http://www.developerfusion.co.uk/show/1951/1/

No comments: