/* * Chinese round seal type * @author lkk/lianq.net * @create on 10:03 2012-5-29 * @example: * $seal = new Circleseal (' You and me he sits East ', 75,6,24,0,0,16,40); * $seal->doimg (); */ Class Circleseal { Private $sealString; Stamp character Private $strMaxLeng; Maximum characters length Private $sealRadius; Seal radius Private $rimWidth; Border thickness Private $innerRadius; Radius of Inner Circle Private $startRadius; Pentagram radius Private $startAngle; Pentagram Tilt Angle Private $backGround; Seal color Private $centerDot; Center coordinates Private $img; Graphics resource Handle Private $font; The specified font Private $fontSize; Specify font size Private $width; Picture width Private $height; Picture height Private $points; Point coordinates of the pentagram Private $charRadius; String radius Private $charAngle; String Tilt angle Private $spacing; Character Interval angle Construction method Public function __construct ($str = ", $rad = $rmwidth = 6, $strad =, $stang = 0, $crang = 0, $fsize = +, $inrad =0 ){ $this->sealstring = Empty ($STR)? ' Seal test string ': $str; $this->strmaxleng = 12; $this->sealradius = $rad; $this->rimwidth = $rmwidth; $this->startradius = $strad; $this->startangle = $stang; $this->charangle = $crang; $this->centerdot = Array (' x ' = = $rad, ' y ' = = $rad); $this->font = dirname (__file__). ' /simkai.ttf '; $this->fontsize = $fsize; $this->innerradius = $inrad; Default 0, no $this->spacing = 1; } Create a picture resource Private Function createimg () { $this->width = 2 * $this->sealradius; $this->height = 2 * $this->sealradius; $this->img = imagecreate ($this->width, $this->height); Imagecolorresolvealpha ($this->img,255,255,255,127); $this->background = imagecolorallocate ($this->img,255,0,0); } Draw a seal border Private Function Drawrim () { for ($i =0; $i < $this->rimwidth; $i +) { Imagearc ($this->img, $this->centerdot[' x '], $this->centerdot[' y '], $this->width-$i, $this->height-$ i,0,360, $this->background); } } Draw Inner Circle Private Function drawinnercircle () { Imagearc ($this->img, $this->centerdot[' x '], $this->centerdot[' y '],2* $this->innerradius,2* $this innerradius,0,360, $this->background); } Draw a String Private Function drawstring () { Encoding processing $charset = mb_detect_encoding ($this->sealstring); if ($charset! = ' UTF-8 ') { $this->sealstring = mb_convert_encoding ($this->sealstring, ' UTF-8 ', ' GBK '); } Related metering $this->charradius = $this->sealradius-$this->rimwidth-$this->fontsize; String radius $leng = Mb_strlen ($this->sealstring, ' UTF8 '); String length if ($leng > $this->strmaxleng) $leng = $this->strmaxleng; $avgAngle =/($this->strmaxleng); Average character tilt Splitting and writing strings $words = Array (); Character array for ($i =0; $i < $leng; $i + +) { $words [] = Mb_substr ($this->sealstring, $i, 1, ' UTF8 '); $r = 630 + $this->charangle + $avgAngle * ($i-$leng/2) + $this->spacing* ($i-1); Coordinate angle $R = 720-$this->charangle + $avgAngle * ($leng -2* $i-1)/2 + $this->spacing* (1-$i); Character Angle $x = $this->centerdot[' x '] + $this->charradius * cos (Deg2rad ($r)); The x-coordinate of the character $y = $this->centerdot[' y ') + $this->charradius * sin (Deg2rad ($r)); The y-coordinate of the character Imagettftext ($this->img, $this->fontsize, $R, $x, $y, $this->background, $this->font, $words [$i]); } } Draw a Pentagram Private Function Drawstart () { $ang _out = + $this->startangle; $ang _in = + $this->startangle; $rad _out = $this->startradius; $rad _in = $rad _out * 0.382; for ($i =0; $i <5; $i + +) { Five vertex coordinates $this->points[] = $rad _out * cos (2*m_pi/5* $i-deg2rad ($ang _out)) + $this->centerdot[' x ']; $this->points[] = $rad _out * sin (2*m_pi/5* $i-deg2rad ($ang _out)) + $this->centerdot[' y ']; The point coordinates of the inner concave $this->points[] = $rad _in * cos (2*m_pi/5* ($i + 1)-Deg2rad ($ang _in)) + $this->centerdot[' x ']; $this->points[] = $rad _in * sin (2*m_pi/5* ($i + 1)-Deg2rad ($ang _in)) + $this->centerdot[' y ']; } Imagefilledpolygon ($this->img, $this->points, $this->background); } Output Private Function OutPut () { Header (' content-type:image/png '); Imagepng ($this->img); Imagedestroy ($this->img); } External generation Public Function doimg () { $this->createimg (); $this->drawrim (); $this->drawinnercircle (); $this->drawstring (); $this->drawstart (); $this->output (); } } |