国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

實現(xiàn)中文圓形印章的PHP類

php中文網(wǎng)
發(fā)布: 2016-07-25 08:43:12
原創(chuàng)
1193人瀏覽過
  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; //內(nèi)圓半徑
  15. private $startRadius; //五角星半徑
  16. private $startAngle; //五角星傾斜角度
  17. private $backGround; //印章顏色
  18. private $centerDot; //圓心坐標(biāo)
  19. private $img; //圖形資源句柄
  20. private $font; //指定的字體
  21. private $fontSize; //指定字體大小
  22. private $width; //圖片寬度
  23. private $height; //圖片高度
  24. private $points; //五角星各點坐標(biāo)
  25. private $charRadius; //字符串半徑
  26. private $charAngle; //字符串傾斜角度
  27. private $spacing; //字符間隔角度
  28. //構(gòu)造方法
  29. public function __construct($str ='', $rad = 75, $rmwidth = 6, $strad = 24, $stang = 0, $crang = 0, $fsize = 16, $inrad =0){
  30. $this->sealString = empty($str) ? '印章測試字符串' : $str;
  31. $this->strMaxLeng = 12;
  32. $this->sealRadius = $rad;
  33. $this->rimWidth = $rmwidth;
  34. $this->startRadius = $strad;
  35. $this->startAngle = $stang;
  36. $this->charAngle = $crang;
  37. $this->centerDot = array('x'=>$rad, 'y'=>$rad);
  38. $this->font = dirname(__FILE__) .'/simkai.ttf';
  39. $this->fontSize = $fsize;
  40. $this->innerRadius = $inrad; //默認(rèn)0,沒有
  41. $this->spacing = 1;
  42. }
  43. //創(chuàng)建圖片資源
  44. private function createImg(){
  45. $this->width = 2 * $this->sealRadius;
  46. $this->height = 2 * $this->sealRadius;
  47. $this->img = imagecreate($this->width, $this->height);
  48. imagecolorresolvealpha($this->img,255,255,255,127);
  49. $this->backGround = imagecolorallocate($this->img,255,0,0);
  50. }
  51. //畫印章邊框
  52. private function drawRim(){
  53. for($i=0;$irimWidth;$i++){
  54. imagearc($this->img,$this->centerDot['x'],$this->centerDot['y'],$this->width - $i,$this->height - $i,0,360,$this->backGround);
  55. }
  56. }
  57. //畫內(nèi)圓
  58. private function drawInnerCircle(){
  59. imagearc($this->img,$this->centerDot['x'],$this->centerDot['y'],2*$this->innerRadius,2*$this->innerRadius,0,360,$this->backGround);
  60. }
  61. //畫字符串
  62. private function drawString(){
  63. //編碼處理
  64. $charset = mb_detect_encoding($this->sealString);
  65. if($charset != 'UTF-8'){
  66. $this->sealString = mb_convert_encoding($this->sealString, 'UTF-8', 'GBK');
  67. }
  68. //相關(guān)計量
  69. $this->charRadius = $this->sealRadius - $this->rimWidth - $this->fontSize; //字符串半徑
  70. $leng = mb_strlen($this->sealString,'utf8'); //字符串長度
  71. if($leng > $this->strMaxLeng) $leng = $this->strMaxLeng;
  72. $avgAngle = 360 / ($this->strMaxLeng); //平均字符傾斜度
  73. //拆分并寫入字符串
  74. $words = array(); //字符數(shù)組
  75. for($i=0;$i $words[] = mb_substr($this->sealString,$i,1,'utf8');
  76. $r = 630 + $this->charAngle + $avgAngle*($i - $leng/2) + $this->spacing*($i-1); //坐標(biāo)角度
  77. $R = 720 - $this->charAngle + $avgAngle*($leng-2*$i-1)/2 + $this->spacing*(1-$i); //字符角度
  78. $x = $this->centerDot['x'] + $this->charRadius * cos(deg2rad($r)); //字符的x坐標(biāo)
  79. $y = $this->centerDot['y'] + $this->charRadius * sin(deg2rad($r)); //字符的y坐標(biāo)
  80. imagettftext($this->img, $this->fontSize, $R, $x, $y, $this->backGround, $this->font, $words[$i]);
  81. }
  82. }
  83. //畫五角星
  84. private function drawStart(){
  85. $ang_out = 18 + $this->startAngle;
  86. $ang_in = 56 + $this->startAngle;
  87. $rad_out = $this->startRadius;
  88. $rad_in = $rad_out * 0.382;
  89. for($i=0;$i //五個頂點坐標(biāo)
  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. //內(nèi)凹的點坐標(biāo)
  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. private function outPut(){
  100. header('Content-type:image/png');
  101. imagepng($this->img);
  102. imagedestroy($this->img);
  103. }
  104. //對外生成
  105. public function doImg(){
  106. $this->createImg();
  107. $this->drawRim();
  108. $this->drawInnerCircle();
  109. $this->drawString();
  110. $this->drawStart();
  111. $this->outPut();
  112. }
  113. }
復(fù)制代碼

PHP


PHP速學(xué)教程(入門到精通)
PHP速學(xué)教程(入門到精通)

PHP怎么學(xué)習(xí)?PHP怎么入門?PHP在哪學(xué)?PHP怎么學(xué)才快?不用擔(dān)心,這里為大家提供了PHP速學(xué)教程(入門到精通),有需要的小伙伴保存下載就能學(xué)習(xí)啦!

下載
來源:php中文網(wǎng)
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn
最新問題
開源免費商場系統(tǒng)廣告
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號