我说的是ttf字体,好多人都问坐标怎么确定,那么我告诉大家,$text_x,$text_y所表示的坐标定义了第一个字符的基本点,大概是字符的左下角坐标。(其中$text_y 坐标,它设定了字体基线的位置,不是字符的最底端。)
看到好多人都需要一些特别的水印,就做了这个特别为5.0做的水印.
修改文件bbs/admin/setting中的
- 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中
- 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);
-
- //文字内容,暂时支持英文,可以把独自流浪内容改了
- $text = "(C) 2001-2006, duziliulang Inc.";
- $font = 4; //字体1-5
- $text_x = round(($img_w - ($logo_w + 20 )) / 2) + ($logo_w + 20) - round((@imagefontwidth($font) * strlen($text)) / 2);
- $text_y = round(($bg_y2 - $bg_y1 - (@imagefontheight($font))) / 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);
-
- } else {
- imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
- }
复制代码
看到好多人都要汉字支持,所以添加了汉字支持,注意:以下修改只供discuz论坛的爱好者测试和研究,因为以下修改而出现的其他问题,本作者不负任何责任,因为牵涉到GBK汉字转utf编码,我测试没有出现问题,不保证不会出现其他问题,作者注!!
汉字支持修改以下(第一步修改文件bbs/admin/setting和上面的一样)主要是修改post.func.php文件:
首先添加附件到include目录下,所用到的'simsun.ttc'为宋体字体,请到c:\windows\fonts下面找到宋体,复制到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;
- }
复制代码
寻找bbs/include/post.func.php中
- 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);
- }
复制代码
所用到的'simsun.ttc'为宋体字体,请到c:\windows\fonts下面找到宋体,复制到include即可,太大了没有办法上传!
效果如下:
[ 本帖最后由 hnxxwyq 于 2006-12-17 13:42 编辑 ] |