// **************************************** // 
// 功能:给图片添加水印(支持中文)并生成缩略图 
// 参数: $srcFile 图片文件名 
// $dstFile 另存图片文件名 
// $words 水印文字内容 
// $image 水印图片地址 
// $dstW 图片保存宽度 
// $dstH 图片保存高度 
// $rate 图片保存品质 
// **************************************** // 
function makethumb($srcFile,$dstFile,$dstW,$dstH,$rate=100,$words=null,$image=null) 

$data = GetImageSize($srcFile); 
switch($data[2]) 

case 1: 
$im=@ImageCreateFromGIF($srcFile); 
break; 
case 2: 
$im=@ImageCreateFromJPEG($srcFile); 
break; 
case 3: 
$im=@ImageCreateFromPNG($srcFile); 
break; 

if(!$im) return False; 
$srcW=ImageSX($im); 
$srcH=ImageSY($im); 
$dstX=0; 
$dstY=0; 
if ($srcW*$dstH>$srcH*$dstW) 

$fdstH = round($srcH*$dstW/$srcW); 
$dstY = floor(($dstH-$fdstH)/2); 
$fdstW = $dstW; 

else 

$fdstW = round($srcW*$dstH/$srcH); 
$dstX = floor(($dstW-$fdstW)/2); 
$fdstH = $dstH; 

$ni=ImageCreateTrueColor($dstW,$dstH); 
$dstX=($dstX<0)?0:$dstX; 
$dstY=($dstX<0)?0:$dstY; 
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX; 
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY; 
$white = ImageColorAllocate($ni,255,255,255); 
$black = ImageColorAllocate($ni,0,0,0); 
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white);// 填充背景色 
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH); // 生成水印 
if($words!=null) 

$words=iconv("gb2312","UTF-8",$words); 
//转换文字编码 
ImageTTFText($ni,9,0,10,15,$white,"simhei.ttf",$words); 
//ImageTTFText(int im,int size,int angle,int x,int y,int col,string fontfile,string text): 
//本函数将 TTF (TrueType Fonts) 字型文字写入图片。 
//参数: size 为字形的尺寸; 
// angle 为字型的角度,顺时针计算,0 度为水平(由左到右),90 度则为由下到上的文字; 
// x,y 二参数为文字的坐标值 (原点为左上角); 
// col 为字的颜色; 
// fontfile 为字型文件名称; 
// text 是字符串内容。 

elseif($image!=null) 

$wimage_data = GetImageSize($image); 
switch($wimage_data[2]) 

case 1: 
$wimage=@ImageCreateFromGIF($image); 
break; 
case 2: 
$wimage=@ImageCreateFromJPEG($image); 
break; 
case 3: 
$wimage=@ImageCreateFromPNG($image); 
break; 

imagecopy($ni,$wimage,0,0,0,0,88,31); 
imagedestroy($wimage); 
} ImageJpeg($ni,$dstFile,$rate); 
imagedestroy($im); 
imagedestroy($ni); 
//结束图形,释放内存空间 
}