img.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "config.php";
  23. error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings
  24. session_start();
  25. // Captcha verification image -----------------------
  26. // Description this page is used to verify the captcha
  27. $_SESSION["captcha"] = substr(md5(date('r')), 0, 6);
  28. $text = $_SESSION["captcha"];
  29. //echo $text;
  30. exit;
  31. function isfile($filename) {
  32. if (@filesize($filename) > 0) { return true; } else { return false; }
  33. }
  34. function dircontents($dir) {
  35. clearstatcache();
  36. $htmldirlist = '';
  37. $htmlfilelist = '';
  38. $dirlist = opendir($dir);
  39. while ($file = readdir ($dirlist)) {
  40. if ($file != '.' && $file != '..') {
  41. $newpath = $dir.'/'.$file;
  42. $level = explode('/',$newpath);
  43. if (is_dir($newpath)) {
  44. //do nothing
  45. }
  46. else {
  47. $mod_array[] = end($level);
  48. }
  49. }
  50. }
  51. closedir($dirlist);
  52. return $mod_array;
  53. }
  54. $fontarray = dircontents($pathtofonts);
  55. //print_r($fontarray);
  56. function make_seed()
  57. {
  58. list($usec, $sec) = explode(' ', microtime());
  59. return (float) $sec + ((float) $usec * 100000);
  60. }
  61. srand(make_seed());
  62. $random = (rand()%count($fontarray));
  63. $font = $pathtofonts.$fontarray[$random];
  64. //echo $font;
  65. //echo phpinfo();
  66. //exit;
  67. $fontsize = 16;
  68. if(@$_GET['fontsize']) {
  69. $fontsize = $_GET['fontsize'];
  70. }
  71. //picked up from a note at http://www.php.net/imagettfbbox
  72. function imagettfbbox_custom($size, $angle, $font, $text) {
  73. $dummy = imagecreate(1, 1);
  74. $black = imagecolorallocate($dummy, 0, 0, 0);
  75. $bbox = imagettftext($dummy, $size, $angle, 0, 0, $black, $font, $text);
  76. imagedestroy($dummy);
  77. return $bbox;
  78. }
  79. // Create the image
  80. $size = imagettfbbox_custom($fontsize, 0, $font, $text);
  81. $width = $size[2] + $size[0] + 8;
  82. $height = abs($size[1]) + abs($size[7]);
  83. //$width = 200;
  84. //$height = 200;
  85. $im = imagecreate($width, $height);
  86. $colourBlack = imagecolorallocate($im, 255, 255, 255);
  87. imagecolortransparent($im, $colourBlack);
  88. // Create some colors
  89. $white = imagecolorallocate($im, 255, 255, 255);
  90. $black = imagecolorallocate($im, 0, 0, 0);
  91. // Add the text
  92. imagefttext($im, $fontsize, 0, 0, abs($size[5]), $black, $font, $text);
  93. // Set the content-type
  94. header("Content-type: image/png");
  95. // Using imagepng() results in clearer text compared with
  96. imagepng($im);
  97. imagedestroy($im);
  98. ?>