如果对php的gd库比较熟悉,看懂这篇文章一点都不难了!
zwell图片上传程序
上传文件:
允许上传的文件类型为:=implode(', ',$uptypes)?>
> 程序开发频道 >> php >> 正文: 标题:php经典的给图片加水印程序(2)时间:2006-8-7 来源:酷网动力 浏览数:7次 $pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo 已经成功上传
文件名: .$destination_folder.$fname.
;
echo 宽度:.$image_size[0];
echo 长度:.$image_size[1];
echo
大小:.$file[size]. bytes;
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
$white=imagecolorallocate($nimage,255,255,255);
$black=imagecolorallocate($nimage,0,0,0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);
switch ($iinfo[2])
{
case 1:
$simage =imagecreatefromgif($destination);
break;
case 2:
$simage =imagecreatefromjpeg($destination);
break;
case 3:
$simage =imagecreatefrompng($destination);
break;
case 6:
$simage =imagecreatefromwbmp($destination);
break;
default:
die(不支持的文件类型;
exit;
}
imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);
switch($watertype)
{
case 1: //加水印字符串
imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
break;
case 2: //加水印图片
$simage1 =imagecreatefromgif(xplore.gif;
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);
break;
}
switch ($iinfo[2])
{
case 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination);
break;
case 2:
imagejpeg($nimage, $destination);
break;
case 3:
imagepng($nimage, $destination);
break;
case 6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
break;
}
//覆盖原上传文件
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==1)
{
echo
图片预览:
;
echo echo alt='\图片预览:\r文件名:.$destination.\r上传时间:\'>;
}
}
?>
最后我觉得有必要说一下给图片加水印的原理:
取得上传的文件信息,建立一个真彩色图象,分配颜色方案并且填充图像。
通过判断文件类型建立图形,然后把其复制到原建立的图形上,填充并建立rectangle,以备写入imagestring()或是原已经定好的图像
程序当中判断水印类型:一是字符串,另是增加一个图形对象在上面。