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

/Upload/DoYouHaoBaby/LibPHP/App/Package/Util/Seccode.class.php

http://dyhb-frame.googlecode.com/
PHP | 594 lines | 553 code | 37 blank | 4 comment | 77 complexity | 49bb21925ae9c281f9783edf56ee7c66 MD5 | raw file
  1. <?php
  2. /* [DoYouHaoBaby!] (C)Dianniu From 2010.
  3. ??????Modify from Discuz!?($)*/
  4. !defined('DYHB_PATH') && exit;
  5. class Seccode{
  6. protected $_nCode;
  7. protected $_nWidth=0;
  8. protected $_nHeight=0;
  9. protected $_bBackground=TRUE;
  10. protected $_bImageBackground=TRUE;
  11. protected $_bAdulterate=TRUE;
  12. protected $_bTtf=TRUE;
  13. protected $_bTilt=TRUE;
  14. protected $_bColor=TRUE;
  15. protected $_bSize=TRUE;
  16. protected $_bShadow=TRUE;
  17. protected $_sFontPath;
  18. protected $_sDataPath='';
  19. protected $_arrFontColor;
  20. protected $_oIm;
  21. protected $_sImCodeFile='';
  22. protected $_oImCode=null;
  23. protected $_oImCodeShadow=null;
  24. protected $_bChineseCode=false;
  25. protected $_oColor=null;
  26. protected $_bAnimator=false;
  27. protected $_nType=1;
  28. protected $_bNoise=false;
  29. protected $_bCurve=false;
  30. protected $_arrCodeSet='346789ABCDEFGHJKLMNPQRTUVWXY';
  31. protected $_nFontSize=25;
  32. const SECCODE_IMAGE_WIDTH_MAX_SIZE=160;
  33. const SECCODE_IMAGE_HEIGHT_MAX_SIZE=60;
  34. protected $_arrDefaultOption=array(
  35. 'seccode_image_width_size'=>160,
  36. 'seccode_image_height_size'=>60,
  37. 'seccode_adulterate'=>true,
  38. 'seccode_ttf'=>true,
  39. 'seccode_tilt'=>true,
  40. 'seccode_color'=>true,
  41. 'seccode_size'=>true,
  42. 'seccode_shadow'=>true,
  43. 'seccode_fontpath'=>'',
  44. 'seccode_datapath'=>'',
  45. 'seccode_chinesecode'=>false,
  46. 'seccode_animator'=>false,
  47. 'seccode_tupe'=>1,
  48. 'seccode_norise'=>false,
  49. 'seccode_curve'=>false,
  50. 'seccode_codeset'=>array(),
  51. 'seccode_fontsize'=>25,
  52. 'seccode_background'=>true,
  53. 'seccode_image_background'=>true);
  54. public function __construct($arrOption=null){
  55. $this->_arrDefaultOption['seccode_fontpath']=DYHB_PATH.'/Resource/Seccode/Fonts';
  56. $this->_arrDefaultOption['seccode_datapath']=DYHB_PATH.'/Resource/Seccode';
  57. if(!empty($arrOption)){
  58. $arrDefaultOption=array_merge($this->_arrDefaultOption,$arrOption);
  59. }else{
  60. $arrDefaultOption=$this->_arrDefaultOption;
  61. }
  62. return $this->setWidth($arrDefaultOption['seccode_image_width_size'])// ?????
  63. ->setHeight($arrDefaultOption['seccode_image_height_size']) // ?????
  64. ->setAdulterate($arrDefaultOption['seccode_adulterate']) // ??????
  65. ->setTtf($arrDefaultOption['seccode_ttf'])// ??TTF??
  66. ->setTilt($arrDefaultOption['seccode_tilt'])//?????
  67. ->setColor($arrDefaultOption['seccode_color'])//????
  68. ->setSize($arrDefaultOption['seccode_size'])//????
  69. ->setShadow($arrDefaultOption['seccode_shadow'])//????
  70. ->setFontPath($arrDefaultOption['seccode_fontpath'])// ????
  71. ->setDataPath($arrDefaultOption['seccode_datapath'])// ???????
  72. ->setChineseCode($arrDefaultOption['seccode_chinesecode'])// ?????????
  73. ->setAnimator($arrDefaultOption['seccode_animator'])//??????
  74. ->setType($arrDefaultOption['seccode_tupe'])// ???????????? 1???????? 2??????????
  75. ->setNorise($arrDefaultOption['seccode_norise'])// ??????
  76. ->setCurve($arrDefaultOption['seccode_curve'])// ??????
  77. ->setCodeSet($arrDefaultOption['seccode_codeset'])// ???????????????
  78. ->setFontSize($arrDefaultOption['seccode_fontsize'])// ???????(px)
  79. ->setBackground($arrDefaultOption['seccode_background'])// ??????
  80. ->setImageBackground($arrDefaultOption['seccode_image_background']);// ????????????????????
  81. }
  82. public function setCode($nCode){
  83. if(empty($nCode) or $nCode==0){return $this;}
  84. $this->_nCode=$nCode;
  85. return $this;
  86. }
  87. public function setWidth($nWidth){
  88. if(empty($nWidth) or $nWidth==0){return $this;}
  89. $this->_nWidth=$nWidth;
  90. return $this;
  91. }
  92. public function setHeight($nHeight){
  93. if(empty($nHeight) or $nHeight==0){return $this;}
  94. $this->_nHeight=$nHeight;
  95. return $this;
  96. }
  97. public function setAdulterate($bValue){
  98. $this->_bAdulterate=$bValue;
  99. return $this;
  100. }
  101. public function setTtf($bValue){
  102. $this->_bTtf=$bValue;
  103. return $this;
  104. }
  105. public function setTilt( $bValue){
  106. $this->_bTilt=$bValue;
  107. return $this;
  108. }
  109. public function setColor($bValue){
  110. $this->_bColor=$bValue;
  111. return $this;
  112. }
  113. public function setShadow($bValue){
  114. $this->_bShadow=$bValue;
  115. return $this;
  116. }
  117. public function setFontPath($sPath){
  118. if( empty( $sPath)){return $this;}
  119. $this->_sFontPath=$sPath;
  120. return $this;
  121. }
  122. public function setSize($bSize){
  123. $this->_bSize=$bSize;
  124. return $this;
  125. }
  126. public function setDataPath($sDataPath){
  127. if(empty($sDataPath)){return $this;}
  128. $this->_sDataPath=$sDataPath;
  129. return $this;
  130. }
  131. public function setChineseCode($bChineseCode){
  132. $this->_bChineseCode=$bChineseCode;
  133. return $this;
  134. }
  135. public function setAnimator($bAnimator){
  136. $this->_bAnimator=$bAnimator;
  137. return $this;
  138. }
  139. public function setType($nType){
  140. if(!in_array($nType,array(1,2)))return $this;
  141. $this->_nType=$nType;
  142. return $this;
  143. }
  144. public function setNorise($bNorise){
  145. $this->_bNorise=$bNorise;
  146. return $this;
  147. }
  148. public function setCurve($bCurve){
  149. $this->_bCurve=$bCurve;
  150. return $this;
  151. }
  152. public function setFontSize($nFontSize){
  153. if(empty($nFontSize)){return $this;}
  154. $this->_nFontSize=$nFontSize;
  155. return $this;
  156. }
  157. public function setCodeSet($arrCodeSet){
  158. if(empty( $nFontSize)){return $this;}
  159. $this->_arrCodeSet=$arrCodeSet;
  160. return $this;
  161. }
  162. public function setBackground($bBackground){
  163. $this->_bBackground=$bBackground;
  164. return $this;
  165. }
  166. public function setImageBackground($bImageBackground){
  167. $this->_bImageBackground=$bImageBackground;
  168. return $this;
  169. }
  170. public function display(){
  171. $nMaxWidthSize=self::SECCODE_IMAGE_WIDTH_MAX_SIZE;
  172. $nMaxHeightSize=self::SECCODE_IMAGE_HEIGHT_MAX_SIZE;
  173. $this->_nWidth=$this->_nWidth >=0 && $this->_nWidth<=$nMaxWidthSize?$this->_nWidth:$nMaxWidthSize;// ???????
  174. $this->_nHeight=$this->_nHeight>=0 && $this->_nHeight<=$nMaxHeightSize?$this->_nHeight:$nMaxHeightSize;
  175. E::seccodeConvert($this->_nCode,$this->_bChineseCode,$this->_nType);// ??
  176. if( function_exists('imagecreate') and function_exists('imagecolorset') and function_exists('imagecopyresized') and function_exists('imagecolorallocate') and function_exists('imagesetpixel') and function_exists('imagechar') and function_exists('imageline') and function_exists('imagecreatefromstring') and (function_exists('imagegif') or function_exists('imagepng') or function_exists('imagejpeg'))){
  177. $this->image();
  178. }
  179. else{
  180. $this->bitMap();
  181. }
  182. }
  183. protected function fileExt($sFileName){
  184. return trim(substr(strrchr($sFileName,'.'),1,10));
  185. }
  186. protected function image(){
  187. $sBgContent=$this->background();// ?????
  188. if($this->_bAnimator===TRUE && function_exists('imagegif')){// ?????????
  189. $nTrueFrame=mt_rand(1,9);
  190. for($nI=0;$nI<=9;$nI++){
  191. $this->_oIm=imagecreatefromstring($sBgContent);
  192. $arrX[$nI]=$arrY[$nI]=0;
  193. $this->_bAdulterate && $this->adulterate();
  194. if($nI==$nTrueFrame){
  195. $this->_bTtf && function_exists('imagettftext') || $this->_nType== 1?$this->ttfFont():$this->gifFont();
  196. $this->gifFont();
  197. $arrD[$nI]=mt_rand(250, 400);
  198. }
  199. else{
  200. $this->adulterateFont();
  201. $arrD[$nI]=mt_rand(5, 15);
  202. }
  203. if($this->_bNorise){// ??????
  204. $this->writeNoise_();
  205. }
  206. if($this->_bCurve){// ??????
  207. $this->writeCurve_();
  208. }
  209. ob_start();
  210. imagegif($this->_oIm);
  211. imagedestroy($this->_oIm);
  212. $arrFrame[$nI]=ob_get_contents();
  213. ob_end_clean();
  214. }
  215. $oAnim=new GifMerge($arrFrame ,255,255,255,0,$arrD,$arrX,$arrY,'C_MEMORY');
  216. @header('Content-type: image/gif');
  217. echo $oAnim->getAnimation();
  218. }
  219. else{
  220. $this->_oIm=imagecreatefromstring( $sBgContent); // ????
  221. $this->_bAdulterate and $this->adulterate(); // ????
  222. $this->_bTtf and function_exists('imagettftext')?$this->ttfFont():$this->textFont(); // ??????
  223. if($this->_bNorise){// ??????
  224. $this->writeNoise_();
  225. }
  226. if($this->_bCurve){// ??????
  227. $this->writeCurve_();
  228. }
  229. if(function_exists('imagepng')){// ????png???????????
  230. header('Content-type: image/png');
  231. imagepng( $this->_oIm);
  232. }
  233. else{// ??jpeg??
  234. header('Content-type: image/jpeg');
  235. imagejpeg($this->_oIm,'',100);
  236. }
  237. imagedestroy($this->_oIm);
  238. }
  239. }
  240. protected function writeCurve_(){
  241. $nPx=$nPy=0;
  242. // ?????
  243. $nA=mt_rand(1,$this->_nHeight/2);// ??
  244. $nB=mt_rand(-$this->_nHeight/4,$this->_nHeight/4);// Y??????
  245. $nF=mt_rand(-$this->_nHeight/4,$this->_nHeight/4);// X??????
  246. $nT=mt_rand($this->_nHeight,$this->_nWidth*2);// ??
  247. $nW=(2*M_PI)/$nT;
  248. $bIsBreak=mt_rand(0,1);
  249. $nPx1=0;// ?????????
  250. $nPx2=mt_rand($this->_nWidth/2,$this->_nWidth*0.8);// ?????????
  251. for($nPx=$nPx1;$nPx<=$nPx2;$nPx=$nPx+0.9){
  252. if($nW!=0){
  253. $nPy=$nA*sin($nW*$nPx+$nF)+$nB+$this->_nHeight/2;// y=Asin(?x+?)+ b
  254. $nI=(int)(($this->_nFontSize-6)/4);
  255. while($nI>0){
  256. imagesetpixel($this->_oIm,$nPx+($bIsBreak?$nI:0),$nPy+$nI,$this->_oColor);
  257. $nI--;
  258. }
  259. }
  260. }
  261. // ?????
  262. $nA=mt_rand(1,$this->_nHeight/2);// ??
  263. $nF=mt_rand(-$this->_nHeight/4,$this->_nHeight/4);// X??????
  264. $nT=mt_rand($this->_nHeight, $this->_nWidth*2); // ??
  265. $nW=(2*M_PI)/$nT;
  266. $nB=$nPy-$nA*sin($nW*$nPx+$nF)-$this->_nHeight/2;
  267. $nPx1=$nPx2;
  268. $nPx2=$this->_nWidth;
  269. $bIsBreak=mt_rand(0,1);
  270. for($nPx=$nPx1;$nPx<=$nPx2;$nPx=$nPx+0.9){
  271. if($nW!=0){
  272. $nPy=$nA*sin($nW*$nPx+$nF)+$nB+$this->_nHeight/2;// y=Asin(?x+?)+ b
  273. $nI=(int)(($this->_nFontSize-8)/4);
  274. while($nI>0){
  275. imagesetpixel( $this->_oIm,$nPx+($bIsBreak?$nI:0),$nPy+$nI,$this->_oColor);
  276. $nI--;
  277. }
  278. }
  279. }
  280. }
  281. protected function writeNoise_(){
  282. for($nI=0;$nI<10;$nI++){
  283. $noiseColor=imagecolorallocate($this->_oIm,mt_rand(150,225),mt_rand(150,225),mt_rand(150,225));// ????
  284. for($nJ=0;$nJ<5;$nJ++){
  285. imagestring($this->_oIm,5,mt_rand(-10,$this->_nWidth),mt_rand(-10,$this->_nHeight),$this->_arrCodeSet[mt_rand(0, 27)], /* ????????????? */$noiseColor);// ???
  286. }
  287. }
  288. }
  289. protected function background(){
  290. $this->_oIm=imagecreatetruecolor($this->_nWidth,$this->_nHeight);// ???????????
  291. $oBackgroundColor=imagecolorallocate($this->_oIm,255,255,255);// ????
  292. $arrBackgrounds=$arrC=array();
  293. if($this->_bBackground && $this->_bImageBackground && function_exists('imagecreatefromjpeg') && function_exists('imagecolorat') && function_exists('imagecopymerge') && function_exists('imagesetpixel') && function_exists('imageSX') && function_exists('imageSY')){
  294. if($hHandle=@opendir($this->_sDataPath.'/background')){
  295. while($sBgFile=@readdir($hHandle)){
  296. if(preg_match( '/\.jpg$/i',$sBgFile)){
  297. $arrBackgrounds[]=$this->_sDataPath.'/background/'.$sBgFile;
  298. }
  299. }
  300. @closedir($hHandle);
  301. }
  302. if($arrBackgrounds){
  303. $oImwm=imagecreatefromjpeg($arrBackgrounds[ array_rand( $arrBackgrounds)]);// ??????????????
  304. $oColorIndex=imagecolorat($oImwm,0,0);// imagecolorat?????????
  305. $arrC=imagecolorsforindex($oImwm,$oColorIndex);// imagecolorsforindex ????
  306. $oColorIndex=imagecolorat($oImwm,1,0);
  307. imagesetpixel($oImwm,0,0,$oColorIndex);// ????
  308. $arrC[0]=$arrC['red'];
  309. $arrC[1]=$arrC['green'];
  310. $arrC[2]=$arrC['blue'];
  311. imagecopymerge($this->_oIm,$oImwm,0,0,mt_rand(0,200-$this->_nWidth),mt_rand(0,80-$this->_nHeight),imageSX($oImwm),imageSY($oImwm),100);// imagecopymerge????png????
  312. imagedestroy( $oImwm);
  313. }
  314. }
  315. if(!$this->_bBackground || !$arrBackgrounds){
  316. for($nI=0;$nI<3;$nI++){
  317. $arrStart[$nI]=mt_rand(200,255);
  318. $arrEnd[$nI]=mt_rand(100,150);
  319. $arrStep[$nI]=($arrEnd[$nI]-$arrStart[$nI])/$this->_nWidth;
  320. $arrC[$nI]=$arrStart[$nI];
  321. }
  322. for($nI=0;$nI<$this->_nWidth;$nI++){
  323. $oColor=imagecolorallocate($this->_oIm,$arrC[0],$arrC[1],$arrC[2]);
  324. imageline($this->_oIm,$nI,0,$nI-(isset($bTilt)?$bTilt:0),$this->_nHeight,$oColor);
  325. $arrC[0]+=$arrStep[0];
  326. $arrC[1]+=$arrStep[1];
  327. $arrC[2]+=$arrStep[2];
  328. }
  329. $arrC[0]-=20;
  330. $arrC[1]-=20;
  331. $arrC[2]-=20;
  332. }
  333. ob_start();
  334. if(function_exists('imagepng')){
  335. imagepng($this->_oIm);
  336. }
  337. else{
  338. imagejpeg($this->_oIm,'',100);
  339. }
  340. imagedestroy( $this->_oIm);
  341. $sBgContent=ob_get_contents();
  342. ob_end_clean();
  343. $this->_arrFontColor=$arrC;
  344. return $sBgContent;
  345. }
  346. protected function adulterate(){
  347. $nLineNums=$this->_nHeight/10;
  348. for($nI=0;$nI<=$nLineNums;$nI++){
  349. $oColor=$this->_bColor?imagecolorallocate($this->_oIm,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)):imagecolorallocate($this->_oIm,$this->_arrFontColor[0],$this->__arrFontColor[1], $this->_arrFontColor[2]);
  350. $nX=mt_rand(0,$this->_nWidth);
  351. $nY=mt_rand(0,$this->_nHeight);
  352. if(mt_rand(0,1)){
  353. imagearc($this->_oIm,$nX,$nY,mt_rand(0,$this->_nWidth),mt_rand(0,$this->_nHeight),mt_rand(0,360),mt_rand(0,360),$oColor);
  354. }
  355. else{
  356. $nLineMaxLong=isset($nLineMaxLong)?$nLineMaxLong:0;
  357. $nLineX=isset($nLineX)?$nLineX:0;
  358. $nLineY=isset($nLineY)?$nLineY:0;
  359. imageline($this->_oIm,$nX,$nY,$nLineX+mt_rand(0,$nLineMaxLong),$nLineY+mt_rand(0,mt_rand($this->_nHeight,$this->_nWidth)),$oColor);
  360. }
  361. }
  362. $this->_oColor=$oColor;
  363. }
  364. protected function ttfFont(){
  365. $nSeccode=$this->_nCode; // ???
  366. $sSeccodeRoot=$this->_sFontPath.($this->_bChineseCode===true?'/Zh-cn':'/En' ); // ????
  367. $hDirs=opendir($sSeccodeRoot);// ???????
  368. $arrSeccodeTtf=array();
  369. while($entry=readdir( $hDirs)){
  370. if($entry!='.' and $entry!='..' and in_array(strtolower($this->fileExt($entry)),array('ttf','ttc'))){
  371. $arrSeccodeTtf[]=$entry;
  372. }
  373. }
  374. if(empty($arrSeccodeTtf)){// ??????????????????
  375. $this->textFont();
  376. return;
  377. }
  378. $nSeccodeLength=4;// ?????
  379. $nWidthTotal=0;
  380. for($nI=0;$nI<$nSeccodeLength;$nI++){
  381. $arrFont[$nI]['font']=$sSeccodeRoot.'/'.$arrSeccodeTtf[array_rand($arrSeccodeTtf)]; // ??
  382. $arrFont[$nI]['tilt']=$this->_bTilt?mt_rand(-30,30):0;// ?????????
  383. $arrFont[$nI]['size']=$this->_nWidth/6;// ?? 1/6????( $this->_nFontSize??????)
  384. $this->_bSize and $arrFont[$nI]['size']=mt_rand( $arrFont[$nI]['size']-$this->_nWidth/40,$arrFont[$nI]['size']+$this->_nWidth/20); // ????
  385. $oBox=imagettfbbox($arrFont[$nI]['size'], 0, $arrFont[$nI]['font'], $nSeccode[$nI]);
  386. $arrFont[$nI]['zheight']=max($oBox[1],$oBox[3])-min($oBox[5],$oBox[7]);
  387. $oBox=imagettfbbox($arrFont[$nI]['size'],$arrFont[$nI]['tilt'],$arrFont[$nI]['font'],$nSeccode[$nI]);
  388. $arrFont[$nI]['height']=max($oBox[1],$oBox[3])-min($oBox[5],$oBox[7]);
  389. $arrFont[$nI]['hd']=$arrFont[$nI]['height']-$arrFont[$nI]['zheight'];
  390. $arrFont[$nI]['width']=(max($oBox[2],$oBox[4])-min($oBox[0],$oBox[6]))+mt_rand(0,$this->_nWidth/8);
  391. $arrFont[$nI]['width']=$arrFont[$nI]['width']>$this->_nWidth/$nSeccodeLength?$this->_nWidth/$nSeccodeLength:$arrFont[$nI]['width'];
  392. $nWidthTotal+=$arrFont[$nI]['width'];
  393. }
  394. $nX=mt_rand($arrFont[0]['tilt']>0?cos(deg2rad(90-$arrFont[0]['tilt']))*$arrFont[0]['zheight']:1,$this->_nWidth-$nWidthTotal);// deg2rad()??????????&cos?cosine???.??????
  395. !$this->_bColor and $oTextColor=imagecolorallocate($this->_oIm,$this->_arrFontColor[0],$this->_arrFontColor[1],$this->_arrFontColor[2]); // ????????
  396. for($nI=0;$nI<$nSeccodeLength;$nI++){
  397. if($this->_bColor){
  398. $this->_arrFontColor=array(mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  399. $this->_bShadow and $oTextShadowcolor=imagecolorallocate($this->_oIm,255-$this->_arrFontColor[0],255-$this->_arrFontColor[1],255-$this->_arrFontColor[2]);
  400. $oTextColor=imagecolorallocate($this->_oIm,$this->_arrFontColor[0],$this->_arrFontColor[1],$this->_arrFontColor[2]);
  401. }
  402. elseif($this->_bShadow){
  403. $oTextShadowcolor=imagecolorallocate($this->_oIm,255-$this->_arrFontColor[0],255-$this->_arrFontColor[1],255-$this->_arrFontColor[2]);
  404. }
  405. $nY=$arrFont[0]['tilt']>0?mt_rand($arrFont[$nI]['height'],$this->_nHeight):mt_rand($arrFont[$nI]['height']-$arrFont[$nI]['hd'],$this->_nHeight-$arrFont[$nI]['hd']);
  406. $this->_bShadow and imagettftext($this->_oIm,$arrFont[$nI]['size'],$arrFont[$nI]['tilt'],$nX+1,$nY+1,$oTextShadowcolor,$arrFont[$nI]['font'],$nSeccode[$nI]);
  407. imagettftext($this->_oIm,$arrFont[$nI]['size'],$arrFont[$nI]['tilt'],$nX,$nY,$oTextColor,$arrFont[$nI]['font'],$nSeccode[$nI]);
  408. $nX+=$arrFont[$nI]['width'];
  409. }
  410. }
  411. protected function adulterateFont(){
  412. $sSeccodeUnits='BCEFGHJKMPQRTVWXY2346789';// ????
  413. $nX=$this->_nWidth/4;
  414. $nY=$this->_nHeight/10;
  415. $oTextColor=imagecolorallocate( $this->_oIm,$this->_arrFontColor[0],$this->_arrFontColor[1],$this->_arrFontColor[2]);// ????
  416. for($nI=0;$nI<=3;$nI++){
  417. $sAdulterateCode=$sSeccodeUnits[mt_rand(0,23)];
  418. imagechar($this->_oIm,5,$nX*$nI+mt_rand(0,$nX-10),mt_rand($nY,$this->_nHeight-10-$nY),$sAdulterateCode,$oTextColor);
  419. }
  420. }
  421. protected function textFont(){
  422. $nSeccode=$this->_ncode;
  423. $nWidthTotal=0;
  424. for($nI=0;$nI<=3;$nI++){
  425. $arrFont[$nI]['width']=8+mt_rand(0,$this->_nWidth/5-5);
  426. $nWidthTotal+=$arrFont[$nI]['width'];
  427. }
  428. $nX=mt_rand(1,$this->_nWidth-$nWidthTotal);
  429. for($nI=0;$nI<=3;$nI++){
  430. $this->_oColor && $this->_arrFontColor=array(mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  431. $nY=mt_rand(0,$this->_nHeight-20);
  432. if($this->_bShadow){
  433. $oTextShadowColor=imagecolorallocate($this->_oIm,255-$this->_arrFontcolor[0],255-$this->_arrFontcolor[1],255-$this->_arrFontcolor[2]);
  434. imagechar($this->_oIm,5,$nX+1,$nY+1,$nSeccode[$nI],$oTextShadowColor);
  435. }
  436. $oTextColor=imagecolorallocate($this->_oIm,$this->_arrFontColor[0],$this->_arrFontColor[1],$this->_arrFontColor[2]);
  437. imagechar($this->_oIm,5,$nX,$nY,$this->_arrFontColor[$nX],$oTextColor);
  438. $nX+=$arrFont[$nI]['width'];
  439. }
  440. }
  441. protected function gifFont(){
  442. $nSeccode=$this->_nCode;
  443. $arrSeccodeDir=array();
  444. if(function_exists( 'imagecreatefromgif')){// ???????gif??
  445. $sSeccodeRoot=$this->_sDataPath.'/gif';
  446. $arrDirs=opendir($sSeccodeRoot);
  447. while($sDir=readdir($arrDirs)){
  448. if($sDir!='.' && $sDir!='..' && file_exists($sSeccodeRoot.'/'.$sDir.'/9.gif')){
  449. $arrSeccodeDir[]=$sDir;
  450. }
  451. }
  452. }
  453. $nWidthTotal=0;
  454. for($nI=0;$nI<=3;$nI++){
  455. $this->_sImCodeFile=$arrSeccodeDir?$sSeccodeRoot.$arrSeccodeDir[array_rand($arrSeccodeDir)].'/'.strtolower( $nSeccode[$nI]).'.gif':'';// ?????????
  456. if(!empty( $this->_sImCodeFile) && file_exists($this->_sImCodeFile)){
  457. $arrFont[$nI]['file']=$this->_sImCodeFile;
  458. $arrFont[$nI]['data']=getimagesize( $this->_sImCodeFile);
  459. $arrFont[$nI]['width']=$arrFont[$nI]['data'][0]+mt_rand(0,6)-4;
  460. $arrFont[$nI]['height']=$arrFont[$nI]['data'][1]+mt_rand(0,6)-4;
  461. $arrFont[$nI]['width'] += mt_rand(0,$this->_nWidth/5-$arrFont[$nI]['width']);
  462. $nWidthTotal+=$arrFont[$nI]['width'];
  463. }
  464. else{
  465. $arrFont[$nI]['file']='';
  466. $arrFont[$nI]['width']=8+mt_rand(0,$this->_nWidth/5-5);
  467. $nWidthTotal+=$arrFont[$nI]['width'];
  468. }
  469. }
  470. $nX=mt_rand(1,$this->_nWidth-$nWidthTotal);
  471. for($nI=0;$nI<=3;$nI++){
  472. $this->_oColor && $this->_arrFontColor=array(mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  473. if($arrFont[$nI]['file']){
  474. $this->_oImCode=imagecreatefromgif($arrFont[$nI]['file']);
  475. if($this->_bSize){
  476. $arrFont[$nI]['width']=mt_rand($arrFont[$nI]['width']-$this->_nWidth/20,$arrFont[$nI]['width']+$this->_nWidth/20);
  477. $arrFont[$nI]['height']=mt_rand($arrFont[$nI]['height']-$this->_nWidth/20,$arrFont[$nI]['height']+$this->_nWidth/20);
  478. }
  479. $nY=mt_rand(0,$this->_nHeight-$arrFont[$nI]['height']);
  480. if($this->_bShadow){
  481. $this->_oImCodeShadow=$this->_oImCode;
  482. imagecolorset($this->_oImCodeShadow,0,255-$this->_arrFontColor[0],255-$this->_arrFontColor[1],255-$this->_arrFontColor[2]);
  483. imagecopyresized($this->_oIm,$this->_oImCodeShadow,$nX+1,$nY+1,0,0,$arrFont[$nI]['width'],$arrFont[$nI]['height'],$arrFont[$nI]['data'][0],$arrFont[$nI]['data'][1]);
  484. }
  485. imagecolorset($this->_oImCode,0,$this->_arrFontColor[0],$this->_arrFontColor[1],$this->_arrFontColor[2]);
  486. imagecopyresized($this->_oIm,$this->_oImCode,$nX,$nY,0,0,$arrFont[$nI]['width'],$arrFont[$nI]['height'],$arrFont[$nI]['data'][0],$arrFont[$nI]['data'][1]);
  487. }
  488. else{
  489. $nY=mt_rand(0,$this->_nHeight-20);
  490. if($this->_bShadow){
  491. $oTextShadowcolor=imagecolorallocate($this->_oIm,255-$this->_arrFontColor[0],255-$this->_arrFontColor[1],255-$this->_arrFontColor[2]);
  492. imagechar($this->_oIm,5,$nX+1,$nY+1,$nSeccode[$nI],$oTextShadowcolor);
  493. }
  494. $oTextColor=imagecolorallocate($this->_oIm,$this->_arrFontColor[0],$this->_arrFontColor[1],$this->_arrFontColor[2]);
  495. imagechar($this->_oIm,5,$nX,$nY,$nSeccode[$nI],$oTextColor);
  496. }
  497. $nX+=$arrFont[$nI]['width'];
  498. }
  499. }
  500. protected function bitmap(){
  501. $arrNumbers=array(
  502. 'B'=>array('00','fc','66','66','66','7c','66','66','fc','00'),
  503. 'C'=>array('00','38','64','c0','c0','c0','c4','64','3c','00'),
  504. 'E'=>array('00','fe','62','62','68','78','6a','62','fe','00'),
  505. 'F'=>array('00','f8','60','60','68','78','6a','62','fe','00'),
  506. 'G'=>array('00','78','cc','cc','de','c0','c4','c4','7c','00'),
  507. 'H'=>array('00','e7','66','66','66','7e','66','66','e7','00'),
  508. 'J'=>array('00','f8','cc','cc','cc','0c','0c','0c','7f','00'),
  509. 'K'=>array('00','f3','66','66','7c','78','6c','66','f7','00'),
  510. 'M'=>array('00','f7','63','6b','6b','77','77','77','e3','00'),
  511. 'P'=>array('00','f8','60','60','7c','66','66','66','fc','00'),
  512. 'Q'=>array('00','78','cc','cc','cc','cc','cc','cc','78','00'),
  513. 'R'=>array('00','f3','66','6c','7c','66','66','66','fc','00'),
  514. 'T'=>array('00','78','30','30','30','30','b4','b4','fc','00'),
  515. 'V'=>array('00','1c','1c','36','36','36','63','63','f7','00'),
  516. 'W'=>array('00','36','36','36','77','7f','6b','63','f7','00'),
  517. 'X'=>array('00','f7','66','3c','18','18','3c','66','ef','00'),
  518. 'Y'=>array('00','7e','18','18','18','3c','24','66','ef','00'),
  519. '2'=>array('fc','c0','60','30','18','0c','cc','cc','78','00'),
  520. '3'=>array('78','8c','0c','0c','38','0c','0c','8c','78','00'),
  521. '4'=>array('00','3e','0c','fe','4c','6c','2c','3c','1c','1c'),
  522. '6'=>array('78','cc','cc','cc','ec','d8','c0','60','3c','00'),
  523. '7'=>array('30','30','38','18','18','18','1c','8c','fc','00'),
  524. '8'=>array('78','cc','cc','cc','78','cc','cc','cc','78','00'),
  525. '9'=>array('f0','18','0c','6c','dc','cc','cc','cc','78','00')
  526. );
  527. foreach($arrNumbers as $nI=>$arrNumber){
  528. for($nJ=0;$nJ<6;$nJ++){
  529. $sA1=substr('012',mt_rand(0,2),1).substr('012345',mt_rand(0,5),1);
  530. $sA2=substr('012345',mt_rand(0,5),1).substr('0123',mt_rand(0,3),1);
  531. mt_rand(0,1)== 1 ? array_push($arrNumbers[$nI],$sA1): array_unshift($arrNumbers[$nI],$sA1);
  532. mt_rand(0,1)== 0 ? array_push($arrNumbers[$nI],$sA1): array_unshift($arrNumbers[$nI],$sA2);
  533. }
  534. }
  535. $arrBitmap=array();
  536. for($nI=0;$nI<20;$nI++){
  537. for($nJ=0;$nJ<=3;$nJ++){
  538. $nA=mt_rand(0,14);
  539. if(isset($arrNumbers[$this->_nCode[$nJ]])){
  540. $nBytes=$arrNumbers[$this->_nCode[$nJ]][$nI];
  541. }
  542. else{
  543. $nBytes='';
  544. }
  545. array_push($arrBitmap,$nBytes);
  546. }
  547. }
  548. for($nI=0;$nI<8;$nI++){
  549. $nA=substr('012345',mt_rand(0,2),1).substr('012345',mt_rand(0,5),1);
  550. array_unshift($arrBitmap,$nA);
  551. array_push($arrBitmap,$nA);
  552. }
  553. $sImage=pack('H*','424d9e000000000000003e000000280000002000000018000000010001000000'.'0000600000000000000000000000000000000000000000000000FFFFFF00'.implode('',$arrBitmap));
  554. header('Content-Type: image/bmp');
  555. echo $sImage;
  556. }
  557. }