修改文件:\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 结束 }
修改后的水印平铺效果