PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/site/sites/all/modules/click_heatmap/clickheat/logo.big.png.php

https://bitbucket.org/kaerast/ppl
PHP | 218 lines | 196 code | 7 blank | 15 comment | 24 complexity | 1762ba171a6dd0433795f99e5a8b711f MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. <?php
  2. /**
  3. * ClickHeat : cr?Še sur disque et renvoie le logo PNG 80x15 / creates on disk and returns the PNG 80x15 logo
  4. *
  5. * @author Yvan Taviaud - LabsMedia - www.labsmedia.com
  6. * @since 31/10/2006
  7. **/
  8. define('CLICKHEAT_GREY_COLOR', 255);
  9. define('CLICKHEAT_LOW_COLOR', 0);
  10. define('CLICKHEAT_HIGH_COLOR', 255);
  11. /** Image creation */
  12. $img = imagecreatetruecolor(180, 45);
  13. $white = imagecolorallocate($img, 255, 255, 255);
  14. $blue = imagecolorallocate($img, 70, 70, 255);
  15. $red = imagecolorallocate($img, 255, 70, 70);
  16. $black = imagecolorallocate($img, 0, 0, 0);
  17. $shadow = imagecolorallocate($img, 200, 200, 255);
  18. imagefill($img, 0, 0, $white);
  19. /**
  20. * Colors creation :
  21. * grey => deep blue (rgB) => light blue (rGB) => green (rGb) => yellow (RGb) => red (Rgb)
  22. * 0 $colorLevels[0] $colorLevels[1] $colorLevels[2] $colorLevels[3] 128
  23. **/
  24. $colorLevels = array(0, 40, 45, 70, 100);
  25. $colors = array();
  26. for ($i = 0; $i < 128; $i++)
  27. {
  28. /** Red */
  29. if ($i < $colorLevels[0])
  30. {
  31. $colors[$i][0] = CLICKHEAT_GREY_COLOR + (CLICKHEAT_LOW_COLOR - CLICKHEAT_GREY_COLOR) * $i / $colorLevels[0];
  32. }
  33. elseif ($i < $colorLevels[2])
  34. {
  35. $colors[$i][0] = CLICKHEAT_LOW_COLOR;
  36. }
  37. elseif ($i < $colorLevels[3])
  38. {
  39. $colors[$i][0] = CLICKHEAT_LOW_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[2]) / ($colorLevels[3] - $colorLevels[2]);
  40. }
  41. else
  42. {
  43. $colors[$i][0] = CLICKHEAT_HIGH_COLOR;
  44. }
  45. /** Green */
  46. if ($i < $colorLevels[0])
  47. {
  48. $colors[$i][1] = CLICKHEAT_GREY_COLOR + (CLICKHEAT_LOW_COLOR - CLICKHEAT_GREY_COLOR) * $i / $colorLevels[0];
  49. }
  50. elseif ($i < $colorLevels[1])
  51. {
  52. $colors[$i][1] = CLICKHEAT_LOW_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[0]) / ($colorLevels[1] - $colorLevels[0]);
  53. }
  54. elseif ($i < $colorLevels[3])
  55. {
  56. $colors[$i][1] = CLICKHEAT_HIGH_COLOR;
  57. }
  58. else
  59. {
  60. $colors[$i][1] = CLICKHEAT_HIGH_COLOR - (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[3]) / (127 - $colorLevels[3]);
  61. }
  62. /** Blue */
  63. if ($i < $colorLevels[0])
  64. {
  65. $colors[$i][2] = CLICKHEAT_GREY_COLOR + (CLICKHEAT_HIGH_COLOR - CLICKHEAT_GREY_COLOR) * $i / $colorLevels[0];
  66. }
  67. elseif ($i < $colorLevels[1])
  68. {
  69. $colors[$i][2] = CLICKHEAT_HIGH_COLOR;
  70. }
  71. elseif ($i < $colorLevels[2])
  72. {
  73. $colors[$i][2] = CLICKHEAT_HIGH_COLOR - (CLICKHEAT_HIGH_COLOR - CLICKHEAT_LOW_COLOR) * ($i - $colorLevels[1]) / ($colorLevels[2] - $colorLevels[1]);
  74. }
  75. else
  76. {
  77. $colors[$i][2] = CLICKHEAT_LOW_COLOR;
  78. }
  79. }
  80. $max = 12;
  81. $pixels = array(
  82. ' *** ',
  83. ' ***** ',
  84. ' ***** ',
  85. ' ****** ',
  86. ' ****** ',
  87. ' ******* ',
  88. ' ******* ',
  89. ' ******* ',
  90. ' ******** ',
  91. ' ********* ',
  92. ' ********** ',
  93. ' *********** ',
  94. ' ************* ',
  95. ' ************** ',
  96. ' **************** ',
  97. ' ****************** ',
  98. ' ******************** ',
  99. '*********************** ',
  100. '************************ ',
  101. '************************* ',
  102. '************************* ',
  103. '**************************',
  104. '**************************',
  105. ' *************************',
  106. ' *************************',
  107. ' ************************',
  108. ' ************************',
  109. ' ***********************',
  110. ' **********************',
  111. ' ******************** ',
  112. ' ******************* ',
  113. ' ****************** ',
  114. ' *************** ',
  115. ' ************** ',
  116. ' *********** ',
  117. ' ********* ',
  118. ' ****** ',
  119. ' ***** ',
  120. ' **** ',
  121. ' *** ',
  122. ' ** ',
  123. ' * ');
  124. $mx = strlen($pixels[0]);
  125. $my = count($pixels);
  126. $blur = imagecreatetruecolor($mx + 2, $my + 2);
  127. $white = imagecolorallocate($blur, 255, 255, 255);
  128. imagefill($blur, 0, 0, $white);
  129. for ($x = 0; $x < $mx; $x++)
  130. {
  131. for ($y = 0; $y < $my; $y++)
  132. {
  133. if ($pixels[$y][$x] === '*')
  134. {
  135. imagesetpixel($blur, $x + 1, $y + 1, $black);
  136. }
  137. }
  138. }
  139. $previous = $white;
  140. for ($i = 0; $i <= $max; $i++)
  141. {
  142. $color = imagecolorallocate($blur, $colors[ceil($i * 127 / $max)][0], $colors[ceil($i * 127 / $max)][1], $colors[ceil($i * 127 / $max)][2]);
  143. for ($x = 1; $x < $mx + 1; $x++)
  144. {
  145. for ($y = 1; $y < $my + 1; $y++)
  146. {
  147. if (imagecolorat($blur, $x, $y) === $black)
  148. {
  149. if ($i === $max || imagecolorat($blur, $x + 1, $y) === $previous || imagecolorat($blur, $x - 1, $y) === $previous
  150. || imagecolorat($blur, $x, $y + 1) === $previous || imagecolorat($blur, $x, $y - 1) === $previous)
  151. {
  152. imagesetpixel($blur, $x, $y, $color);
  153. }
  154. }
  155. }
  156. }
  157. $previous = $color;
  158. }
  159. $color = array();
  160. $level = 1;
  161. for ($x = 1; $x < $mx + 1; $x++)
  162. {
  163. for ($y = 1; $y < $my + 1; $y++)
  164. {
  165. $color[0] = imagecolorsforindex($blur, imagecolorat($blur, $x, $y));
  166. if ($color[0]['red'] + $color[0]['green'] + $color[0]['blue'] === 765)
  167. {
  168. $color[1] = imagecolorsforindex($blur, imagecolorat($blur, $x + 1, $y));
  169. $color[2] = imagecolorsforindex($blur, imagecolorat($blur, $x - 1, $y));
  170. $color[3] = imagecolorsforindex($blur, imagecolorat($blur, $x, $y + 1));
  171. $color[4] = imagecolorsforindex($blur, imagecolorat($blur, $x, $y - 1));
  172. $col = imagecolorallocate($img, ceil(($level * $color[0]['red'] + $color[1]['red'] + $color[2]['red'] + $color[3]['red'] + $color[4]['red']) / ($level + 4)),
  173. ceil(($level * $color[0]['green'] + $color[1]['green'] + $color[2]['green'] + $color[3]['green'] + $color[4]['green']) / ($level + 4)),
  174. ceil(($level * $color[0]['blue'] + $color[1]['blue'] + $color[2]['blue'] + $color[3]['blue'] + $color[4]['blue']) / ($level + 4)));
  175. }
  176. else
  177. {
  178. $col = imagecolorallocate($img, $color[0]['red'], $color[0]['green'], $color[0]['blue']);
  179. }
  180. imagesetpixel($img, $x, $y, $col);
  181. }
  182. }
  183. imagedestroy($blur);
  184. $string = 'ClickHeat';
  185. $x = 28;
  186. $font = '/home/yvan/.ies4linux/ie5/drive_c/windows/fonts/verdana.ttf';
  187. $size = 25;
  188. for ($i = 0, $max = strlen($string); $i < $max; $i++)
  189. {
  190. $info = imagettfbbox($size, 0, $font, $string[$i]);
  191. if (strtolower($string[$i]) === 'h')
  192. {
  193. $font = '/home/yvan/.ies4linux/ie5/drive_c/windows/fonts/verdanab.ttf';
  194. }
  195. imagettftext($img, $size, 0, $x + 1, 36, $shadow, $font, $string[$i]);
  196. imagettftext($img, $size, 0, $x, 35, $blue, $font, $string[$i]);
  197. $x += $info[2] - $info[0] + 3;
  198. if (strtolower($string[$i]) === 'c' || strtolower($string[$i]) === 'k')
  199. {
  200. $x -= 2;
  201. }
  202. if (strtolower($string[$i]) === 'h')
  203. {
  204. $x += 4;
  205. }
  206. }
  207. header('Content-Type: image/png');
  208. imagepng($img, './images/logo.big.png');
  209. imagepng($img);
  210. imagedestroy($img);
  211. ?>