1. 好易之首页
  2. 咨询文档
  3. 技术文档

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!让水印平铺的修改方法

原创文章,作者:郑家喜,如若转载,请注明出处:https://www.zhengjiaxi.com/zxwd/jswd/65.html

发表评论

登录后才能评论

联系我们

400-800-8888

在线咨询:点击这里给我发消息

邮件:766103754@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注公众号