note 59420 added to ref.image

From: Date: Tue, 06 Dec 2005 17:46:12 +0000
Subject: note 59420 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-99640@lists.php.net to get a copy of this message
If you want to have a dynamic image validation code like yahoo, you can use this function: <?php function generateValidationImage($rand) { global $site_font_path; global $site_font_validation; $width = 120; $height = 40; $image = imagecreate($width, $height); $bgColor = imagecolorallocate ($image, 255, 255, 255); $textColor = imagecolorallocate ($image, 0, 0, 0); // Add Random noise for ($i = 0; $i < 250; $i++) { $rx1 = rand(0,$width); $rx2 = rand(0,$width); $ry1 = rand(0,$height); $ry2 = rand(0,$height); $rcVal = rand(0,255); $rc1 = imagecolorallocate($image, rand(0,255), rand(0,255), rand(100,255)); imageline ($image, $rx1, $ry1, $rx2, $ry2, $rc1); } // write the random number $font = imageloadfont($site_font_path."/".$site_font_validation); imagestring($image, $font, 3, 0, $rand, $textColor); // send several headers to make sure the image is not cached // Date in the past header("Expires: Mon, 23 Jul 1993 05:00:00 GMT"); // always modified header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // HTTP/1.1 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0 header("Pragma: no-cache"); // send the content type header so the image is displayed properly header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); } ?> The $site_font_path should be set to something like "/home/user/www/fonts". The $site_font_validation should be set to the name of the GD font file, like "anonymous.gdf". You can view and download the code here: http://www.digital-seven.net/?option=com_content&task=view&id=67 ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59420 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59420&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59420&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99640) next »