PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/miles/GlobalMBA/mba/sns_00/upload/ucenter/lib/seccode.class.php

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