captcha
yazım: 23 Mart 09 13:37 / güncelleme: 25 Mart 09 20:26
imagick ile captcha yapımı
php imagick ile captcha örneği
/** * captcha function, session is must * * @param imageFile $bg * @param int $charCount */ public function captcha($bg,$charCount = 4){ header('Content-type: image/jpeg'); $captcha = new imagick($bg); $width = $captcha->getImageWidth()-8; $height = $captcha->getImageHeight()-8; $line = new imagickDraw(); $line->setStrokeWidth(2); $line->setStrokeColor (new ImagickPixel('#cdcdde')); //$line->setStrokeLineJoin(3); for( $i=0; $iline(rand(3,$width), rand(3,$height), rand(3,$width), rand(3,$height)); } $captcha->drawImage($line); $possible = '23456789bcdfghjkmnpqrstvwxyz'; $codeText = ''; $i = 0; $left = 5; $code = new imagickDraw(); while ($i < $charCount) { $codeText .= $codeChar = (rand(0,10)>5)?strtoupper(substr($possible, rand(0, strlen($possible)-1), 1)):(substr($possible, rand(0, strlen($possible)-1), 1)); $fontSize = $height * (rand(50,70)/100); $code->setFont('lib/captcha/captcha.ttf'); $code->setFontSize($fontSize); $code->setFillColor(new ImagickPixel('#dd'.rand(11,22).''.rand(11,22))); $code->setTextAlignment(1); $code->setStrokeWidth(2); $code->setStrokeColor (new ImagickPixel('#cc'.rand(11,22).'00')); $captcha->annotateImage($code, $left, 41, rand(-21,21), $codeChar); $left += $fontSize; $i++; } $_SESSION['captcha'] = $codeText; echo $captcha; }






