PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/function/Function.EditProfile.CaptchaSecurityImages.php

https://github.com/arvino/vino-cms-kabarbumn-com
PHP | 62 lines | 43 code | 19 blank | 0 comment | 4 complexity | 38ef8c172eca484a133e66248c49712c MD5 | raw file
Possible License(s): GPL-2.0
  1. <?PHP
  2. session_name("CUST");
  3. session_start();
  4. class CaptchaSecurityImages {
  5. var $font = 'monofont.ttf';
  6. function generateCode($characters) {
  7. $possible = '45673ABCDEFGHIJKLMN';
  8. $code = '';
  9. $i = 0;
  10. while ($i < $characters) {
  11. $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
  12. $i++;
  13. }
  14. return $code;
  15. }
  16. function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
  17. $code = $this->generateCode($characters);
  18. $font_size = $height * 0.75;
  19. $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
  20. $background_color = imagecolorallocate($image, 225, 225, 195);
  21. $text_color = imagecolorallocate($image, 245, 2, 13);
  22. $noise_color = imagecolorallocate($image, 225, 200, 100);
  23. for( $i=0; $i<($width*$height)/3; $i++ ) {
  24. imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
  25. }
  26. for( $i=0; $i<($width*$height)/150; $i++ ) {
  27. imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
  28. }
  29. $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
  30. $x = ($width - $textbox[4])/2;
  31. $y = ($height - $textbox[5])/2;
  32. imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
  33. header('Content-Type: image/jpeg');
  34. imagejpeg($image);
  35. imagedestroy($image);
  36. $_SESSION['editprofile_code'] = $code;
  37. }
  38. }
  39. $width = isset($_GET['width']) ? $_GET['width'] : '100';
  40. $height = isset($_GET['height']) ? $_GET['height'] : '30';
  41. $characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
  42. $captcha = new CaptchaSecurityImages($width,$height,$characters);
  43. ?>