/****************
*
*$imgname 要加水印的图片名称
*$imgurl 要加水印的路劲
*$watestring 要加水印的字符串
*$wateimg 要加水印的图片
*$sltf_r,$sltf_l 缩略图的长和宽
*
* -------要是加汉字水印的话,请把字体也和文件放到一起
*
*水印不返回true 缩略图返回处理后图片的路劲
*
*****************/
function watemark($imgname,$imgurl,$watestring,$wateimg,$sltf_r,$sltf_l){
$iinfo=getimagesize($imgurl.$imgname);
$typei="";
switch ($iinfo[2])
{
case 1:
$simage =imagecreatefromgif($imgurl.$imgname);
$typei=".gif";
break;
case 2:
$simage =imagecreatefromjpeg($imgurl.$imgname);
$typei=".jpg";
break;
case 3:
$simage =imagecreatefrompng($imgurl.$imgname);
$typei=".png";
break;
case 6:
$simage =imagecreatefromwbmp($imgurl.$imgname);
$typei=".bmp";
break;
default:
die("不支持的文件类型");
exit;
}
if($watestring){ //加文字水印
$white=imagecolorallocate($simage,255,255,255);
$str=iconv("gbk","utf-8",$watestring);
imagettftext($simage,12,0,20,20,$white,'SIMKAI.TTF',$str);
}
if($wateimg){
$logo=getimagesize($wateimg);
switch ($logo[2])
{
case 1:
$logoimg =imagecreatefromgif($wateimg);
break;
case 2:
$logoimg =imagecreatefromjpeg($wateimg);
break;
case 3:
$logoimg =imagecreatefrompng($wateimg);
break;
case 6:
$logoimg =imagecreatefromwbmp($wateimg);
break;
default:
die("不支持的文件类型");
exit;
}
imagecopy($simage,$logoimg,10,10,0,0,$logo[0],$logo[1]);
}
if($sltf_r&&$sltf_l){
$new=imageCreateTrueColor($sltf_r,$sltf_l);
ImageCopyResized($new,$simage,0,0,0,0,$sltf_r,$sltf_l,$iinfo[0],$iinfo[1]);
switch ($iinfo[2])
{
case 1:
imagegif($new,$imgurl."index_".$imgname);
return $imgurl."index_".$imgname;
case 2:
imagejpeg($new,$imgurl."index_".$imgname);
return $imgurl."index_".$imgname;
case 3:
imagepng($new,$imgurl."index_".$imgname);
return $imgurl."index_".$imgname;
case 6:
imagewbmp($new,$imgurl."index_".$imgname);
return $imgurl."index_".$imgname;
default:
return false;
}
}
switch ($iinfo[2])
{
case 1:
imagegif($simage,$imgurl.$imgname);
return true;
case 2:
imagejpeg($simage,$imgurl.$imgname);
return true;
case 3:
imagepng($simage,$imgurl.$imgname);
return true;
case 6:
imagewbmp($simage,$imgurl.$imgname);
return true;
default:
return false;
}
return false;
}