圖片水印完整版本. joey
http://coolvbb.info http://trueme.cn
感謝網友忘憂提供思路.
修改共2步.補充一步.
第一步:
打開functions_image.php 在最後加如下函數代碼:
//watermark images
function watermark_image($filepath,$id)
{
global $DB_site;
$wmark = "您的水印圖片路徑/圖片名稱.png";
$im = imagecreatefromjpeg($filepath);
imagealphablending($im, true);
$watermark = imagecreatefrompng($wmark);
$y = imagesy($im) - imagesy($watermark);
$w = imagesx($watermark);
$h = imagesy($watermark);
imagecopy($im, $watermark, 0, $y, 0, 0, $w, $h);
imagejpeg($im,$filepath ,100);
$filesize=filesize($filepath);
$DB_site->query("UPDATE " . TABLE_PREFIX . "attachment SET filesize='$filesize' WHERE attachmentid='$id'");
}
#########################################################
#####如果不想使用png圖片請使用如下函數(網友忘憂所寫)#####
#########################################################
//watermark images
function watermark_image($filepath,$id,$type)
{
global $DB_site;
$typ_img=getimagesize($filepath);
if( $typ_img[2] != 2 )
return '';
$font = "/u/home/bbs/images/simhei.ttf";
$font1 = "/u/home/bbs/images/arial.ttf";
$im = imagecreatefromjpeg($filepath);
imagealphablending($im, true);
$y = imagesy($im)-5;
$str_copyright=chr(0xE9).chr(0x9D).chr(0x92).chr(0xE6).chr(0xB5).chr(0xB7).c
hr(0xE7).chr(0xBB).chr(0xBC).chr(0xE5).chr(0x90).chr(0x88).chr(0xE4).chr(0xBF).c
hr(0xA1).chr(0xE6).chr(0x81).chr(0xAF).chr(0xE7).chr(0xBD).chr(0x91).chr(0x0D).c
hr(0x0D);
$white = ImageColorAllocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
imagettftext($im,11,0,15,$y+1,$red,$font,$str_copyright);
imagettftext($im,11,0,15,$y,$white,$font,$str_copyright);
imagettftext($im,11,0,130,$y+1,$red,$font1,"http://你的網站網址/");
imagettftext($im,11,0,130,$y,$white,$font1,"http://你的網站網址/");
imagejpeg($im,$filepath ,100);
$filesize=filesize($filepath);
switch($type)
{
case "thumb":
$SQL="UPDATE attachment SET thumbnail_filesize='$filesize' WHERE a
ttachmentid='$id'";
break;
case "attach":
$SQL="UPDATE attachment SET filesize='$filesize' WHERE attachmenti
d='$id'";
break;
}
$DB_site->query($SQL);
}
第2步:
打開functions_file.php
查找:
else if (!empty($thumbnail['filedata']))
{
// write out thumbnail now
$filename = fetch_attachment_path($posterid, $attachmentid, true);
$fp = fopen($filename, 'wb');
fwrite($fp, $thumbnail['filedata']);
fclose($fp);
unset($thumbnail);
後面加:
/* 水印 joey*/
if($extension=='jpg' or $extension=='jpeg' or $extension=='jpe')
{
watermark_image(fetch_attachment_path($posterid,$attachmentid),$attachmentid);
}
##############添加水印完成###########
######################################################################
如果你有現成的附件也想加上水印請按如下步奏再做處理:
打開admincp/misc.php
查找:
echo construct_phrase($vbphrase['processing_x'], "$vbphrase[attachment] : " .
construct_link_code($attachment['attachmentid'], "../attachment.php?$session[sessionurl]attachmentid=$attachment[attachmentid]", 1) . " ($vbphrase[post] : " .
construct_link_code($attachment['postid'], "../showthread.php?$session[sessionurl]postid=$attachment[postid]", 1) . " )") . ' ';
後面加上:
watermark_image(fetch_attachment_path($attachment['userid'],$attachment['attachmentid']),$attachment['attachmentid']);
echo"---本附件加水印完成---";
然後再重新建立縮略圖.
最後再刪去此改動,以免重複加水印.
※此Hack必須有GD的支援,請確定你的伺服器支援GD函式庫。