27
Mar
2017

Discuz!让水印平铺的修改方法

修改文件:\source\class\class_image.PHP

修改原理:计算水印大小和图片大小,每次偏移一个水印的位置重复打水印;

由于discuz支持png和gif两种水印,因此本方法涉及两处修改:
修改1属于支持png水印,修改2属于支持gif水印;

修改1:大概第475行原始代码

if($this->param['watermarktype'][$type] == 'png') {

imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);

}

修改为

if($this->param['watermarktype'][$type] == 'png') {

//修改1 开始

//imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);

if(intval($this->imginfo['width']/$logo_w)>=3){

$wblank=($logo_w+$this->imginfo['width']%$logo_w)/intval($this->imginfo['width']/$logo_w);

$hblank=($logo_h+$this->imginfo['height']%$logo_h)/intval($this->imginfo['height']/$logo_h);

for($x = $wblank;$x+$logo_w<=$this->imginfo['width'];$x=$x+$logo_w+$wblank){

for($y = $hblank;$y+$logo_h<=$this->imginfo['height'];$y=$y+$logo_h+$hblank){

imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);

}

}

}else{

for($x = 5;$x+$logo_w<=$this->imginfo['width'];$x=$x+$logo_w+10){

for($y = 5;$y+$logo_h<=$this->imginfo['height'];$y=$y+$logo_h+10){

imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);

}

}

}

//修改1 结束

}

修改2:大概500行,原始代码为:

else {

imageAlphaBlending($watermark_logo, true);

imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->param['watermarktrans'][$type]);

}

修改为:

else {

imageAlphaBlending($watermark_logo, true);

//修改2 开始

if(intval($this->imginfo['width']/$logo_w)>=3){

$wblank=($logo_w+$this->imginfo['width']%$logo_w)/intval($this->imginfo['width']/$logo_w);

$hblank=($logo_h+$this->imginfo['height']%$logo_h)/intval($this->imginfo['height']/$logo_h);

for($x = $wblank;$x+$logo_w<=$this->imginfo['width'];$x=$x+$logo_w+$wblank){

for($y = $hblank;$y+$logo_h<=$this->imginfo['height'];$y=$y+$logo_h+$hblank){

imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->param['watermarktrans'][$type]);

}

}

}else{

for($x = 5;$x+$logo_w<=$this->imginfo['width'];$x=$x+$logo_w+10){

for($y = 5;$y+$logo_h<=$this->imginfo['height'];$y=$y+$logo_h+10){

imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->param['watermarktrans'][$type]);

}

}

}

//imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->param['watermarktrans'][$type]);

//修改2 结束

}

修改后的水印平铺效果

点击查看原图

上一篇:Discuz!修改CC攻击防御机制attackevasive,实现忽略指定ip段和搜索引擎不受影响 下一篇:Discuz!附件图片、头像图片、相册图片存储规则详解

评论列表:

发表评论: