当前位置:Gxlcms > PHP教程 > php图片上传并加水印的例子

php图片上传并加水印的例子

时间:2021-07-01 10:21:17 帮助过:14人阅读

有关php图片上传与php加水印的实例代码,一个完整的php上传图片的例子,需要的朋友参考下。

1、send.html

  
   
  File Uploader
    
   
   
  

File Upload

Select a file to upload:

2,接收 img_receive.php

  
已经成功上传
文件名: ".$destination_folder.$fname."
"; echo " 宽度:".$image_size[0]; echo " 长度:".$image_size[1]; echo "
大小:".$file["size"]." bytes"; if($watermark==1)//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 "\"图片预览:\r文件名:".$destination."\r上传时间:\""; } }

人气教程排行