PageRenderTime 66ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/cms/modules/form/captcha/class/filter.class.php

https://github.com/swat/pragyan
PHP | 123 lines | 66 code | 32 blank | 25 comment | 5 complexity | ac02fe82b1d0c7ee23000da0e912ce6d MD5 | raw file
  1. <?php
  2. /******************************************************************
  3. Projectname: CAPTCHA class
  4. Version: 2.0
  5. Author: Pascal Rehfeldt <Pascal@Pascal-Rehfeldt.com>
  6. Last modified: 15. January 2006
  7. * GNU General Public License (Version 2, June 1991)
  8. *
  9. * This program is free software; you can redistribute
  10. * it and/or modify it under the terms of the GNU
  11. * General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License,
  13. * or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will
  16. * be useful, but WITHOUT ANY WARRANTY; without even the
  17. * implied warranty of MERCHANTABILITY or FITNESS FOR A
  18. * PARTICULAR PURPOSE. See the GNU General Public License
  19. * for more details.
  20. Description:
  21. Filters
  22. ******************************************************************/
  23. class filters
  24. {
  25. function noise (&$image, $runs = 30)
  26. {
  27. $w = imagesx($image);
  28. $h = imagesy($image);
  29. for ($n = 0; $n < $runs; $n++)
  30. {
  31. for ($i = 1; $i <= $h; $i++)
  32. {
  33. $randcolor = imagecolorallocate($image,
  34. mt_rand(0, 255),
  35. mt_rand(0, 255),
  36. mt_rand(0, 255));
  37. imagesetpixel($image,
  38. mt_rand(1, $w),
  39. mt_rand(1, $h),
  40. $randcolor);
  41. }
  42. }
  43. } //noise
  44. function signs (&$image, $font, $cells = 3)
  45. {
  46. $w = imagesx($image);
  47. $h = imagesy($image);
  48. for ($i = 0; $i < $cells; $i++)
  49. {
  50. $centerX = mt_rand(1, $w);
  51. $centerY = mt_rand(1, $h);
  52. $amount = mt_rand(1, 15);
  53. $stringcolor = imagecolorallocate($image, 175, 175, 175);
  54. for ($n = 0; $n < $amount; $n++)
  55. {
  56. $signs = range('A', 'Z');
  57. $sign = $signs[mt_rand(0, count($signs) - 1)];
  58. imagettftext($image, 25,
  59. mt_rand(-15, 15),
  60. $centerX + mt_rand(-50, 50),
  61. $centerY + mt_rand(-50, 50),
  62. $stringcolor, $font, $sign);
  63. }
  64. }
  65. } //signs
  66. function blur (&$image, $radius = 3)
  67. {
  68. $radius = round(max(0, min($radius, 50)) * 2);
  69. $w = imagesx($image);
  70. $h = imagesy($image);
  71. $imgBlur = imagecreate($w, $h);
  72. for ($i = 0; $i < $radius; $i++)
  73. {
  74. imagecopy ($imgBlur, $image, 0, 0, 1, 1, $w - 1, $h - 1);
  75. imagecopymerge($imgBlur, $image, 1, 1, 0, 0, $w, $h, 50.0000);
  76. imagecopymerge($imgBlur, $image, 0, 1, 1, 0, $w - 1, $h, 33.3333);
  77. imagecopymerge($imgBlur, $image, 1, 0, 0, 1, $w, $h - 1, 25.0000);
  78. imagecopymerge($imgBlur, $image, 0, 0, 1, 0, $w - 1, $h, 33.3333);
  79. imagecopymerge($imgBlur, $image, 1, 0, 0, 0, $w, $h, 25.0000);
  80. imagecopymerge($imgBlur, $image, 0, 0, 0, 1, $w, $h - 1, 20.0000);
  81. imagecopymerge($imgBlur, $image, 0, 1, 0, 0, $w, $h, 16.6667);
  82. imagecopymerge($imgBlur, $image, 0, 0, 0, 0, $w, $h, 50.0000);
  83. imagecopy ($image , $imgBlur, 0, 0, 0, 0, $w, $h);
  84. }
  85. imagedestroy($imgBlur);
  86. } //blur
  87. } //class: filters