文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP图片水印

PHP图片水印

时间:2008-04-22  来源:傲枭



  Normal
  0
  
  
  
  7.8 磅
  0
  2
  
  false
  false
  false
  
  EN-US
  ZH-CN
  X-NONE
  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
  
  MicrosoftInternetExplorer4
  
   
   
   
   
   
   
   
   
   
   
   
  

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

/* Style Definitions */
table.MsoNormalTable
        {mso-style-name:普通表格;
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-priority:99;
        mso-style-qformat:yes;
        mso-style-parent:"";
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.5pt;
        mso-bidi-font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-ascii-font-family:Calibri;
        mso-ascii-theme-font:minor-latin;
        mso-fareast-font-family:宋体;
        mso-fareast-theme-font:minor-fareast;
        mso-hansi-font-family:Calibri;
        mso-hansi-theme-font:minor-latin;
        mso-bidi-font-family:"Times New Roman";
        mso-bidi-theme-font:minor-bidi;
        mso-font-kerning:1.0pt;}
$uptypes=array('image/jpg','image/jpeg','image/pjpeg','image/gif');//上传图片文件类型列表
$wFile="a.jpg";//取得文件路径
$waterimg="hq.gif";//水印图片路径
if(in_array($wFile['type'], $uptypes))
{//检查文件类型,若上传的文件为jpg或gif图片则加水印
   if(strstr($wFile['type'],"jp")){ //若上传图片类型为jpg,pjpeg,jpeg,则用imagecreatefromjpeg读取目标文件
    $im = imageCreatefromjpeg($wFile);
$wfilew=imagesx($im);//取得图片的宽
$wfileh=imagesy($im);//取得图片的高
   }else{//否则若上传图片类型为gif,则用imagecreatefromgif读取目标文件
    $im = imageCreatefromgif($wFile);
$wfilew=imagesx($im);//取得图片的宽
$wfileh=imagesy($im);//取得图片的高
}
   //设定混合模式
    imagealphablending($im, true);
    //读取水印文件
    $im2 = imagecreatefromgif($waterimg);//若水印图片为jpg,则此去可改为$im2 =
imagecreatefromjpeg($waterimg)
$waterw=imagesx($im2);//取得水印图片的宽
$waterh=imagesy($im2);//取得水印图片的高
    //随机放水印到图片中
$randval = rand(0,9);//在0-9之间产生随机数
if($randval==0||$randval==3||$randval==2||$randval==8||$randval==7){//此处还可完善放更多位置
$wimgx=5;$wimgy=5;//放左上角
}else{
$wimgx=$wfilew-5-$waterw;$wimgy=$wfileh-5-$waterh;//放右上角
}
//拷贝水印到目标文件
imagecopy($im, $im2, $wimgx, $wimgy, 0, 0, $waterw,$waterh);
   
//输出图片
   if(strstr($wFile['type'],"jp")){ //同上
imagejpeg($im,$wFile);
}else{
imagegif($im,$wFile);
}
    imagedestroy($im);
    imagedestroy($im2);
}
/************************************************************
**********水印结束*******************************************
***********************************************************/
               
               
               

相关阅读 更多 +
排行榜 更多 +
西安交大通

西安交大通

生活实用 下载
长江云通

长江云通

生活实用 下载
translatez

translatez

生活实用 下载