当前位置: 网学 > 编程文档 > PHP > 正文

PHP 图片水印类代码

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/20
Img_info[0];
$this->y = 0;
break 1;
case 4: //中左
$this->x = 0;
$this->y = ($this->srcImg_info-$this->waterImg_info)/2;
break 1;
case 5: //中中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = ($this->srcImg_info-$this->waterImg_info)/2;
break 1;
case 6: //中右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = ($this->srcImg_info-$this->waterImg_info)/2;
break 1;
case 7: //下左
$this->x = 0;
$this->y = $this->srcImg_info-$this->waterImg_info;
break 1;
case 8: //下中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = $this->srcImg_info-$this->waterImg_info;
break 1;
default: //下右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = $this->srcImg_info-$this->waterImg_info;
break 1;
}
}
private function waterimg() {
if ($this->srcImg_info[0] <= $this->waterImg_info[0] || $this->srcImg_info <= $this->waterImg_info){
die(''水印比原图大!'');
}
$this->waterpos();
$cut = imagecreatetruecolor($this->waterImg_info[0],$this->waterImg_info);
imagecopy($cut,$this->im,0,0,$this->x,$this->y,$this->waterImg_info[0],$this->waterImg_info);
$pct = $this->transparent;
imagecopy($cut,$this->water_im,0,0,0,0,$this->waterImg_info[0],$this->waterImg_info);
imagecopymerge($this->im,$cut,$this->x,$this->y,0,0,$this->waterImg_info[0],$this->waterImg_info,$pct);
}
private function waterstr() {
$rect = imagettfbbox($this->fontSize,0,$this->fontFile,$this->waterStr);
$w = abs($rect-$rect);
$h = abs($rect-$rect);
$fontHeight = $this->fontSize;
$this->water_im = imagecreatetruecolor($w, $h);
imagealphablending($this->water_im,false);
imagesavealpha($this->water_im,true);
$white_alpha = imagecolorallocatealpha($this->water_im,255,255,255,127);
imagefill($this->water_im,0,0,$white_alpha);
$color = imagecolorallocate($this->water_im,$this->fontColor[0],$this->fontColor,$this->fontColor);
imagettftext($this->water_im,$this->fontSize,0,0,$this->fontSize,$color,$this->fontFile,$this->waterStr);
$this->waterImg_info = array(0=>$w,1=>$h);
$this->waterimg();
}
function output() {
$this->imginfo();
if ($this->waterType == 0) {
$this->waterstr();
}else {
$this->waterimginfo();
$this->waterimg();
}
switch ($this->srcImg_info) {
case 3:
imagepng($this->im,$this->srcImg);
break 1;
case 2:
imagejpeg($this->im,$this->srcImg);
break 1;
case 1:
imagegif($this->im,$this->srcImg);
break 1;
default:
die(''添加水印失败!'');
break;
}
imagedestroy($this->im);
imagedestroy($this->water_im);
}
}
?>

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号