详情页

帝国cms前台投稿标题图片字段上传图片自动加上水印的方法

时间:2023年05月21日

编辑:佚名

 在e/class/userfun.php这个自定义函数文件中添加一个函数
function user_TranImgAuto($mid,$f,$isadd,$isq,$value,$cs){  
        global $empire,$dbtbpre,$public_r,$emod_r,$class_r,$tranpicturetype,$musername;  
        //$filetf=$f.'imgf';//变量名  
  $filetf=$f.'file';//变量名  
        if(!$_FILES[$filetf]['name'])  
        {  
                return '';  
        }  
        $classid=(int)$_POST['classid'];//栏目ID  
        $id=(int)$_POST['id'];//信息ID  
        $filepass=(int)$_POST['filepass'];  
        $filetype=GetFiletype($_FILES[$filetf]['name']);//文件类型  
        $pr=$empire->fetch1("select qaddtran,qaddtransize,qaddtranimgtype from {$dbtbpre}enewspublic limit 1");  
        if(!$pr['qaddtran'])  
        {  
                printerror("CloseQTranPic","",1);//系统关闭上传图片功能  
        }  
        if(!strstr($pr['qaddtranimgtype'],"|".$filetype."|"))  
        {  
                printerror("NotQTranFiletype","",1);//您上传的文件扩展名有误  
        }  
        if($_FILES[$filetf]['size']>$pr['qaddtransize']*1024)  
        {  
                printerror("TooBigQTranFile","",1);//您上传的文件大小超过系统限制  
        }  
        if(!strstr($tranpicturetype,','.$filetype.','))  
        {  
                printerror("NotQTranFiletype","",1);//您上传的文件扩展名有误  
        }  
        $tfr=DoTranFile($_FILES[$filetf]['tmp_name'],$_FILES[$filetf]['name'],$_FILES[$filetf]['type'],$_FILES[$filetf]['size'],$classid);  
        if($tfr['tran'])  
        {  
                //获取参数  
    $csr=explode(',',$cs);  
                $maxwidth=$csr[0];  
                $maxheight=$csr[1];  
    $datu=$csr[2];//是否保留原图判断  
    $suiyi=$csr[3];//是否加水印判断  
     include_once(ECMS_PATH.'e/class/gd.php');  
                $yname=$tfr['yname'];//大图完整地址  
                //加水印  
                /* 
                * 功能:图片加水印 (水印支持图片或文字) 
                * 参数: 
                *      $groundImage    背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式; 
                *      $waterPos        水印位置,有10种状态,0为随机位置; 
                *                        1为顶端居左,2为顶端居中,3为顶端居右; 
                *                        4为中部居左,5为中部居中,6为中部居右; 
                *                        7为底端居左,8为底端居中,9为底端居右; 
                *      $waterImage        图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式; 
                *      $waterText        文字水印,即把文字作为为水印,支持ASCII码,不支持中文; 
                *      $textFont        文字大小,值为1、2、3、4或5,默认为5; 
                *      $textColor        文字颜色,值为十六进制颜色值,默认为#FF0000(红色); 
                * 
                * 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG 
                *      $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。 
                *      当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。 
                *      加水印后的图片的文件名和 $groundImage 一样。 
                *      $w_pct  $w_quality 分别是图片质量,水印透明度 
                */              
                if($suiyi=="yes" and $datu=="yes"){  
         imageWaterMark($tfr[yname],5,"../data/mark/maskdef.gif","",5,"#FF0000","../data/mark/cour.ttf",100,100);//执行加水印  
    }  
                $name=$tfr['name'];//缩图完整地址  
                //生成缩图  
                $filer=ResizeImage($yname,$name,$maxwidth,$maxheight,$public_r['spickill']);     
                 if($datu=="no"){  
                     DelFiletext($yname);//删除大图  
    }  
                if($filer['file'])  
                {  
                        //写入数据库  
                        $type=1;  
                        $filetime=date("Y-m-d H:i:s");  
                        $filesize=@filesize($filer['file']);  
                        $filename=GetFilename(str_replace(ECMS_PATH,'',$filer['file']));  
                        $adduser='[Member]'.$musername;  
                        $infoid=$isadd==1?0:$id;  
                        //$empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,fpath) values('$filename','$filesize','$adduser','$tfr[filepath]','$filetime','$classid','[s]".addslashes(RepPostStr($_POST[title]))."','$type','$infoid','$filepass','$public_r[fpath]');");插入附件缩图  
      if($datu=="yes"){  
      $empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,fpath) values('$tfr[filename]','$filesize','$adduser','$tfr[filepath]','$filetime','$classid','".addslashes(RepPostStr($_POST[title]))."','$type','$infoid','$filepass','$public_r[fpath]');");//插入附件原图  
      }  
                }  
    //$value=str_replace($tfr['filename'],$filename,$tfr['url']);//返回缩图地址  
    $value=$tfr['url'];//返回原图地址  
        }  
        else  
        {  
                $value='';  
        }  
        return $value;  
}  
在titlepic中添加处理函数,如图所示:

具体字段处理函数添加说明如下:user_TranImgAuto##160,120,yes,yes
160 宽度
120 高度
no 代表删除大图保留缩图,同时下面第4个参数无效  yes 代表保留大图和小图
no 代表不加水印  yes 代表加水印
相关文章
猜你需要