PHP production company Five chapters, round chop and oval chop, square seal

Source: Internet
Author: User
Tags chop cos sin

Are written dead, code duplication too much, no search for the oval text evenly distributed, math is not good, there is a big God can calculate a bit.

function Signtest () {
$name = "Beijing Aspen Four Major limited liability company";
$path = $_server["Document_root"]. '/data/sign/'. Date ("Y"). "/" . Date ("M"). "/". Date ("D"). "/";
mkdir ($path, 0755,true);
$filename = Uniqid ();
$picpath = $path. $filename;
Vendor (' signcom ');
$CC = new \circleseal ($name);
$sealname = ";
for ($i =1; $i <4; $i + +) {
if ($i ==2) {
$sealname = ' Financial Special chapter ';
}elseif ($i ==3) {
$sealname = ' Special seal of contract ';
}
$CC->saveimg ($picpath. ". $i. jpg ", $sealname);
}
$CC->saveell ($picpath. ". 4.jpg ", ' Invoice exclusive chapter ');
$CC->savesquare ($picpath. ". 5.jpg ", ' Wang Li ');
}

<?php
/*
* 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 $numRadius; Digital radius
Private $charAngle; String Tilt angle
Private $spacing; Character Interval angle
Private $sealNum; Digital
Private $sealName; Chapter Name
Private $yheight; The y-coordinate of the character;



Construction method
Public function __construct ($str = ", $num =", $rad = 0, $rmwidth = 6, $strad = 16, $stang = 0, $crang =, $fsize =, $inrad =0) {
$this->sealstring = Empty ($STR)? ' Seal test string ': $str;
$this->sealnum = Empty ($num)? ' 010101010 ': $num;
$this->strmaxleng = 18;
$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__). ' /simhei.ttf ';
$this->fontsize = $fsize;
$this->innerradius = $inrad; Default 0, no
$this->spacing = 1;
$this->width = 2 * $this->sealradius;
$this->height = 2 * $this->sealradius;
$this->yheight = 150; The y-coordinate of the character
}

Create a picture resource
Private Function createimg () {
$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 a seal border
Private Function Drawsqu () {
for ($i =0; $i < $this->rimwidth; $i +) {
Imagerectangle ($this->img,0+ $i, 0+ $i, 120-$i, 120-$i, $this->background);
}
}
Draw the name of a square
Private Function drawName1 () {
Encoding processing
$charset = mb_detect_encoding ($this->sealname);
if ($charset! = ' UTF-8 ') {
$this->sealname = mb_convert_encoding ($this->sealname, ' UTF-8 ', ' GBK ');
}
Related metering
$leng = Mb_strlen ($this->sealname, ' UTF8 '); String length
if ($leng = = 2 | | $leng = = 3) {
$this->sealname. = ' printing ';
}
$nums = Array ();
Splitting and writing strings
for ($i =0; $i < $leng +1; $i + +) {
$nums [] = Mb_substr ($this->sealname, $i, 1, ' UTF8 ');
}
Imagettftext ($this->img,38, 0, 60,50, $this->background, $this->font, $nums [0]);
Imagettftext ($this->img,38, 0, 60,110, $this->background, $this->font, $nums [1]);
Imagettftext ($this->img,38, 0, 10,50, $this->background, $this->font, $nums [2]);
Imagettftext ($this->img,38, 0, 10,110, $this->background, $this->font, $nums [3]);
}


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 the numbers below
Private Function Drawnum () {
Encoding processing
$charset = mb_detect_encoding ($this->sealnum);
if ($charset! = ' UTF-8 ') {
$this->sealnum = mb_convert_encoding ($this->sealnum, ' UTF-8 ', ' GBK ');
}
Related metering
$this->numradius = $this->sealradius-$this->rimwidth-5; Digital radius
$leng = Mb_strlen ($this->sealnum, ' UTF8 '); String length
if ($leng > $this->strmaxleng) $leng = $this->strmaxleng;
$avgAngle = 80/9; Average character tilt

Splitting and writing strings
$nums = Array (); Character array
for ($i =0; $i < $leng; $i + +) {
$nums [] = Mb_substr ($this->sealnum, $i, 1, ' UTF8 ');
$r =95 + $this->charangle + $avgAngle * ($i-$leng/2); Coordinate angle
$R = 720-$this->charangle + $avgAngle * ($leng -2* $i-1)/2; Character Angle
$x = $this->centerdot[' x '] + $this->numradius * cos (Deg2rad ($r)); The x-coordinate of the character
$y = $this->centerdot[' y ') + $this->numradius * sin (Deg2rad ($r)); The y-coordinate of the character
Imagettftext ($this->img,10, $R, $x, $y, $this->background, $this->font, $nums [$i]);
}
}

Draw the name of the Middle chapter
Private Function Drawname () {
Encoding processing
$charset = mb_detect_encoding ($this->sealname);
if ($charset! = ' UTF-8 ') {
$this->sealname = mb_convert_encoding ($this->sealname, ' UTF-8 ', ' GBK ');
}
Related metering
$leng = Mb_strlen ($this->sealname, ' UTF8 '); String length

Splitting and writing strings
$nums = Array (); Character array
for ($i =0; $i < $leng; $i + +) {
$nums [] = Mb_substr ($this->sealname, $i, 1, ' UTF8 ');
$r =99 + $this->charangle + $avgAngle * ($i-$leng/2); Coordinate angle
$R = 720-$this->charangle + $avgAngle * ($leng -2* $i-1)/2; Character Angle
$x = 44+ $i *22; The x-coordinate of the character
$y = $this->yheight; The y-coordinate of the character
Imagettftext ($this->img,18, 0, $x, $y, $this->background, $this->font, $nums [$i]);
}
}

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-5; 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); Coordinate angle
$R = 720-$this->charangle + $avgAngle * ($leng -2* $i-1)/2; 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 an oval string
Private Function drawString1 () {
Encoding processing
$charset = mb_detect_encoding ($this->sealstring);
if ($charset! = ' UTF-8 ') {
$this->sealstring = mb_convert_encoding ($this->sealstring, ' UTF-8 ', ' GBK ');
}

//Correlation metering
$charRadiusy = $this->centerdot[' y ')-$this->rimwidth-$this->fontsize;//String y
$ Charradiusx = $this->centerdot[' x ']-$this->rimwidth-$this->fontsize; string x
$leng = Mb_strlen ($this->sealstring, ' UTF8 ');//String length
if ($leng > $this->strmaxleng) $leng = $ this->strmaxleng;
$avgAngle = 270/$this->strmaxleng;//average character inclination
//Split and write string
$words = Array ();//character array
for ($i =0; $i < $len G; $i + +) {
$words [] = Mb_substr ($this->sealstring, $i, 1, ' UTF8 ');
$r = 630 + $this->charangle + $avgAngle * ($i- $leng/2); Coordinate angle
$R = 720-$this->charangle + $avgAngle * ($leng -2* $i-1)/2;//character angle
$x = $this->centerdot[' x ') + $charRa Diusx * cos (Deg2rad ($r)); The x-coordinate of the character
$y = $this->centerdot[' y '] + $charRadiusy * sin (Deg2rad ($r));//The y-coordinate of the character
Imagettftext ($this->img, $ This->fontsize, $R, $x, $y, $this->background, $this->font, $words [$i]);
}
}

Draw the numbers below
Private Function DrawNum1 () {
Encoding processing
$charset = mb_detect_encoding ($this->sealnum);
if ($charset! = ' UTF-8 ') {
$this->sealnum = mb_convert_encoding ($this->sealnum, ' UTF-8 ', ' GBK ');
}
Related metering
$charRadiusy = $this->centerdot[' y ')-$this->rimwidth-$this->fontsize+15; String y
$charRadiusx = $this->centerdot[' x ']-$this->rimwidth-$this->fontsize-2; String x
$leng = Mb_strlen ($this->sealnum, ' UTF8 '); String length
if ($leng > $this->strmaxleng) $leng = $this->strmaxleng;
$avgAngle = 80/9; Average character tilt

Splitting and writing strings
$nums = Array (); Character array
for ($i =0; $i < $leng; $i + +) {
$nums [] = Mb_substr ($this->sealnum, $i, 1, ' UTF8 ');
$r =97 + $this->charangle + $avgAngle * ($i-$leng/2); Coordinate angle
$R = 720-$this->charangle + $avgAngle * ($leng -2* $i-1)/2; Character Angle
$x = $this->centerdot[' x '] + $charRadiusx * cos (Deg2rad ($r)); The x-coordinate of the character
$y = $this->centerdot[' y ') + $charRadiusy * sin (Deg2rad ($r)); The y-coordinate of the character
Imagettftext ($this->img,10, $R, $x, $y, $this->background, $this->font, $nums [$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 saveimg ($path, $name = ") {
$this->sealname = $name;
$this->createimg ();
$this->drawrim ();
$this->drawinnercircle ();
$this->drawname ();
$this->drawnum ();
$this->drawstring ();
$this->drawstart ();
Imagepng ($this->img, $path);
Imagedestroy ($this->img);
}
Create ellipse
Public Function Saveell ($path, $name = ") {
$this->sealname = $name;
$this->width = 200;
$this->height = 147;
$this->yheight = 110;
$this->startradius = 20;
$this->fontsize = 16;
$this->sealradius = 75;
$this->points = Array ();
$this->centerdot = Array (' x ' = = $this->width/2, ' y ' = = $this-&GT;HEIGHT/2);
$this->createimg ();
$this->drawrim ();
$this->drawinnercircle ();
$this->drawname ();
$this->drawnum1 ();
$this->drawstring1 ();
$this->drawstart ();
Imagepng ($this->img, $path);
Imagedestroy ($this->img);
}
Generate Four Square
Public Function Savesquare ($path, $name = ") {
$this->sealname = $name;
$this->width = 120;
$this->height = 120;
$this->createimg ();
$this->drawsqu ();
$this->drawname1 ();
Imagepng ($this->img, $path);
Imagedestroy ($this->img);
}

External generation
Public Function doimg ($name = ") {
$this->sealname = $name;
$this->createimg ();
$this->drawrim ();
$this->drawinnercircle ();
$this->drawname ();
$this->drawnum ();
$this->drawstring ();
$this->drawstart ();
$this->output ();
}
}

PHP production company Five chapters, round chop and oval chop, square seal

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.