PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/system/library/captcha.php

https://bitbucket.org/MSambrook/dsgi-opencart-site
PHP | 47 lines | 35 code | 12 blank | 0 comment | 0 complexity | 19e964080810c258c1a06ca6a9ac881d MD5 | raw file
  1. <?php
  2. class Captcha {
  3. protected $code;
  4. protected $width = 35;
  5. protected $height = 150;
  6. function __construct() {
  7. $this->code = substr(sha1(mt_rand()), 17, 6);
  8. }
  9. function getCode(){
  10. return $this->code;
  11. }
  12. function showImage() {
  13. $image = imagecreatetruecolor($this->height, $this->width);
  14. $width = imagesx($image);
  15. $height = imagesy($image);
  16. $black = imagecolorallocate($image, 0, 0, 0);
  17. $white = imagecolorallocate($image, 255, 255, 255);
  18. $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
  19. $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
  20. $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
  21. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  22. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
  23. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
  24. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
  25. imagefilledrectangle($image, 0, 0, $width, 0, $black);
  26. imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
  27. imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
  28. imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
  29. imagestring($image, 10, intval(($width - (strlen($this->code) * 9)) / 2), intval(($height - 15) / 2), $this->code, $black);
  30. header('Content-type: image/jpeg');
  31. imagejpeg($image);
  32. imagedestroy($image);
  33. }
  34. }
  35. ?>