- /*
- * Chinese circular seals
- * @ Author lkk/lianq.net
- * @ Create on
- * @ Example:
- * $ Seal = new circleSeal ('You and I are standing in the Middle East, West, North and South ', 40 );
- * $ Seal-> 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; // star radius
- Private $ startAngle; // The angle of the pentagram tilt.
- 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; // image width
- Private $ height; // Image height
- Private $ points; // coordinates of each vertex of the pentagram
- 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; // The default value is 0. no
- $ This-> spacing = 1;
- }
- // Create image resources
- 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 );
- }
- // 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 incircle
- Private function drawInnerCircle (){
- Imagearc ($ this-> img, $ this-> centerDot ['x'], $ this-> centerDot ['Y'], 2 * $ this-> innerRadius, 2 x $ this-> innerRadius, 0,360, $ this-> backGround );
- }
- // Draw a string
- Private function drawString (){
- // Encoding
- $ Charset = mb_detect_encoding ($ this-> sealString );
- If ($ charset! = 'Utf-8 '){
- $ This-> sealString = mb_convert_encoding ($ this-> sealString, 'utf-8', 'gbk ');
- }
- // 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 = 360/($ this-> strMaxLeng); // average character skew
- // Split and write 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 (deg 2rad ($ r); // x coordinate of the character
- $ Y = $ this-> centerDot ['Y'] + $ this-> charRadius * sin (deg 2rad ($ r); // y coordinate of the character
- Imagettftext ($ this-> img, $ this-> fontSize, $ R, $ x, $ y, $ this-> backGround, $ this-> font, $ words [$ I]);
- }
- }
- // Draw a star
- 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 );
- }
- // Generate externally
- Public function doImg (){
- $ This-> createImg ();
- $ This-> drawRim ();
- $ This-> drawInnerCircle ();
- $ This-> drawString ();
- $ This-> drawStart ();
- $ This-> outPut ();
- }
- }
|