PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/text2shield.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 204 lines | 166 code | 27 blank | 11 comment | 25 complexity | e1b278e71b20e73ff33f67d445595fdd MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. define('CTRACKER_DISABLED', true);
  11. define('IN_ICYPHOENIX', true);
  12. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  13. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  14. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  15. // Start session management
  16. $user->session_begin(false);
  17. $auth->acl($user->data);
  18. $user->setup();
  19. // End session management
  20. $smiley_creator_path = IP_ROOT_PATH . 'images/smiles/smiley_creator/';
  21. $sm_fontcolor = request_var('fontcolor', '#000000');
  22. $sm_shadowcolor = request_var('shadowcolor', '#000000');
  23. $sm_shadow = request_var('shieldshadow', 0);
  24. $smilie = request_var('smilie', 1);
  25. $text = urldecode(request_var('text', '', true));
  26. $anz_smilie = -1;
  27. $hdl = @opendir($smiley_creator_path);
  28. while($res = @readdir($hdl))
  29. {
  30. if(strtolower(substr($res, (strlen($res) - 3), 3)) == 'png')
  31. {
  32. $anz_smilie++;
  33. }
  34. }
  35. @closedir($hdl);
  36. if(!file_exists($schriftdatei))
  37. {
  38. $schriftwidth = 6;
  39. $schriftheight = 8;
  40. }
  41. else
  42. {
  43. if((!$schriftheight) || (!$schriftwidth))
  44. {
  45. $schriftwidth = imagefontwidth($schriftdatei);
  46. $schriftheight = imagefontheight($schriftdatei);
  47. }
  48. }
  49. $schriftheight += 2;
  50. $text = stripslashes($text);
  51. $text = str_replace('&lt;', '<', $text);
  52. $text = str_replace('&gt;', '>', $text);
  53. while(substr_count($text, '<'))
  54. {
  55. $text = str_replace(substr($text, strpos($text, '<'), (strpos($text, '>') - strpos($text, '<') + 1)), '', $text);
  56. }
  57. if(!$text)
  58. {
  59. $text = $lang['SC_error'];
  60. }
  61. if(strlen($text) > 33)
  62. {
  63. $worte = explode(' ', $text);
  64. if(is_array($worte))
  65. {
  66. $i = 0;
  67. foreach($worte as $wort)
  68. {
  69. if((strlen($output[$i] . ' ' . $wort) < 33) && (!substr_count($wort, "[SM")))
  70. {
  71. $output[$i] .= ' ' . $wort;
  72. }
  73. else
  74. {
  75. if($i <= 11)
  76. {
  77. if($zeichenzahl < strlen($output[$i]))
  78. {
  79. $zeichenzahl = strlen($output[$i]);
  80. }
  81. $i++;
  82. $output[$i] = $wort;
  83. }
  84. }
  85. }
  86. }
  87. else
  88. {
  89. $zeichenzahl = 33;
  90. $output[0] = substr($text, 0, 30) . '...';
  91. }
  92. }
  93. else
  94. {
  95. $zeichenzahl = strlen($text);
  96. $output[0] = $text;
  97. }
  98. if(sizeof($output) > 12)
  99. {
  100. $output[12] = substr($output[12], 0, 30) . '...';
  101. }
  102. $width = ($zeichenzahl * $schriftwidth) + 6;
  103. $height = (sizeof($output) * $schriftheight) + 34;
  104. if($width < 60)
  105. {
  106. $width = 60;
  107. }
  108. mt_srand((double) microtime() * 3216549);
  109. if($smilie == 'random')
  110. {
  111. $smilie = mt_rand(1, $anz_smilie);
  112. }
  113. if(!$smilie)
  114. {
  115. $smilie = mt_rand(1, $anz_smilie);
  116. }
  117. $smilie = imagecreatefrompng($smiley_creator_path . 'smilie' . $smilie . '.png');
  118. $schild = imagecreatefrompng($smiley_creator_path . 'schild.png');
  119. $img = imagecreate($width,$height);
  120. $bgcolor = imagecolorallocate ($img, 111, 252, 134);
  121. $txtcolor = imagecolorallocate ($img, hexdec(substr(str_replace('#', '', $sm_fontcolor), 0, 2)), hexdec(substr(str_replace('#', '', $sm_fontcolor), 2, 2)), hexdec(substr(str_replace('#', '', $sm_fontcolor), 4, 2)));
  122. $txt2color = imagecolorallocate ($img, hexdec(substr(str_replace('#', '', $sm_shadowcolor), 0, 2)), hexdec(substr(str_replace('#', '', $sm_shadowcolor), 2, 2)), hexdec(substr(str_replace('#', '', $sm_shadowcolor), 4, 2)));
  123. $bocolor = imagecolorallocate ($img, 0, 0, 0);
  124. $schcolor = imagecolorallocate ($img, 255, 255, 255);
  125. $schatten1color = imagecolorallocate ($img, 235, 235, 235);
  126. $schatten2color = imagecolorallocate ($img, 219, 219, 219);
  127. $smiliefarbe = imagecolorsforindex($smilie, imagecolorat($smilie, 5, 14));
  128. imagesetpixel($schild, 1, 14, imagecolorallocate($schild, ($smiliefarbe['red'] + 52), ($smiliefarbe['green'] + 59), ($smiliefarbe['blue'] + 11)));
  129. imagesetpixel($schild, 2, 14, imagecolorallocate($schild, ($smiliefarbe['red'] + 50), ($smiliefarbe['green'] + 52), ($smiliefarbe['blue'] + 50)));
  130. imagesetpixel($schild, 1, 15, imagecolorallocate($schild, ($smiliefarbe['red'] + 50), ($smiliefarbe['green'] + 52), ($smiliefarbe['blue'] + 50)));
  131. imagesetpixel($schild, 2, 15, imagecolorallocate($schild, ($smiliefarbe['red'] + 22), ($smiliefarbe['green'] + 21), ($smiliefarbe['blue'] + 35)));
  132. imagesetpixel($schild, 1, 16, imagecolorat($smilie, 5, 14));
  133. imagesetpixel($schild, 2, 16, imagecolorat($smilie, 5, 14));
  134. imagesetpixel($schild, 5, 16, imagecolorallocate($schild, ($smiliefarbe['red'] + 22), ($smiliefarbe['green'] + 21), ($smiliefarbe['blue'] + 35)));
  135. imagesetpixel($schild, 6, 16, imagecolorat($smilie, 5, 14));
  136. imagesetpixel($schild, 5, 15, imagecolorallocate($schild, ($smiliefarbe['red'] + 52), ($smiliefarbe['green'] + 59), ($smiliefarbe['blue'] + 11)));
  137. imagesetpixel($schild, 6, 15, imagecolorallocate($schild, ($smiliefarbe['red'] + 50), ($smiliefarbe['green'] + 52), ($smiliefarbe['blue'] + 50)));
  138. imagecopy($img, $schild, ($width / 2 - 3), 0, 0, 0, 6, 4); // Bildteil kopieren
  139. imagecopy($img, $schild, ($width / 2 - 3), ($height - 24), 0, 5, 9, 17); // Bildteil kopieren
  140. imagecopy($img, $smilie, ($width / 2 + 6), ($height - 24), 0, 0, 23, 23); // Bildteil kopieren
  141. imagefilledrectangle($img, 0, 4, $width, ($height - 25), $bocolor);
  142. imagefilledrectangle($img, 1, 5, ($width - 2), ($height - 26), $schcolor);
  143. if($sm_shadow == true)
  144. {
  145. imagefilledpolygon($img, array((($width - 2) / 2 + ((($width - 2) / 4) - 3)), 5, (($width - 2) / 2 + ((($width - 2) / 4) + 3)), 5, (($width - 2) / 2 - ((($width - 2) / 4) - 3)), ($height - 26), (($width - 2) / 2 - ((($width - 2) / 4) + 3)), ($height - 26)), 4, $schatten1color);
  146. imagefilledpolygon($img, array((($width - 2) / 2 + ((($width - 2) / 4) + 4)), 5, ($width - 2), 5, ($width - 2), ($height - 26), (($width - 2) / 2 - ((($width - 2) / 4) - 4)), ($height - 26)), 4, $schatten2color);
  147. }
  148. $i = 0;
  149. while($i < sizeof($output))
  150. {
  151. if(((!$gd_info['FreeType Support']) || (!file_exists($schriftdatei))))
  152. {
  153. if($sm_shadowcolor)
  154. {
  155. imagestring($img, 2, (($width - (strlen(trim($output[$i])) * $schriftwidth) - 2) / 2 + 1), ($i * $schriftheight + 6), trim($output[$i]), $txt2color);
  156. }
  157. imagestring($img, 2, (($width - (strlen(trim($output[$i])) * $schriftwidth) - 2) / 2), ($i * $schriftheight + 5), trim($output[$i]), $txtcolor);
  158. }
  159. else
  160. {
  161. if($sm_shadowcolor)
  162. {
  163. imagettftext($img, $schriftheight, 0, (($width - (strlen(trim($output[$i])) * $schriftwidth) - 2) / 2 + 1), ($i * $schriftheight + $schriftheight + 4), $txt2color, $schriftdatei, trim($output[$i]));
  164. }
  165. imagettftext($img, $schriftheight, 0, (($width - (strlen(trim($output[$i])) * $schriftwidth) - 2) / 2), ($i * $schriftheight + $schriftheight + 3), $txtcolor, $schriftdatei, trim($output[$i]));
  166. }
  167. $i++;
  168. }
  169. imagecolortransparent($img, $bgcolor); // Dummybg als transparenz setzen
  170. imageinterlace($img, 1);
  171. header('Content-Type: image/png');
  172. Imagepng($img); // 100 = komprimierung
  173. //Imagepng($img,'',100); // 100 = komprimierung
  174. ImageDestroy($img);
  175. ImageDestroy($schild);
  176. ImageDestroy($smilie);
  177. ?>