seccode.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <?php
  2. /*
  3. [Discuz!] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: seccode.class.php 1164 2014-10-31 06:58:24Z hypowang $
  6. */
  7. class seccode {
  8. var $code; //100000-999999 范围内随机
  9. var $type = 0; //0 英文图片验证码 1 中文图片验证码 2 Flash 验证码 3 语音验证码
  10. var $width = 0;
  11. var $height = 0;
  12. var $background = 1;
  13. var $adulterate = 1;
  14. var $ttf = 0;
  15. var $angle = 0;
  16. var $color = 1;
  17. var $size = 0;
  18. var $shadow = 1;
  19. var $animator = 0; //GIF 动画
  20. var $fontpath = ''; //TTF 字库目录
  21. var $datapath = '';
  22. var $includepath= '';
  23. var $fontcolor;
  24. var $im;
  25. static function seccode_check($code, $input) {
  26. if ($code == '' || $input == '') {
  27. return false;
  28. }
  29. self::seccodeconvert($code);
  30. return $input === $code;
  31. }
  32. function seccodeconvert(&$seccode) {
  33. $s = sprintf('%04s', base_convert($seccode, 10, 20));
  34. $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
  35. $seccode = '';
  36. for($i = 0; $i < 4; $i++) {
  37. $unit = ord($s{$i});
  38. $seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
  39. }
  40. }
  41. function display() {
  42. $this->type == 2 && !extension_loaded('ming') && $this->type = 0;
  43. $this->width = $this->width >= 0 && $this->width <= 200 ? $this->width : 150;
  44. $this->height = $this->height >= 0 && $this->height <= 80 ? $this->height : 60;
  45. $this->seccodeconvert($this->code);
  46. if($this->type < 2 && function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') &&
  47. function_exists('imagecolorallocate') && function_exists('imagechar') && function_exists('imagecolorsforindex') &&
  48. function_exists('imageline') && function_exists('imagecreatefromstring') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))) {
  49. $this->image();
  50. } elseif($this->type == 2 && extension_loaded('ming')) {
  51. $this->flash();
  52. } elseif($this->type == 3) {
  53. $this->audio();
  54. } else {
  55. $this->bitmap();
  56. }
  57. }
  58. function fileext($filename) {
  59. return trim(substr(strrchr($filename, '.'), 1, 10));
  60. }
  61. function image() {
  62. $bgcontent = $this->background();
  63. if($this->animator == 1 && function_exists('imagegif')) {
  64. include_once $this->includepath.'gifmerge.class.php';
  65. $trueframe = mt_rand(1, 9);
  66. for($i = 0; $i <= 9; $i++) {
  67. $this->im = imagecreatefromstring($bgcontent);
  68. $x[$i] = $y[$i] = 0;
  69. $this->adulterate && $this->adulterate();
  70. if($i == $trueframe) {
  71. $this->ttf && function_exists('imagettftext') || $this->type == 1 ? $this->ttffont() : $this->giffont();
  72. $d[$i] = mt_rand(250, 400);
  73. } else {
  74. $this->adulteratefont();
  75. $d[$i] = mt_rand(5, 15);
  76. }
  77. ob_start();
  78. imagegif($this->im);
  79. imagedestroy($this->im);
  80. $frame[$i] = ob_get_contents();
  81. ob_end_clean();
  82. }
  83. $anim = new GifMerge($frame, 255, 255, 255, 0, $d, $x, $y, 'C_MEMORY');
  84. header('Content-type: image/gif');
  85. echo $anim->getAnimation();
  86. } else {
  87. $this->im = imagecreatefromstring($bgcontent);
  88. $this->adulterate && $this->adulterate();
  89. $this->ttf && function_exists('imagettftext') || $this->type == 1 ? $this->ttffont() : $this->giffont();
  90. if(function_exists('imagepng')) {
  91. header('Content-type: image/png');
  92. imagepng($this->im);
  93. } else {
  94. header('Content-type: image/jpeg');
  95. imagejpeg($this->im, '', 100);
  96. }
  97. imagedestroy($this->im);
  98. }
  99. }
  100. function background() {
  101. $this->im = imagecreatetruecolor($this->width, $this->height);
  102. $backgroundcolor = imagecolorallocate($this->im, 255, 255, 255);
  103. $backgrounds = $c = array();
  104. if($this->background && function_exists('imagecreatefromjpeg') && function_exists('imagecolorat') && function_exists('imagecopymerge') &&
  105. function_exists('imagesetpixel') && function_exists('imageSX') && function_exists('imageSY')) {
  106. if($handle = @opendir($this->datapath.'background/')) {
  107. while($bgfile = @readdir($handle)) {
  108. if(preg_match('/\.jpg$/i', $bgfile)) {
  109. $backgrounds[] = $this->datapath.'background/'.$bgfile;
  110. }
  111. }
  112. @closedir($handle);
  113. }
  114. if($backgrounds) {
  115. $imwm = imagecreatefromjpeg($backgrounds[array_rand($backgrounds)]);
  116. $colorindex = imagecolorat($imwm, 0, 0);
  117. $this->c = imagecolorsforindex($imwm, $colorindex);
  118. $colorindex = imagecolorat($imwm, 1, 0);
  119. imagesetpixel($imwm, 0, 0, $colorindex);
  120. $c[0] = $c['red'];$c[1] = $c['green'];$c[2] = $c['blue'];
  121. imagecopymerge($this->im, $imwm, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), imageSX($imwm), imageSY($imwm), 100);
  122. imagedestroy($imwm);
  123. }
  124. }
  125. if(!$this->background || !$backgrounds) {
  126. for($i = 0;$i < 3;$i++) {
  127. $start[$i] = mt_rand(200, 255);$end[$i] = mt_rand(100, 150);$step[$i] = ($end[$i] - $start[$i]) / $this->width;$c[$i] = $start[$i];
  128. }
  129. for($i = 0;$i < $this->width;$i++) {
  130. $color = imagecolorallocate($this->im, $c[0], $c[1], $c[2]);
  131. imageline($this->im, $i, 0, $i-(isset($angle) ? $angle : 0), $this->height, $color);
  132. $c[0] += $step[0];$c[1] += $step[1];$c[2] += $step[2];
  133. }
  134. $c[0] -= 20;$c[1] -= 20;$c[2] -= 20;
  135. }
  136. ob_start();
  137. if(function_exists('imagepng')) {
  138. imagepng($this->im);
  139. } else {
  140. imagejpeg($this->im, '', 100);
  141. }
  142. imagedestroy($this->im);
  143. $bgcontent = ob_get_contents();
  144. ob_end_clean();
  145. $this->fontcolor = $c;
  146. return $bgcontent;
  147. }
  148. function adulterate() {
  149. $linenums = $this->height / 10;
  150. for($i=0; $i <= $linenums; $i++) {
  151. $color = $this->color ? imagecolorallocate($this->im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)) : imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
  152. $x = mt_rand(0, $this->width);
  153. $y = mt_rand(0, $this->height);
  154. if(mt_rand(0, 1)) {
  155. imagearc($this->im, $x, $y, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, 360), mt_rand(0, 360), $color);
  156. } else {
  157. $linemaxlong = isset($linemaxlong) ? $linemaxlong : 0;
  158. $linex = isset($linex) ? $linex : 0;
  159. $liney = isset($liney) ? $liney : 0;
  160. imageline($this->im, $x, $y, $linex + mt_rand(0, $linemaxlong), $liney + mt_rand(0, mt_rand($this->height, $this->width)), $color);
  161. }
  162. }
  163. }
  164. function adulteratefont() {
  165. $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
  166. $x = $this->width / 4;
  167. $y = $this->height / 10;
  168. $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
  169. for($i = 0; $i <= 3; $i++) {
  170. $adulteratecode = $seccodeunits[mt_rand(0, 23)];
  171. imagechar($this->im, 5, $x * $i + mt_rand(0, $x - 10), mt_rand($y, $this->height - 10 - $y), $adulteratecode, $text_color);
  172. }
  173. }
  174. function ttffont() {
  175. $seccode = $this->code;
  176. $charset = isset($GLOBALS['charset']) ? $GLOBALS['charset'] : '';
  177. $seccoderoot = $this->type ? $this->fontpath.'ch/' : $this->fontpath.'en/';
  178. $dirs = opendir($seccoderoot);
  179. $seccodettf = array();
  180. while($entry = readdir($dirs)) {
  181. if($entry != '.' && $entry != '..' && in_array(strtolower($this->fileext($entry)), array('ttf', 'ttc'))) {
  182. $seccodettf[] = $entry;
  183. }
  184. }
  185. if(empty($seccodettf)) {
  186. $this->giffont();
  187. return;
  188. }
  189. $seccodelength = 4;
  190. if($this->type && !empty($seccodettf)) {
  191. if(strtoupper($charset) != 'UTF-8') {
  192. include $this->includepath.'chinese.class.php';
  193. $cvt = new Chinese($charset, 'utf8');
  194. $seccode = $cvt->Convert($seccode);
  195. }
  196. $seccode = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
  197. $seccodelength = 2;
  198. }
  199. $widthtotal = 0;
  200. for($i = 0; $i < $seccodelength; $i++) {
  201. $font[$i]['font'] = $seccoderoot.$seccodettf[array_rand($seccodettf)];
  202. $font[$i]['angle'] = $this->angle ? mt_rand(-30, 30) : 0;
  203. $font[$i]['size'] = $this->type ? $this->width / 7 : $this->width / 6;
  204. $this->size && $font[$i]['size'] = mt_rand($font[$i]['size'] - $this->width / 40, $font[$i]['size'] + $this->width / 20);
  205. $box = imagettfbbox($font[$i]['size'], 0, $font[$i]['font'], $seccode[$i]);
  206. $font[$i]['zheight'] = max($box[1], $box[3]) - min($box[5], $box[7]);
  207. $box = imagettfbbox($font[$i]['size'], $font[$i]['angle'], $font[$i]['font'], $seccode[$i]);
  208. $font[$i]['height'] = max($box[1], $box[3]) - min($box[5], $box[7]);
  209. $font[$i]['hd'] = $font[$i]['height'] - $font[$i]['zheight'];
  210. $font[$i]['width'] = (max($box[2], $box[4]) - min($box[0], $box[6])) + mt_rand(0, $this->width / 8);
  211. $font[$i]['width'] = $font[$i]['width'] > $this->width / $seccodelength ? $this->width / $seccodelength : $font[$i]['width'];
  212. $widthtotal += $font[$i]['width'];
  213. }
  214. $x = mt_rand($font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $this->width - $widthtotal);
  215. !$this->color && $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
  216. for($i = 0; $i < $seccodelength; $i++) {
  217. if($this->color) {
  218. $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
  219. $this->shadow && $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
  220. $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
  221. } elseif($this->shadow) {
  222. $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
  223. }
  224. $y = $font[0]['angle'] > 0 ? mt_rand($font[$i]['height'], $this->height) : mt_rand($font[$i]['height'] - $font[$i]['hd'], $this->height - $font[$i]['hd']);
  225. $this->shadow && imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x + 1, $y + 1, $text_shadowcolor, $font[$i]['font'], $seccode[$i]);
  226. imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x, $y, $text_color, $font[$i]['font'], $seccode[$i]);
  227. $x += $font[$i]['width'];
  228. }
  229. }
  230. function giffont() {
  231. $seccode = $this->code;
  232. $seccodedir = array();
  233. if(function_exists('imagecreatefromgif')) {
  234. $seccoderoot = $this->datapath.'gif/';
  235. $dirs = opendir($seccoderoot);
  236. while($dir = readdir($dirs)) {
  237. if($dir != '.' && $dir != '..' && file_exists($seccoderoot.$dir.'/9.gif')) {
  238. $seccodedir[] = $dir;
  239. }
  240. }
  241. }
  242. $widthtotal = 0;
  243. for($i = 0; $i <= 3; $i++) {
  244. $this->imcodefile = $seccodedir ? $seccoderoot.$seccodedir[array_rand($seccodedir)].'/'.strtolower($seccode[$i]).'.gif' : '';
  245. if(!empty($this->imcodefile) && file_exists($this->imcodefile)) {
  246. $font[$i]['file'] = $this->imcodefile;
  247. $font[$i]['data'] = getimagesize($this->imcodefile);
  248. $font[$i]['width'] = $font[$i]['data'][0] + mt_rand(0, 6) - 4;
  249. $font[$i]['height'] = $font[$i]['data'][1] + mt_rand(0, 6) - 4;
  250. $font[$i]['width'] += mt_rand(0, $this->width / 5 - $font[$i]['width']);
  251. $widthtotal += $font[$i]['width'];
  252. } else {
  253. $font[$i]['file'] = '';
  254. $font[$i]['width'] = 8 + mt_rand(0, $this->width / 5 - 5);
  255. $widthtotal += $font[$i]['width'];
  256. }
  257. }
  258. $x = mt_rand(1, $this->width - $widthtotal);
  259. for($i = 0; $i <= 3; $i++) {
  260. $this->color && $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
  261. if($font[$i]['file']) {
  262. $this->imcode = imagecreatefromgif($font[$i]['file']);
  263. if($this->size) {
  264. $font[$i]['width'] = mt_rand($font[$i]['width'] - $this->width / 20, $font[$i]['width'] + $this->width / 20);
  265. $font[$i]['height'] = mt_rand($font[$i]['height'] - $this->width / 20, $font[$i]['height'] + $this->width / 20);
  266. }
  267. $y = mt_rand(0, $this->height - $font[$i]['height']);
  268. if($this->shadow) {
  269. $this->imcodeshadow = $this->imcode;
  270. imagecolorset($this->imcodeshadow, 0 , 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
  271. imagecopyresized($this->im, $this->imcodeshadow, $x + 1, $y + 1, 0, 0, $font[$i]['width'], $font[$i]['height'], $font[$i]['data'][0], $font[$i]['data'][1]);
  272. }
  273. imagecolorset($this->imcode, 0 , $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
  274. imagecopyresized($this->im, $this->imcode, $x, $y, 0, 0, $font[$i]['width'], $font[$i]['height'], $font[$i]['data'][0], $font[$i]['data'][1]);
  275. } else {
  276. $y = mt_rand(0, $this->height - 20);
  277. if($this->shadow) {
  278. $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
  279. imagechar($this->im, 5, $x + 1, $y + 1, $seccode[$i], $text_shadowcolor);
  280. }
  281. $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
  282. imagechar($this->im, 5, $x, $y, $seccode[$i], $text_color);
  283. }
  284. $x += $font[$i]['width'];
  285. }
  286. }
  287. function flash() {
  288. $spacing = 5;
  289. $codewidth = ($this->width - $spacing * 5) / 4;
  290. $strforswdaction = '';
  291. for($i = 0; $i <= 3; $i++) {
  292. $strforswdaction .= $this->swfcode($codewidth, $spacing, $this->code[$i], $i+1);
  293. }
  294. ming_setScale(20.00000000);
  295. ming_useswfversion(6);
  296. $movie = new SWFMovie();
  297. $movie->setDimension($this->width, $this->height);
  298. $movie->setBackground(255, 255, 255);
  299. $movie->setRate(31);
  300. $fontcolor = '0x'.(sprintf('%02s', dechex (mt_rand(0, 255)))).(sprintf('%02s', dechex (mt_rand(0, 128)))).(sprintf('%02s', dechex (mt_rand(0, 255))));
  301. $strAction = "
  302. _root.createEmptyMovieClip ( 'triangle', 1 );
  303. with ( _root.triangle ) {
  304. lineStyle( 3, $fontcolor, 100 );
  305. $strforswdaction
  306. }
  307. ";
  308. $movie->add(new SWFAction( str_replace("\r", "", $strAction) ));
  309. header('Content-type: application/x-shockwave-flash');
  310. $movie->output();
  311. }
  312. function swfcode($width, $d, $code, $order) {
  313. $str = '';
  314. $height = $this->height - $d * 2;
  315. $x_0 = ($order * ($width + $d) - $width);
  316. $x_1 = $x_0 + $width / 2;
  317. $x_2 = $x_0 + $width;
  318. $y_0 = $d;
  319. $y_2 = $y_0 + $height;
  320. $y_1 = $y_2 / 2;
  321. $y_0_5 = $y_2 / 4;
  322. $y_1_5 = $y_1 + $y_0_5;
  323. switch($code) {
  324. case 'B':$str .= 'moveTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_1.', '.$y_2.');lineTo('.$x_2.', '.$y_1_5.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
  325. case 'C':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');';break;
  326. case 'E':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
  327. case 'F':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
  328. case 'G':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
  329. case 'H':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
  330. case 'J':$str .= 'moveTo('.$x_1.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_1_5.');';break;
  331. case 'K':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');';break;
  332. case 'M':$str .= 'moveTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');';break;
  333. case 'P':$str .= 'moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');';break;
  334. case 'Q':$str .= 'moveTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_1.', '.$y_1.');';break;
  335. case 'R':$str .= 'moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');';break;
  336. case 'T':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');moveTo('.$x_1.', '.$y_0.');lineTo('.$x_1.', '.$y_2.');';break;
  337. case 'V':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');';break;
  338. case 'W':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');';break;
  339. case 'X':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');';break;
  340. case 'Y':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_1.', '.$y_2.');';break;
  341. case '2':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');';break;
  342. case '3':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
  343. case '4':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
  344. case '6':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');';break;
  345. case '7':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');';break;
  346. case '8':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
  347. case '9':$str .= 'moveTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');';break;
  348. }
  349. return $str;
  350. }
  351. function audio() {
  352. header('Content-type: audio/mpeg');
  353. for($i = 0;$i <= 3; $i++) {
  354. readfile($this->datapath.'sound/'.strtolower($this->code[$i]).'.mp3');
  355. }
  356. }
  357. function bitmap() {
  358. $numbers = array
  359. (
  360. 'B' => array('00','fc','66','66','66','7c','66','66','fc','00'),
  361. 'C' => array('00','38','64','c0','c0','c0','c4','64','3c','00'),
  362. 'E' => array('00','fe','62','62','68','78','6a','62','fe','00'),
  363. 'F' => array('00','f8','60','60','68','78','6a','62','fe','00'),
  364. 'G' => array('00','78','cc','cc','de','c0','c4','c4','7c','00'),
  365. 'H' => array('00','e7','66','66','66','7e','66','66','e7','00'),
  366. 'J' => array('00','f8','cc','cc','cc','0c','0c','0c','7f','00'),
  367. 'K' => array('00','f3','66','66','7c','78','6c','66','f7','00'),
  368. 'M' => array('00','f7','63','6b','6b','77','77','77','e3','00'),
  369. 'P' => array('00','f8','60','60','7c','66','66','66','fc','00'),
  370. 'Q' => array('00','78','cc','cc','cc','cc','cc','cc','78','00'),
  371. 'R' => array('00','f3','66','6c','7c','66','66','66','fc','00'),
  372. 'T' => array('00','78','30','30','30','30','b4','b4','fc','00'),
  373. 'V' => array('00','1c','1c','36','36','36','63','63','f7','00'),
  374. 'W' => array('00','36','36','36','77','7f','6b','63','f7','00'),
  375. 'X' => array('00','f7','66','3c','18','18','3c','66','ef','00'),
  376. 'Y' => array('00','7e','18','18','18','3c','24','66','ef','00'),
  377. '2' => array('fc','c0','60','30','18','0c','cc','cc','78','00'),
  378. '3' => array('78','8c','0c','0c','38','0c','0c','8c','78','00'),
  379. '4' => array('00','3e','0c','fe','4c','6c','2c','3c','1c','1c'),
  380. '6' => array('78','cc','cc','cc','ec','d8','c0','60','3c','00'),
  381. '7' => array('30','30','38','18','18','18','1c','8c','fc','00'),
  382. '8' => array('78','cc','cc','cc','78','cc','cc','cc','78','00'),
  383. '9' => array('f0','18','0c','6c','dc','cc','cc','cc','78','00')
  384. );
  385. foreach($numbers as $i => $number) {
  386. for($j = 0; $j < 6; $j++) {
  387. $a1 = substr('012', mt_rand(0, 2), 1).substr('012345', mt_rand(0, 5), 1);
  388. $a2 = substr('012345', mt_rand(0, 5), 1).substr('0123', mt_rand(0, 3), 1);
  389. mt_rand(0, 1) == 1 ? array_push($numbers[$i], $a1) : array_unshift($numbers[$i], $a1);
  390. mt_rand(0, 1) == 0 ? array_push($numbers[$i], $a1) : array_unshift($numbers[$i], $a2);
  391. }
  392. }
  393. $bitmap = array();
  394. for($i = 0; $i < 20; $i++) {
  395. for($j = 0; $j <= 3; $j++) {
  396. $bytes = $numbers[$this->code[$j]][$i];
  397. $a = mt_rand(0, 14);
  398. array_push($bitmap, $bytes);
  399. }
  400. }
  401. for($i = 0; $i < 8; $i++) {
  402. $a = substr('012345', mt_rand(0, 2), 1) . substr('012345', mt_rand(0, 5), 1);
  403. array_unshift($bitmap, $a);
  404. array_push($bitmap, $a);
  405. }
  406. $image = pack('H*', '424d9e000000000000003e000000280000002000000018000000010001000000'.
  407. '0000600000000000000000000000000000000000000000000000FFFFFF00'.implode('', $bitmap));
  408. header('Content-Type: image/bmp');
  409. echo $image;
  410. }
  411. }
  412. ?>