• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP图像操作类

php 搞代码 3年前 (2022-01-23) 18次浏览 已收录 0个评论

基于已给出的各种图像操作方法,这里我总结出了PHP图像操作的一个类,包括给图像添加文字水印、图像水印和压缩图片。读者可自行添加功能。

<?phpclass Image {	private $info;	private $type;	private $iamge;	/**	* 打开图片,写入内存	*	**/	public function __construct($src) 	{		$this->info = getimagesize($src);		$this->type = image_type_to_extension($this->info[2],false);		$fun = "imagecreatefrom".$this->type;		$this->image = $fun($src);	}	//缩略图	public function thumb($width, $height)	{		$image_thumb = imagecreatetruecolor($width, $height);		imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[0], $this->info[1]);		imagedestroy($this->image);		$this->image = $image_thumb;	}	//文字水印	public function fontMark($content, $fontUrl, $size, $color, $locate=array('x'=>0,'y'=>0), $angle=0)	{		$color = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]);		imagettftext($this->image, $size, $angle, $locate['x'], $locate['y'], $color, $fontUrl, $content);	}	//图片水印	public function imageMark($src,$locate,$alpha)	{		$info2 = getimagesize($src);		$type2 = image_type_to_extension($info2[2],false);		$fun2 = "imagecreatefrom".$type2;		$water = $fun2($src);		imagecopymerge($this->image, $water, $locate['x'], $locate['y'], 0, 0, $info2[0], $info2[1], $alpha);		imagedestroy($water);	}	//在浏览器中显示	public function show()	{		header("Content-type:".$this->info['mime']);		$fun = "image".$this->type;		$fun($this->i本文来源gaodai#ma#com搞*!代#%^码$网!搞代gaodaima码mage);	}	//保存为文件	public function save($newname)	{		$fun = "image".$this->type;		$fun($this->image, $newname.'.'.$this->type);	}	public function __destruct()	{		imagedestroy($this->image);	}}

版权声明:本文为博主原创文章,未经博主允许不得转载。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP图像操作类
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址