本帖最后由 adminadam 于 2009-8-10 01:13 编辑
期待高手完善
先看图片演示
1.修改文件bbs/admin/中的 settings.inc.php
查找- <td><input class="radio" type="radio" name="settingsnew[watermarkstatus]" value="9" '.$checkwm[9].'> #9</td>
复制代码 后面加- <td><input class="radio" type="radio" name="settingsnew[watermarkstatus]" value="10" '.$checkwm[10].'> #10</td>
复制代码 2.修改文件:/include/image.class.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;
- $bg_x2 = $img_w;
- $bg_y2 = $img_h + $logo_h + 8;
- $watermarked = @imagecreatetruecolor ($img_w, $img_h + $logo_h + 15);
- $bg_color = imagecolorallocate($dst_photo, 0, 0, 0); //这里参数0-255,对应颜色R/G/B
- //生成新图片
- imagecopymerge ( $watermarked, $dst_photo, 0, 0, 0, 0, $img_w, $img_h, 100);
-
- //在底部画黑色方框
- imagefilledrectangle($watermarked, $bg_x1, $bg_y1, $bg_x2, $bg_y2, $bg_color);
-
- //logo位置
- imageCopyMerge($watermarked, $watermark_logo, $bg_x1 + 10, $bg_y1 + 5, 0, 0, $logo_w, $logo_h, $watermarktrans);
-
- global $discuz_user;
-
- //文字内容
- $text = "本图片由 $discuz_user 上传到校内网www.xiaonei.com ".date('y年n月j日-H点m分', time());
- $font = './images/fonts/ch/simsun.ttf'; //字体参数
- $text_h = 10; //文字高度
- $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 + 13;
- $text_color = imagecolorallocate($watermarked, 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($watermarked, $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);
- }
- $dst_photo = $watermarked;
- //结束
复制代码 3.上传附件gbkunicode到include下
4.替换字体
所用到的simsun.ttc为宋体字体,请到本地电脑里面c:\windows\fonts下面找到宋体&新宋体,复制到/images/fonts/ch/即可;simsun.ttc重命名为的simsun.ttf
完成
说明- 如果你不想有logo图标的话,就用个1*1的gif图片去代替/images/common/watermark.gif
复制代码 |