php - GD Lib to save a image -
i have code snippet of following
$code = generatecode($characters); /* font size 75% of image height */ $font_size = $height * 0.75; $image = imagecreate($width, $height) or die('cannot initialize new gd image stream'); /* set colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox , add text */ $textbox = imagettfbbox($font_size, 0, $font, $code) or die('error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code) or die('error in imagettftext function'); /* output captcha image browser */ header('content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_session['security_code'] = $code;
i'm struggling save image, able render it, there way save capcha image instead of redering it?
yes can, tip: second parameter, if not set or null, raw image stream outputted directly.
hope helps.
Comments
Post a Comment