Mega Code Archive

 
Categories / Php / Graphics
 

Generate image with random number

<?php /** * imgsecuregen() Generate an image with a random number, usefull for bot protection. */ function imgsecuregen($size = 6){ $width = 11*$size; $height = 30; $string = ""; for($i = 1; $i <= $size; $i++){ $string .= rand (0,9).""; } // for $im = ImageCreate($width, $height); $bg = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); $grey = imagecolorallocate($im, 170, 170, 170); imagerectangle($im,0, 0, $width-1, $height-1, $grey); imagestring($im, 5, $size, 5, $string, $black); imagepng($im); imagedestroy($im); } imgsecuregen(10); ?>