PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/source/class/class_seccode.php

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