PHP implementation of the Chinese circular seal special effects

Source: Internet
Author: User
Tags cos count header sin

Whim, wrote a circular seal generator, the font of the arc rotation is quite time-consuming. Finally, the results are good, code archiving.

Method One:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 <?php * * Chinese round seal class * @author lkk/lianq.net * @create on 10:03 2012-5-29 * @example: * $seal = new Circleseal (' You and I he's got to take a stand and walk. North-South ", 75,6,24,0,0,16,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 circle radius private $startRadius; Pentagram radius private $startAngle; The oblique angle of the pentagram is private $backGround; Seal color private $centerDot; Center coordinates private $IMG; Graphic resource handle private $font; The specified font is private $fontSize; Specifies the font size private $width; Picture width private $height; Picture height private $points; Each 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 Picture resource Private Function createimg () {$this->width = 2 * $this->sealradius; $this->height = 2 * $this-& Gt;sealradius; $this->img = imagecreate ($this->width, $this->height); Imagecolorresolvealpha ($this->img,255,255,255,127); $this->background = imagecolorallocate ($this->img,255,0,0);  //Draw 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 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 = 360/($this->strmaxleng); Average character gradient  //Split and write 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 (Deg2rad ($r)); The x-coordinate of the character $y = $this->centerdot[' y '] + $this->charradius * sin (Deg2rad ($r)); Y-coordinate IMA for charactersGettftext ($this->img, $this->fontsize, $R, $x, $y, $this->background, $this->font, $words [$i]);  //Draw the 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 '];  //Concave point coordinates $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);  //outputs Private function output () {header (' content-type:image/png '); Imagepng ($this->img); Imagedestroy ($ THIS->IMG); }  //external generate public Function doimg () {$this->creatEimg (); $this->drawrim (); $this->drawinnercircle (); $this->drawstring (); $this->drawstart (); $this->output (); } }

Method Two:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15-16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 The <?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, 75,75,148-$i, 148-$i, 0,360, $red);   $stock = ' C:windowsfontssimkai.ttf '; $point = "★"; $size = 30; Imagettftext ($im, $size, 0,72-$size/2,72+ $size/2, $red, $stock, $point);   $a =75 $b =-75;//Center Point 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)) + $a; $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, $stock, $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)) + $a; $ 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 + $j +1-$i]); }   Header (' content-type:image/png '); Imagepng ($im);?>

The above is the entire contents of this article, I hope you can enjoy

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.