PHP图像操作类
发布时间:2020-05-25 07:41:41 所属栏目:PHP 来源:互联网
导读:PHP图像操作类
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 PHP图像操作的一个类,包括给图像添加文字水印、图像水印和压缩图片。 <?php
class 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,$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,$angle,$locate['x'],$locate['y'],$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,$info2[0],$info2[1],$alpha);
imagedestroy($water);
}
//在浏览器中显示
public function show()
{
header("Content-type:".$this->info['mime']);
$fun = "image".$this->type;
$fun($this->image);
}
//保存为文件
public function save($newname)
{
$fun = "image".$this->type;
$fun($this->image,$newname.'.'.$this->type);
}
public function __destruct()
{
imagedestroy($this->image);
}
}
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
