PHP implements the special effect of Chinese circular seals. _ PHP Tutorial

Source: Internet
Author: User
PHP implements the special effect of Chinese circular seals ,. PHP implements the special effect of Chinese circular seals. Method 1: php ** Chinese circular seals * @ authorlkklianq.net * @ createon10: 032012-5-29 * @ example: * $ sealnewcircleSeal (you and I use PHP to implement the special effect of Chinese circular seals,

Method 1:

<? Php/** circular Chinese seal class * @ author lkk/lianq.net * @ create on 10:03 2012-5-29 * @ example: * $ seal = new circleSeal ('You and I are standing in the Middle East, West, and South north ', 75, 6, 24, 0, 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; // private $ startAngle; // private private $ backGround; // Seal color private $ centerDot; // center coordinate private $ img; // graphic 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; // The 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; // Default value: 0, no $ this-> spacing = 1 ;} // create an image 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);} // 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-> height-$ I, 0,360, $ this-> backGround) ;}// 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 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 ();}}

Method 2:

<? Php @ $ hos = iconv ("GBK", "UTF-8", $ _ GET ["hos"]); if (! Isset ($ hos) exit; $ im = ImageCreate (150,150); $ gray = ImageColorResolveAlpha ($ im, 200,200,200,127); $ red = ImageColorAllocate ($ im, 230,150,150 ); for ($ I = 0; $ I <6; $ I ++) ImageArc ($ im, 148, 148-$ I, 0,360-$ I, $ red ); $ stock = 'C: \ WINDOWS \ Fonts \ simkai. ttf'; $ point ="★"; $ Size = 30; ImageTTFText ($ im, $ size,-$ size/+ $ size/2, $ red, $ stock, $ point ); $ a = 75; $ B =-75; // center coordinate $ r = 65; $ m = 40; // radius, angle $ size = 16; // font size $ r = $ r-$ size; $ word = array (); $ max = 18; $ count = mb_strlen ($ hos, 'utf8 '); if ($ count> $ max) $ count = $ max; if ($ count> 12) $ m = floor (360/$ count); else if ($ count> 5) $ m-= $ count; for ($ I = 0; $ I <$ count; $ I ++) $ word [] = mb_substr ($ hos, $ I, 1, 'utf8'); $ j = floor ($ count/2); if ($ j! = $ Count/2) {for ($ I = $ j; $ I >=0; $ I --) {$ arc = $ m * ($ j-$ I) + $ size/2; $ x = round ($ r * cos (90 + $ arc) * M_PI/180) + $; $ y =-1 * (round ($ r * sin (90 + $ arc) * M_PI/180) + $ B); if ($ arc <10) $ arc = 0; ImageTTFText ($ im, $ size, $ arc, $ x, $ y, $ red, $ stock, $ word [$ I]); $ arc = $ m * ($ j-$ I)-$ size/2; $ x = round ($ r * cos (90-$ arc) * M_PI/180) + $ a; $ y =-1 * (round ($ r * sin (90-$ arc) * M_PI/180 )) + $ B); if ($ arc <10) $ arc = 0; ImageTTFText ($ im, $ size,-$ arc, $ x, $ y, $ red, $ stoc K, $ word [$ j + $ j-$ I]) ;}} else {$ j = $ J-1; for ($ I = $ j; $ I >=0; $ I --) {$ arc = $ m/2 + $ m * ($ j-$ I) + $ size/2; $ x = round ($ r * cos (90 + $ arc) * M_PI/180) + $; $ y =-1 * (round ($ r * sin (90 + $ arc) * M_PI/180) + $ B); ImageTTFText ($ im, $ size, $ arc, $ x, $ y, $ red, $ stock, $ word [$ I]); $ arc = $ m/2 + $ m * ($ j-$ I)-$ size/2; $ x = round ($ r * cos (90-$ arc) * M_PI/180) + $ a; $ y =-1 * (round ($ r * sin (90-$ arc) * M_PI/180 )) + $ B); ImageTTFText ($ im, $ size,-$ arc, $ x, $ y, $ red, $ stock, $ Word [$ j + 1-$ I]) ;}} header ('content-Type: image/png '); ImagePNG ($ im);?>

The above is all the content of this article. I hope you will like it.

Example, Method 1: php/** Chinese circular seal class * @ author lkk/lianq.net * @ create on 10:03 2012-5-29 * @ example: * $ seal = new circleSeal ('You and I sit here...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.