PageRenderTime 73ms CodeModel.GetById 2ms app.highlight 61ms RepoModel.GetById 1ms app.codeStats 0ms

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