zenglcms v1.2.0增加了水印功能,支持纯文字水印和图片水印,水印类的代码来源自网络,作者简单修改,让其适应该CMS的环境。 在后台的图片水印相关配置中可以进行水印的相...
<?php /** * 加水印类,支持文字、图片水印以及对透明度的设置、水印图片背景透明。 * 代码来源自网络。。作者简单修改,让其适应该CMS的环境 */ class WaterMark { /** * 水印类型 * @var int $waterType 0为文字水印 ;1为图片水印 */ private $waterType; /** * 水印位置 类型 * @var int $pos 默认为9(右下角) */ private $pos; /** * 水印透明度 * @var int $transparent 水印透明度(值越小越透明) */ private $transparent; ...................................... //省略N行源码 /** * 加图片水印 */ private function waterimg() { if ($this->srcImg_info[0] <= $this->waterImg_info[0] || $this->srcImg_info[1] <= $this->waterImg_info[1]) { //$this->errorExit('图片尺寸太小,无法加水印,请上传一张大图片'); return 'watermark_bigthen_srcimg'; } //计算水印位置 $this->waterpos(); $cut = imagecreatetruecolor($this->waterImg_info[0], $this->waterImg_info[1]); imagecopy($cut, $this->im, 0, 0, $this->x, $this->y, $this->waterImg_info[0], $this->waterImg_info[1]); $pct = $this->transparent; imagecopy($cut, $this->water_im, 0, 0, 0, 0, $this->waterImg_info[0], $this->waterImg_info[1]); //将图片与水印图片合成 imagecopymerge($this->im, $cut, $this->x, $this->y, 0, 0, $this->waterImg_info[0], $this->waterImg_info[1], $pct); } /** * 加文字水印 */ private function waterstr() { $rect = imagettfbbox($this->fontSize, 0, $this->fontFile, $this->waterStr); $w = abs($rect[2] - $rect[6]); $h = abs($rect[3] - $rect[7]); $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); if(preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->config['watermark_fontcolor'], $color)) { $this->fontColor[0] = hexdec($color[1]); //red $this->fontColor[1] = hexdec($color[2]); //green $this->fontColor[2] = hexdec($color[3]); //blue } else { $this->fontColor = array(255,255,255); } $color = imagecolorallocate($this->water_im, $this->fontColor[0], $this->fontColor[1], $this->fontColor[2]); imagettftext($this->water_im, $this->fontSize, 0, 0, $this->fontSize, $color, $this->fontFile, $this->waterStr); $this->waterImg_info = array( 0 => $w, 1 => $h ); return $this->waterimg(); } /** * 水印图片输出 */ public function output() { if($this->config['watermark_switch'] == 'off') return ; $this->imginfo(); if ($this->waterType == 0) { if($this->waterstr()=='watermark_bigthen_srcimg') { return; } } else { $this->waterimginfo(); if($this->waterimg()=='watermark_bigthen_srcimg') { return; } } switch ($this->srcImg_info[2]) { case 3: imagepng($this->im, $this->srcImg); break ; case 2: imagejpeg($this->im, $this->srcImg); break ; case 1: imagegif($this->im, $this->srcImg); break ; default: $this->errorExit('源文件格式不对,必须是png,jpeg,gif格式,添加水印失败!'); break; } //图片合成后的后续销毁处理 imagedestroy($this->im); imagedestroy($this->water_im); } } ?> |
class progress { var $width; //进度条宽度像素值 var $pix; //进度条每执行一任务的需走的像素值 var $cur; //进度条当前游标 var $totaltask; //进度条总任务数 var $isBegin = false; //是否已经begin了 /* * 输出进度条的开头 * 参数$title 标题和初始进度名 * 参数$total 总共需要操作的记录数 * */ function begin($title,$total) { .......................................... //省略N行代码 } /* * 输出进度条 执行完一条任务,步进一格 * 参数$msg 进度条的消息 * */ function step($msg,$isNeedAddProgress = true) { .......................................... //省略N行代码 } /* * 输出进度条结束 * 参数$msg 进度条的消息*/ function end($msg,$isNeedAddLog = true) { .......................................... //省略N行代码 } /* * 重新设置进度条的总任务数 * 参数$total 总任务个数 * 参数isReset 是否重置游标 * */ function setNewTotalTask($total,$isReset = true) { .......................................... //省略N行代码 } } |