知行合一

discuz5.5水印(logo + 文字(英文/汉字任意选择)+发布者名字+时间

文章来自:discuz
我做了一些修改,在此对hnxxwyq表示感谢!
我说的是ttf字体,好多人都问坐标怎么确定,那么我告诉大家,$text_x,$text_y所表示的坐标定义了第一个字符的基本点,大概是字符的左下角坐标。(其中$text_y 坐标,它设定了字体基线的位置,不是字符的最底端。)
注意:以下修改只供discuz论坛的爱好者测试和研究,因为以下修改而出现的其他问题,本作者不负任何责任,因为牵涉到GBK汉字转utf编码,我测试没有出现问题,不保证不会出现其他问题,作者注!!
首先添加附件到include目录下,所用到的’simsun.ttc‘为宋体字体,请到c:\windows\fonts下面找到宋体,复制到include目录即可,太大了没有办法上传!

修改文件bbs/admin/settings.inc.php中的
showsetting(‘settings_watermarkstatus’, ”, ”, ‘<table cellspacing=”‘.INNERBORDERWIDTH.'” cellpadding=”‘.TABLESPACE.'” class=”tableborder” style=”margin-bottom: 3px; margin-top:3px;”><tr><td colspan=”3″><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”0″ ‘.$checkwm[0].’>’.$lang[‘settings_watermarkstatus_none’].'</td></tr><tr align=”center” class=”altbg2″><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”1″ ‘.$checkwm[1].’> #1</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”2″ ‘.$checkwm[2].’> #2</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”3″ ‘.$checkwm[3].’> #3</td></tr><tr align=”center” class=”altbg2″><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”4″ ‘.$checkwm[4].’> #4</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”5″ ‘.$checkwm[5].’> #5</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”6″ ‘.$checkwm[6].’> #6</td></tr><tr align=”center” class=”altbg2″><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”7″ ‘.$checkwm[7].’> #7</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”8″ ‘.$checkwm[8].’> #8</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”9″ ‘.$checkwm[9].’> #9</td></tr></table>’);
修改成:
showsetting(‘settings_watermarkstatus’, ”, ”, ‘<table cellspacing=”‘.INNERBORDERWIDTH.'” cellpadding=”‘.TABLESPACE.'” class=”tableborder” style=”margin-bottom: 3px; margin-top:3px;”><tr><td colspan=”3″><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”0″ ‘.$checkwm[0].’>’.$lang[‘settings_watermarkstatus_none’].'</td></tr><tr align=”center” class=”altbg2″><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”1″ ‘.$checkwm[1].’> #1</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”2″ ‘.$checkwm[2].’> #2</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”3″ ‘.$checkwm[3].’> #3</td></tr><tr align=”center” class=”altbg2″><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”4″ ‘.$checkwm[4].’> #4</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”5″ ‘.$checkwm[5].’> #5</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”6″ ‘.$checkwm[6].’> #6</td></tr><tr align=”center” class=”altbg2″><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”7″ ‘.$checkwm[7].’> #7</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”8″ ‘.$checkwm[8].’> #8</td><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”9″ ‘.$checkwm[9].’> #9</td></tr><tr><td><input class=”radio” type=”radio” name=”settingsnew[watermarkstatus]” value=”10″ ‘.$checkwm[10].’> #10</td></tr></table>’);
寻找bbs/include/post.func.php中找到
if(!defined(‘IN_DISCUZ’)) {
        exit(‘Access Denied’);
}

下面添加函数

//该函数是从网上找到,归原作者所有,我只是修改适合这里使用–独自流浪
function GBKToUnicode(&$String)
        {
          $UnicodeData=file(DISCUZ_ROOT.”./include/gbkunicode.data”);
                $ReturnString=””;
                $StringLength=strlen($String);
                $p=””;
                $q=””;
                for($i=0;$i<$StringLength;$i++){
                        if(($p=ord(substr($String,$i,1)))>128){
                                $q=ord(substr($String,++$i,1));
                                if ($p>254) {
                                    $ReturnString.=’&#’.hexdec(‘003f’).’;’;
                                }
                                elseif ($q<64||$q>254) {
                                    $ReturnString.=’&#’.hexdec(‘003f’).’;’;
                                }
                                else {
                                        $q=($q-64)*4;
                                        $ReturnString.=’&#’.hexdec(substr($UnicodeData[$p-128],$q,4)).’;’;
                                }
                        }
                        else {
                                if ($p==128) {
                                    $ReturnString.=’&#’.hexdec(’20ac’).’;’;
                                }
                                else {
                                        $ReturnString.=’&#’.$p.’;’;
                                }
                        }
                }
                return $ReturnString;
}

找到
imageAlphaBlending($watermark_logo, true);
imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
修改成

imageAlphaBlending($watermark_logo, true);
                                               
                                                if($watermarkstatus == 10) {
                                                       
                                                        //计算黑色的方框的参数
                                                        $bg_x1 = 0;
                                                        $bg_y1 = $img_h – $logo_h – 10;
                                                        $bg_x2 = $img_w;
                                                        $bg_y2 = $img_h;
                                                        $bg_color = imagecolorallocate($dst_photo, 0, 0, 0); //这里参数0-255,对应颜色R/G/B
                                                       
                                                        //在底部画黑色方框
                                                        imagefilledrectangle($dst_photo, $bg_x1, $bg_y1, $bg_x2, $bg_y2, $bg_color);
                                                       
                                                        //logo位置
                                                        imageCopyMerge($dst_photo, $watermark_logo, $bg_x1 + 10,        $bg_y1 + 5, 0, 0, $logo_w, $logo_h, $watermarktrans);
                                                       
                                                        global $discuz_user;
                                                       
                                                        //文字内容,暂时支持英文,可以把独自流浪内容改了                                                                                       
                                                        $text = “(C) 2001-2006, 独自流浪 Inc. 版权归 $discuz_user 所有 “.date(‘y年n月j日-H点m分’, time());                                                       
                                                        $font = ‘simsun.ttc’;        //字体参数
                                                        $text_h = 11;         //文字高度
                                                        $text_x = round(($img_w – ($logo_w + 20 )) / 2) + ($logo_w + 20) – round(($text_h * strlen($text)) / 2);
                                                        $text_y = round(($bg_y2 – $bg_y1 – $text_h) / 2) + $bg_y1;       
                                                        $text_color = imagecolorallocate($dst_photo, 0xff, 0xff, 0xff);                //0xff是255的十六进制,你也可以直接用255,这里参数0-255,对应颜色R/G/B               
                                                        //imagestring($dst_photo, $font, $text_x, $text_y, $text, $text_color);       
                                                        $text = GBKToUnicode($text);                                               
                                                        imagettftext($dst_photo, $text_h, 0, $text_x, $text_y, $text_color, $font, $text);

                                                       
                                                } else {                                               
                                                        imageCopyMerge($dst_photo, $watermark_logo, $x,        $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
                                                }附件为后台新加的#10
attachments/200705/1179762503_0.png
200705/1179762503_1.rar
演示地址:http://bbs.newsevo.com/viewthread.php?tid=57&extra=page%3D1
我的新论坛,大家有空去捧场啊,呵呵。
如果想修改成我这样,没有logo和黑背景需要把最后一步替换成我修改后的代码,具体修改了哪里请自己对照,我不懂php问了好几个人都不会,自己琢磨了半天搞定了,呵呵,代码有不贵干的地方希望别笑话我,能指点下更好。

imageAlphaBlending($watermark_logo, true);
                                               
                                                if($watermarkstatus == 10) {
                                                       
                                                        //计算黑色的方框的参数
                                                        $bg_x1 = 0;
                                                        $bg_y1 = $img_h – $logo_h – 10;
                                                        $bg_x2 = $img_w;
                                                        $bg_y2 = $img_h;
                                                        $bg_color = imagecolorallocate($dst_photo, 0, 0, 0); //这里参数0-255,对应颜色R/G/B
                                                       
                                                        //在底部画黑色方框
                                                        imagefilledrectangle($dst_photo, $bg_x1, $bg_y1, $bg_x2, $bg_y2);
                                                       
                                                        //logo位置
                                                        //imageCopyMerge($dst_photo, $watermark_logo, $bg_x1 + 10,        $bg_y1 + 5, 0, 0, $logo_w, $logo_h, $watermarktrans);
                                                       
                                                        global $discuz_user;
                                                       
                                                        //文字内容,暂时支持英文,可以把独自流浪内容改了                                                                                       
                                                        $text = “图片上传于NEWSEVO.COM”;                                                       
                                                        $font = ‘simsun.ttc’;        //字体参数
                                                        $text_h = 12;         //文字高度
                                                        $text_x = $img_w –  round(($text_h * strlen($text)) / 2) -50;
                                                        $text_y = $img_h – $text_h – 5;       
                                                        $text_color = imagecolorallocate($dst_photo, 0xff, 0xff, 0xff);                //0xff是255的十六进制,你也可以直接用255,这里参数0-255,对应颜色R/G/B               
                                                        //imagestring($dst_photo, $font, $text_x, $text_y, $text, $text_color);       
                                                        $text = GBKToUnicode($text);                                               
                                                        imagettftext($dst_photo, $text_h, 0, $text_x, $text_y, $text_color, $font, $text);

                                                       
                                                } else {                                               
                                                        imageCopyMerge($dst_photo, $watermark_logo, $x,        $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
                                                }

赞(0) 打赏
未经允许不得转载:嘟嘟鱼 » discuz5.5水印(logo + 文字(英文/汉字任意选择)+发布者名字+时间
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏