note 54385 added to function.imageloadfont
| From: | alex at bestgames dot ro | Date: | Sat, 02 Jul 2005 12:01:56 +0000 |
| Subject: | note 54385 added to function.imageloadfont | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91308@lists.php.net to get a copy of this message | ||
Confirmation code generation for preventing automated registrations on a website.
Function arguments are:
$code - the code that you shall random generate
$location - relative location of the image that shall be generated
$fonts_dir - relative location for the GDF fonts directory
This function will create an image with the code given by you and will save it in the directory
specified with the name formed by MD5 hash of the code.
You may insert as many font types in the fonts directory as you wish, with random names.
<?php
function generate_image($code, $location, $fonts_dir)
{
$image = imagecreate(150, 60);
imagecolorallocate($image, rand(0, 100), rand(100, 150), rand(150, 250));
$fonts = scandir($fonts_dir);
$max = count($fonts) - 2;
$width = 10;
for ($i = 0; $i <= strlen($code); $i++)
{
$textcolor = imagecolorallocate($image, 255, 255, 255);
$rand = rand(2, $max);
$font = imageloadfont($fonts_dir."/".$fonts[$rand]);
$fh = imagefontheight($font);
$fw = imagefontwidth($font);
imagechar($image, $font, $width, rand(10, 50 - $fh), $code[$i], $textcolor);
$width = $width + $fw;
}
imagejpeg($image, $location."/".md5($code).".jpg", 100);
imagedestroy($image);
return $code;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imageloadfont.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54385
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54385&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54385&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54385&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54385&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54385&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54385&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54385&report=yes
Search -- http://master.php.net/manage/user-notes.php