一个简单的图片水印的类
时间:2007-12-26
来源:互联网
代码:
<?php/************************************************/
/*功能:添加图片水印 */
/*作者:还珠楼主 */
/*Email:[email protected] */
class digital
{
public $water_w,$water_h;//水印的宽,高
public $des_w,$des_h;//目标图片的宽高
public $pos_x,$pos_y;//落点坐标
public $water_url;//水印URL
public $des_url;//目标URL
public $water_info;//水印的基本信息
public $des_info;//目标图片信息
public $des,$water;
function __construct($des_url,$water_url="images/dig3.png")
{
$this->water=imagecreatefrompng($water_url);
$this->des=imagecreatefromjpeg($des_url);
$this->water_info=$this->getXY($water_url);
$this->des_info=$this->getXY($des_url);
$this->water_w=$this->water_info[0];
$this->water_h=$this->water_info[1];
$this->des_w=$this->des_info[0];
$this->des_h=$this->des_info[1];
$this->pos_x=5;
$this->pos_y=5;
}
function getXY($img)
{
return getimagesize($img);
}
function addDigital($br=true,$bl=false,$tl=false,$tr=false,$mid=false)
{
/***************bootom-right**********/
if($br)
{
$this->pos_x=$this->des_w-$this->water_w;
$this->pos_y=$this->des_h-$this->water_h;
imagecopymerge($this->des,$this->water,$this->pos_x,$this->pos_y,0,0,$this->water_w,$this->water_h,100);
}
/************bottom-left****************/
if($bl)
{
$this->pos_y=$this->des_h-$this->water_h;
imagecopymerge($this->des,$this->water,0,$this->pos_y,0,0,$this->water_w,$this->water_h,100);
}
/**************top-left******************/
if($tl)
{
imagecopymerge($this->des,$this->water,0,0,0,0,$this->water_w,$this->water_h,100);
}
/******************top-right************/
if($tr)
{
$this->pos_x=$this->des_w-$this->water_w;
imagecopymerge($this->des,$this->water,$this->pos_x,0,0,0,$this->water_w,$this->water_h,100);
}
/********************middle************/
if($mid)
{
$this->pos_x=($this->des_w-$this->water_w)/2;
$this->pos_y=($this->des_h-$this->water_h)/2;
imagecopymerge($this->des,$this->water,$this->pos_x,$this->pos_y,0,0,$this->water_w,$this->water_h,100);
}
imagejpeg($this->des);
header("Content-type: image/jpeg");
}
}
?>
代码:
<?include_once("function/digital_class.php");
$dig=new digital("images/2.jpg");
$dig->addDigital(true,false,false,false,false);
?>
作者: dongxin1390008 发布时间: 2007-12-26
可以考虑加入算法在里面
imagecopymerge()函数只是覆盖,破坏了原图片的完整,无法还原图片及提取水印信息
期待楼主做出更强大的数字水印类来供大家使用
作者: lomatus 发布时间: 2007-12-26


作者: luzhou 发布时间: 2007-12-26
引用:
原帖由 luzhou 于 2007-12-26 19:08 发表应鼓励原创精品。


作者: lomatus 发布时间: 2007-12-27
引用:
原帖由 luzhou 于 2007-12-26 19:08 发表应鼓励原创精品。


作者: airwin 发布时间: 2007-12-27

支持一下
作者: 特蓝克斯 发布时间: 2007-12-27
引用:
原帖由 lomatus 于 2007-12-26 16:56 发表顶。。。。
可以考虑加入算法在里面
imagecopymerge()函数只是覆盖,破坏了原图片的完整,无法还原图片及提取水印信息
期待楼主做出更强大的数字水印类来供大家使用
作者: dongxin1390008 发布时间: 2007-12-28
不知道PHP是不是也可以做一个出来
作者: lomatus 发布时间: 2007-12-28


作者: strongability 发布时间: 2008-01-15
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28