添加水印图片
给图片添加水印的颜色只能是RGBM吗
给图片添加水印的颜色只能是RGBM吗
2016-10-27
<?php
class Image {
/*图片的基本信息*/
private $info;
/*构造函数,打开图片,读取到内存中*/
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);
}
/*操作图片(压缩)*/
public function thumb($width,$height){
//1.在内存中建立一个真色彩图片
$image_thumb = imagecreatetruecolor($width,$height);
//2.核心步骤,将原图复制到新建的真色彩图片上,并且按照一定比例压缩
imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']);
//3.销毁原始图片
imagedestroy($this->image);
$this->image = $image_thumb;
}
/*操作图片(添加文字水印)*/
public function fontmark($content,$font_url,$size,$color,$local,$angle){
//设置字体的颜色和透明度,参数1 内存中的图片 2 red 3 gleen 4 bule 5 透明度
$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);
}
/*操作图片(添加图片水印)*/
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);
}
/*把图片保存到硬盘里*/
public function save($newname){
$funs = "image{$this->info['type']}";
$funs($this->image, $newname . "." . $this->info["type"]);
}
/*用析构函数销毁图片*/
public function __destruct(){
imagedestroy($this->image);
}
}
举报