& Lt ;? Php ** circular Chinese seal class * @ authorlkklianq.net * @ createon10: 032012-5-29 * @ example: * $ sealnewcircleSeal (you and I are standing in the Middle East, West, North and South, 40); * $ seal-& gt; doImg ();
DoImg (); */class circleSeal {private $ sealString; // seal character private $ strMaxLeng; // maximum character length private $ sealRadius; // seal radius private $ rimWidth; // border thickness private $ innerRadius; // Inner radius private $ startRadius; // The radius private $ startAngle; // The angle private $ backGround; // seal color private $ centerDot; // center coordinate private $ img; // graphical resource handle private $ font; // The specified font private $ fontSize; // specify the font size private $ width; // the image width private $ height; // The Image height private $ points; // Private $ charRadius; // string radius private $ charAngle; // string skew angle private $ spacing; // character interval angle // Constructor public function _ construct ($ str = '', $ rad = 75, $ rmwidth = 6, $ strad = 24, $ stang = 0, $ crang = 0, $ fsize = 16, $ 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 value: 0, no $ this-> spacing = 1 ;} // create an image resource private function createImg () {$ this-> width = 2 * $ this-> s EalRadius; $ 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 );} // draw the 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-& gt; height-$ I, 0,360, $ this-& gt; backGrou Nd) ;}}// draw the 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 the 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 measurement $ 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 = 360/($ this-> strMaxLeng); // average character skew // Split and write the string $ 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 (deg 2rad ($ r )); // x coordinate of the character $ y = $ this-> centerDot ['Y'] + $ this-> charRadius * sin (deg 2rad ($ r )); // y coordinate imagettftext ($ this-> img, $ this-> fontSize, $ R, $ x, $ y, $ this-> backGround, $ this-> font, $ words [$ I]) ;}// draw a pentagram private function drawStart () {$ ang_out = 18 + $ this-> startAngle; $ ang_in = 56 + $ 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-deg 2rad ($ ang_out )) + $ this-> centerDot ['x']; $ this-> points [] = $ rad_out * sin (2 * M_PI/5 * $ I-deg 2rad ($ ang_out )) + $ this-> centerDot ['Y']; // inner concave coordinate $ this-> points [] = $ rad_in * cos (2 * M_PI/5 * ($ I + 1)-deg 2rad ($ ang_in )) + $ this-> centerDot ['x']; $ this-> points [] = $ rad_in * sin (2 * M_PI/5 * ($ I + 1) -deg 2rad ($ ang_in) + $ this-> centerDot ['Y'];} imagefilledpolygon ($ this-> img, $ this-> points, 10, $ this-> backGround);} // outPut private function outPut () {header ('content-type: image/png '); imagepng ($ this-> img ); imagedestroy ($ this-> img);} // public function doImg () {$ this-> createImg (); $ this-> drawRim (); $ this-> drawInnerCircle (); $ this-> drawString (); $ this-> drawStart (); $ this-> outPut ();}}