|
php captcha wave effect
#37494197
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
|
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94.
<?php
error_reporting ( 1 );
$font_file = "fonts/calibri.ttf";
$font_size = 18 ;
$keystring = substr ( md5 ( mt_rand ()), 0 , 3 );
$spacing = 9 ;
$width = ($font_size + $spacing) * strlen ($keystring) + $spacing;
$height = $font_size + $spacing * 2 ;
$padding_top = $font_size + $spacing;
session_start ();
$_SESSION["captcha_keystring"] = $keystring;
$img = imagecreate ($width, $height);
$background = imagecolorallocate ($img, 255 , 255 , 255 );
$color = imagecolorallocate ($img, 0 , 0 , 0 );
$keystring = str_split ( strtoupper ($keystring));
$padding_left = $spacing;
$half_spacing = $spacing / 2 ;
$half_font_size = $font_size / 2 ;
for ($i = 0 ; $i < count ($keystring); ++$i) {
imagettftext ($img, $font_size + mt_rand (-$half_font_size, $half_font_size), mt_rand (- 15 , 15 ), $padding_left + mt_rand (-$half_spacing, $half_spacing), $padding_top + mt_rand (-$half_spacing, $half_spacing), $color, $font_file, $keystring[$i]);
$padding_left += $font_size + $spacing;
}
$img2 = imagecreate ($width, $height);
$rand1 = mt_rand ( 750000 , 1200000 )/ 10000000 ;
$rand2 = mt_rand ( 750000 , 1200000 )/ 10000000 ;
$rand3 = mt_rand ( 750000 , 1200000 )/ 10000000 ;
$rand4 = mt_rand ( 750000 , 1200000 )/ 10000000 ;
// phases
$rand5 = mt_rand ( 0 , 31415926 )/ 10000000 ;
$rand6 = mt_rand ( 0 , 31415926 )/ 10000000 ;
$rand7 = mt_rand ( 0 , 31415926 )/ 10000000 ;
$rand8 = mt_rand ( 0 , 31415926 )/ 10000000 ;
// amplitudes
$rand9 = mt_rand ( 330 , 420 )/ 110 ;
$rand10 = mt_rand ( 330 , 450 )/ 110 ;
$center = $width / 2 ;
//wave distortion
for ($x = 0 ; $x < $width; ++$x) {
for ($y = 0 ; $y < $height; ++$y) {
$sx = $x + ( sin ($x * $rand1 + $rand5) + sin ($y * $rand3 + $rand6)) * $rand9 - $width / 2 + $center + 1 ;
$sy = $y + ( sin ($x * $rand2 + $rand7) + sin ($y * $rand4 + $rand8)) * $rand10;
if ($sx < 0 || $sy < 0 || $sx >= $width - 1 || $sy >= $height - 1 ) {
continue ;
}
else {
$color = imagecolorat ($img, $sx, $sy) & 0xFF;
$color_x = imagecolorat ($img, $sx + 1 , $sy) & 0xFF;
$color_y = imagecolorat ($img, $sx, $sy + 1 ) & 0xFF;
$color_xy = imagecolorat ($img, $sx + 1 , $sy + 1 ) & 0xFF;
}
if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255 ){
continue ;
}
else if ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0 ) {
$newred = $foreground_color[ 0 ];
$newgreen = $foreground_color[ 1 ];
$newblue = $foreground_color[ 2 ];
}
else {
$frsx = $sx - floor ($sx);
$frsy = $sy - floor ($sy);
$frsx1 = 1 - $frsx;
$frsy1 = 1 - $frsy;
$newcolor = $color * $frsx1 * $frsy1 + $color_x * $frsx * $frsy1 + $color_y * $frsx1 * $frsy + $color_xy * $frsx * $frsy;
if ($newcolor > 255 ) {
$newcolor = 255 ;
}
$newcolor = $newcolor / 255 ;
$newcolor0 = 1 - $newcolor;
$newred = $newcolor0 * $foreground_color[ 0 ] + $newcolor * $background_color[ 0 ];
$newgreen = $newcolor0 * $foreground_color[ 1 ] + $newcolor * $background_color[ 1 ];
$newblue = $newcolor0 * $foreground_color[ 2 ] + $newcolor * $background_color[ 2 ];
}
imagesetpixel ($img2, $x, $y, imagecolorallocate ($img2, $newred, $newgreen, $newblue));
}
}
header ("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-store, no-cache, must-revalidate");
header ("Cache-Control: post-check=0, pre-check=0", false );
header ("Pragma: no-cache");
header ("Content-type: image/png");
imagepng ($img2);
imagedestroy ($img2);
?>
ну и что за херня? опять всё черное! короче ясно, автор тех сраных строчек му**к и маг-чернокнижник
|
|
|