중국어 원형 도장을 구현하는 PHP 클래스

WBOY
풀어 주다: 2016-07-25 08:43:12
원래의
1090명이 탐색했습니다.
  1. /*
  2. * 중국 원형 인감 카테고리
  3. * @author lkk/lianq.net
  4. * @create on 10:03 2012-5-29
  5. * @example:
  6. * $seal = new CircleSeal('너와 나는 서서 동,서,북,남,중앙을 걷는다',75,6,24,0,0, 16,40);
  7. * $seal->doImg();
  8. */
  9. class CircleSeal {
  10. private $sealString; //문자 봉인
  11. private $strMaxLeng; //최대 문자 길이
  12. private $sealRadius; //씰 반경
  13. private $rimWidth; //테두리 두께
  14. private $innerRadius; //내부 원 반경
  15. //Pentagram 반경;
  16. private $startAngle; //오각형 기울기 각도
  17. private $backGround; //씰 색상
  18. private $centerDot; //원 중심 좌표
  19. //그래픽 리소스 핸들
  20. private $font; //지정된 글꼴
  21. private $width; //그림 너비
  22. private $points; /Pentagram 각 점의 좌표
  23. private $charRadius; //문자열 반경
  24. private $charAngle; //문자열 기울기 각도
  25. private $spacing; //문자 간격 각도
  26. //구성 메소드
  27. 공개 함수 __construct($str ='', $rad = 75, $rmwidth = 6, $strad = 24, $stang = 0, $crang = 0, $fsize = 16, $inrad =0){
  28. $this->sealString = 비어 있음($str) ? '봉인 테스트 문자열' : $str;
  29. $this->strMaxLeng = 12;
  30. $this->sealRadius = $rad;
  31. $this->rimWidth = $rmwidth;
  32. $this->startRadius = $strad;
  33. $this->startAngle = $stang;
  34. $this->charAngle = $ crang;
  35. $this->centerDot = array('x'=>$rad, 'y'=>$rad);
  36. $this->font = dirname(__FILE__) .'/ simkai.ttf';
  37. $this->fontSize = $fsize;
  38. $this->innerRadius = $inrad; //기본값 0, 아니요
  39. $this->spacing = 1;
  40. }
  41. //이미지 리소스 생성
  42. private function createImg(){
  43. $this->width = 2 * $this->sealRadius;
  44. $this-> height = 2 * $this->sealRadius;
  45. $this->img = imagecreate($this->width, $this->height);
  46. imagecolorresolvealpha($this->img, 255,255,255,127);
  47. $this->backGround = imagecolorallocate($this->img,255,0,0);
  48. }
  49. //인감 테두리 그리기
  50. 비공개 함수 drawRim(){
  51. for($i=0;$i<$this->rimWidth;$i ){
  52. imagearc($this->img,$this->centerDot['x' ] ,$this->centerDot['y'],$this->너비 - $i,$this->높이 - $i,0,360,$this->backGround);
  53. }
  54. }
  55. //내부 원 그리기
  56. 비공개 함수 drawInnerCircle(){
  57. imagearc($this->img,$this->centerDot['x'],$this- > centerDot['y'],2*$this->innerRadius,2*$this->innerRadius,0,360,$this->backGround);
  58. }
  59. //그리기 문자열
  60. 비공개 함수 drawString(){
  61. //인코딩 처리
  62. $charset = mb_Detect_encoding($this->sealString);
  63. if($charset != 'UTF-8'){
  64. $this->sealString = mb_convert_encoding($this->sealString, 'UTF-8', 'GBK');
  65. }
  66. //관련 측정
  67. $this- > charRadius = $this->sealRadius - $this->rimWidth - $this->fontSize; //문자열 반경
  68. $leng = mb_strlen($this->sealString,'utf8'); / 문자열 길이
  69. if($leng > $this->strMaxLeng) $leng = $this->strMaxLeng;
  70. $avgAngle = 360 / ($this->strMaxLeng) //평균 문자 수 기울기
  71. //문자열을 나누어 쓰기
  72. $words = array(); //문자 배열
  73. for($i=0;$i<$leng;$i ) {
  74. $words[] = mb_substr($this->sealString,$i,1,'utf8');
  75. $r = 630 $this->charAngle $avgAngle*($i - $leng /2) $ this->spacing*($i-1); //좌표 각도
  76. $R ​​​​= 720 - $this->charAngle $avgAngle*($leng-2*$i-1)/ 2 $ this->spacing*(1-$i); //문자 각도
  77. $x = $this->centerDot['x'] $this->charRadius * cos(deg2rad($r) ); //문자의 x 좌표
  78. $y = $this->centerDot['y'] $this->charRadius * sin(deg2rad($r)) //문자의 y 좌표
  79. imagettftext($this->img, $this->fontSize, $R, $x, $y, $this->backGround, $this->font, $words[$i]);
  80. }
  81. }
  82. //画五角星
  83. 비공개 함수 drawStart(){
  84. $ang_out = 18 $this->startAngle;
  85. $ang_in = 56 $this->startAngle;
  86. $rad_out = $this->startRadius;
  87. $rad_in = $rad_out * 0.382;
  88. for($i=0;$i<5;$i ){
  89. //五个顶点坐标
  90. $this->points[] = $rad_out * cos(2*M_PI/5*$i - deg2rad($ang_out)) $this->centerDot['x'];
  91. $this- >points[] = $rad_out * sin(2*M_PI/5*$i - deg2rad($ang_out)) $this->centerDot['y'];
  92. //内凹的点坐标
  93. $this->points[] = $rad_in * cos(2*M_PI/5*($i 1) - deg2rad($ang_in)) $this->centerDot['x'];
  94. $this->points[] = $rad_in * sin(2*M_PI/5*($i 1) - deg2rad($ang_in)) $this->centerDot['y'];
  95. }
  96. imagefilledpolygon($this->img, $this->points, 10, $this->backGround);
  97. }
  98. //输出
  99. 비공개 함수 outPut(){
  100. header('Content-type:image/png');
  101. imagepng($this->img);
  102. imagedestroy($this->img);
  103. }
  104. //외생성
  105. 공용 함수 doImg(){
  106. $this->createImg();
  107. $this->drawRim();
  108. $this->drawInnerCircle() ;
  109. $this->drawString();
  110. $this->drawStart();
  111. $this->outPut();
  112. }
  113. }
제조대码

PHP


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!