热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

中文圆形印章类-PHP源码

中文圆形印章类
doImg();
 */

class circleSeal {
	private $sealString;	//印章字符
	private $strMaxLeng;	//最大字符长度
	private $sealRadius;	//印章半径
	private $rimWidth;		//边框厚度
	private $innerRadius;	//内圆半径
	private $startRadius;	//五角星半径
	private $startAngle;	//五角星倾斜角度
	private $backGround;	//印章颜色
	private $centerDot;		//圆心坐标
  	private $img;        	//图形资源句柄
  	private $font;        	//指定的字体
  	private $fontSize;    	//指定字体大小
	private $width;			//图片宽度
	private $height;		//图片高度
	private $points;		//五角星各点坐标
	private $charRadius;	//字符串半径
	private $charAngle;		//字符串倾斜角度
	private $spacing;		//字符间隔角度

	//构造方法
	public function __construct($str ='', $rad = 75, $rmwidth = 6, $strad = 24, $stang = 0, $crang = 0, $fsize = 16, $inrad =0){
		$this->sealString	= empty($str) ? '印章测试字符串' : $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;	//默认0,没有
		$this->spacing		= 1;
	}

	//创建图片资源
	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,0);
	}

	//画印章边框
	private function drawRim(){
		for($i=0;$irimWidth;$i++){
			imagearc($this->img,$this->centerDot['x'],$this->centerDot['y'],$this->width - $i,$this->height - $i,0,360,$this->backGround);
		}
	}

	//画内圆
	private function drawInnerCircle(){
		imagearc($this->img,$this->centerDot['x'],$this->centerDot['y'],2*$this->innerRadius,2*$this->innerRadius,0,360,$this->backGround);
	}

	//画字符串
	private function drawString(){
		//编码处理
		$charset = mb_detect_encoding($this->sealString);
		if($charset != 'UTF-8'){
			$this->sealString = mb_convert_encoding($this->sealString, 'UTF-8', 'GBK');
		}

		//相关计量
		$this->charRadius = $this->sealRadius - $this->rimWidth - $this->fontSize;	//字符串半径
		$leng	= mb_strlen($this->sealString,'utf8');	//字符串长度
		if($leng > $this->strMaxLeng) $leng = $this->strMaxLeng;
		$avgAngle	= 360 / ($this->strMaxLeng);	//平均字符倾斜度

		//拆分并写入字符串
		$words	= array();	//字符数组
		for($i=0;$isealString,$i,1,'utf8');
			$r = 630 + $this->charAngle + $avgAngle*($i - $leng/2) + $this->spacing*($i-1);		//坐标角度
			$R = 720 - $this->charAngle + $avgAngle*($leng-2*$i-1)/2 + $this->spacing*(1-$i);	//字符角度
			$x = $this->centerDot['x'] + $this->charRadius * cos(deg2rad($r));	//字符的x坐标
			$y = $this->centerDot['y'] + $this->charRadius * sin(deg2rad($r));	//字符的y坐标
			imagettftext($this->img, $this->fontSize, $R, $x, $y, $this->backGround, $this->font, $words[$i]);
		}
	}	

	//画五角星
	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;$ipoints[] = $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'];

			//内凹的点坐标
			$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, 10, $this->backGround);
	}

	//输出
	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();
	}
}

推荐阅读
  • vue使用
    关键词: ... [详细]
  • 一、Hadoop来历Hadoop的思想来源于Google在做搜索引擎的时候出现一个很大的问题就是这么多网页我如何才能以最快的速度来搜索到,由于这个问题Google发明 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • Python字典推导式及循环列表生成字典方法
    本文介绍了Python中使用字典推导式和循环列表生成字典的方法,包括通过循环列表生成相应的字典,并给出了执行结果。详细讲解了代码实现过程。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • “你永远都不知道明天和‘公司的意外’哪个先来。”疫情期间,这是我们最战战兢兢的心情。但是显然,有些人体会不了。这份行业数据,让笔者“柠檬” ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 生成对抗式网络GAN及其衍生CGAN、DCGAN、WGAN、LSGAN、BEGAN介绍
    一、GAN原理介绍学习GAN的第一篇论文当然由是IanGoodfellow于2014年发表的GenerativeAdversarialNetworks(论文下载链接arxiv:[h ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • 本文介绍了在Win10上安装WinPythonHadoop的详细步骤,包括安装Python环境、安装JDK8、安装pyspark、安装Hadoop和Spark、设置环境变量、下载winutils.exe等。同时提醒注意Hadoop版本与pyspark版本的一致性,并建议重启电脑以确保安装成功。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
author-avatar
倩女碧海蓝天_979
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有