PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/imagebuilder.php

https://bitbucket.org/udfr/uc3-udfr-ontowiki
PHP | 131 lines | 75 code | 20 blank | 36 comment | 10 complexity | 8904ee91fa6185f6e84d74d99d39276d MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. /*
  3. ============================
  4. QuickCaptcha 1.0 - A bot-thwarting text-in-image web tool.
  5. Copyright (c) 2006 Web 1 Marketing, Inc.
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. ============================
  15. See settings.php for common settings. You shouldn't need to change
  16. anything in this file.
  17. ============================
  18. */
  19. include "settings.php";
  20. // Keep #'s reasonable.
  21. $min_thickness = max(1,$min_thickness);
  22. $max_thickness = min(20,$max_thickness);
  23. // Make radii into height/width
  24. $min_radius *= 2;
  25. $max_radius *= 2;
  26. // Renormalize contrast
  27. $contrast = 255 * ($contrast / 100.0);
  28. $o_contrast = 1.3 * $contrast;
  29. $width = 15 * imagefontwidth (5);
  30. $height = 2.5 * imagefontheight (5);
  31. $image = imagecreatetruecolor ($width, $height);
  32. imagealphablending($image, true);
  33. $black = imagecolorallocatealpha($image,0,0,0,0);
  34. // Build the validation string
  35. $max = strlen($acceptedChars)-1;
  36. $password = NULL;
  37. for($i=0; $i < $stringlength; $i++) {
  38. $cnum[$i] = $acceptedChars{mt_rand(0, $max)};
  39. $password .= $cnum[$i];
  40. }
  41. // Add string to image
  42. $rotated = imagecreatetruecolor (70, 70);
  43. $x = 0;
  44. for ($i = 0; $i < $stringlength; $i++) {
  45. $buffer = imagecreatetruecolor (20, 20);
  46. $buffer2 = imagecreatetruecolor (40, 40);
  47. // Get a random color
  48. $red = mt_rand(0,255);
  49. $green = mt_rand(0,255);
  50. $blue = 255 - sqrt($red * $red + $green * $green);
  51. $color = imagecolorallocate ($buffer, $red, $green, $blue);
  52. // Create character
  53. imagestring($buffer, 5, 0, 0, $cnum[$i], $color);
  54. // Resize character
  55. imagecopyresized ($buffer2, $buffer, 0, 0, 0, 0, 25 + mt_rand(0,12), 25 + mt_rand(0,12), 20, 20);
  56. // Rotate characters a little
  57. $rotated = imagerotate($buffer2, mt_rand(-25, 25),imagecolorallocatealpha($buffer2,0,0,0,0));
  58. imagecolortransparent ($rotated, imagecolorallocatealpha($rotated,0,0,0,0));
  59. // Move characters around a little
  60. $y = mt_rand(1, 3);
  61. $x += mt_rand(2, 6);
  62. imagecopymerge ($image, $rotated, $x, $y, 0, 0, 40, 40, 100);
  63. $x += 22;
  64. imagedestroy ($buffer);
  65. imagedestroy ($buffer2);
  66. }
  67. // Draw polygons
  68. if ($num_polygons > 0) for ($i = 0; $i < $num_polygons; $i++) {
  69. $vertices = array (
  70. mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
  71. mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25),
  72. mt_rand(-0.25*$width,$width*1.25),mt_rand(-0.25*$width,$width*1.25)
  73. );
  74. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
  75. imagefilledpolygon($image, $vertices, 3, $color);
  76. }
  77. // Draw random circles
  78. if ($num_ellipses > 0) for ($i = 0; $i < $num_ellipses; $i++) {
  79. $x1 = mt_rand(0,$width);
  80. $y1 = mt_rand(0,$height);
  81. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
  82. // $color = imagecolorallocate($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast));
  83. imagefilledellipse($image, $x1, $y1, mt_rand($min_radius,$max_radius), mt_rand($min_radius,$max_radius), $color);
  84. }
  85. // Draw random lines
  86. if ($num_lines > 0) for ($i = 0; $i < $num_lines; $i++) {
  87. $x1 = mt_rand(-$width*0.25,$width*1.25);
  88. $y1 = mt_rand(-$height*0.25,$height*1.25);
  89. $x2 = mt_rand(-$width*0.25,$width*1.25);
  90. $y2 = mt_rand(-$height*0.25,$height*1.25);
  91. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), $object_alpha);
  92. imagesetthickness ($image, mt_rand($min_thickness,$max_thickness));
  93. imageline($image, $x1, $y1, $x2, $y2 , $color);
  94. }
  95. // Draw random dots
  96. if ($num_dots > 0) for ($i = 0; $i < $num_dots; $i++) {
  97. $x1 = mt_rand(0,$width);
  98. $y1 = mt_rand(0,$height);
  99. $color = imagecolorallocatealpha ($image, mt_rand(0,$o_contrast), mt_rand(0,$o_contrast), mt_rand(0,$o_contrast),$object_alpha);
  100. imagesetpixel($image, $x1, $y1, $color);
  101. }
  102. session_start();
  103. //$string = new Zend_Session_Namespace('string');
  104. $_SESSION['string'] = $password;
  105. //$string = $password;
  106. header('Content-type: image/png');
  107. imagepng($image);
  108. imagedestroy($image);
  109. ?>