PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/source/class/class_seccode.php

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