php gd库 图片水印,<小田吃饺子> PHP:GD库 图片水印处理

/**

* 处理图片类

* 1.添加文字水印

* 2.添加图片水印

* 3.压缩图片

*/

class TL_Image{

private $image;//内存中的图片

private $info;//图片的基本信息

/**

* 打开一张图片,读取到内存

* @param [type] $src [description] 图片路径

*/

public function __construct($src){

$info = getimagesize($src);

$this->info = array(

‘width‘ => $info[0],

‘height‘ => $info[1],

‘type‘ => image_type_to_extension($info[‘2‘],false),

‘mime‘ => $info[‘mime‘],

);

$fun = "imagecreatefrom{$this->info[‘type‘]}";

$this->image = $fun($src);

}

/**

* 操作图片(压缩)

* @param [type] $width [description] 宽

* @param [type] $height [description] 高

* @return [type] [description]

*/

public function thumb($width,$height){

$image_thumb = imagecreatetruecolor($width,$height);

imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[‘width‘], $this->info[‘height‘]);

imagedestroy($this->image);

$this->image = $image_thumb;

}

/**

* 操作图片(添加文字水印)

* [fontMark description]

* @param [type] $content [description] 设置文字

* @param [type] $font_url [description] 字体文件路径

* @param [type] $size [description] 字体大小

* @param [type] $color [description] 字体颜色 []

* @param [type] $local [description] 位置 []

* @param [type] $angle [description] 旋转

* @return [type] [description]

*/

public function fontMark($content,$font_url,$size,$color,$local,$angle){

$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);

imagettftext($this->image, $size, $angle, $local[‘x‘], $local[‘y‘], $col, $font_url, $content);

}

/**

* 操作图片(添加图片水印)

* @param [type] $source [description] 水印图片路径

* @param [type] $local [description] 位置 []

* @param [type] $alpha [description] 透明

* @return [type] [description]

*/

public function imageMark($source,$local,$alpha){

$info2 = getimagesize($source);

$type2 = image_type_to_extension($info2[2],false);

$fun2 = "imagecreatefrom{$type2}";

$water = $fun2($source);

imagecopymerge($this->image, $water, $local[‘x‘], $local[‘y‘], 0, 0, $info2[0], $info2[1], $alpha);

imagedestroy($water);

}

/**

* 浏览器输出图片

*/

public function show(){

header("Content-Type:" . $this->info[‘mime‘]);

$funs = "image{$this->info[‘type‘]}";

$funs($this->image);

}

/**

* 保存图片

* @param [type] $newname [description] 保存之后的名字

* @return [type] [description]

*/

public function save($srcs){

$funs = "image{$this->info[‘type‘]}";

$funs($this->image,$srcs);

//move_uploaded_file($this->image, $srcs);

}

/**

* 销毁图片

*/

public function __destruct(){

imagedestroy($this->image);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值