[7.X版] 帝国cms常见问题:缩略图函数改进(GD库改进)

帝国CMS缩略图函数改进(GD库改进)
本文关键字词:缩略图,缩略图函数,帝国CMS,帝国CMS,帝国CMS缩略图去黑边框

第一种方式 帝国默认:
sys_ResizeImg($r[titlepic],宽,高,0);//帝国默

帝国CMS(EmpireCMS)缩略图函数改进(GD库改进)xsEECMSPLUS
本文关键字词:缩略图,缩略图函数,帝国CMS(EmpireCMS),帝国CMS(EmpireCMS),帝国CMS(EmpireCMS)缩略图去黑边框xsEECMSPLUS
xsEECMSPLUS
第一种方式 帝国默认:xsEECMSPLUS
sys_ResizeImg($r[titlepic],宽,高,0);//帝国默认的不裁剪缩放生成缩略图的方式xsEECMSPLUS
xsEECMSPLUS
第二种方式 帝国默认:xsEECMSPLUS
sys_ResizeImg($r[titlepic],宽,高,1);//帝国默认的裁剪缩放生成缩略图的方式xsEECMSPLUS
xsEECMSPLUS
第三种方式 去掉裁剪不够时的黑边并且从图片缩放后中间裁剪:xsEECMSPLUS
sys_ResizeImg($r[titlepic],宽,高,2);//新加去黑边裁剪生成缩略图的方式xsEECMSPLUS
xsEECMSPLUS
第四种方式 只固定图片的宽,高度不限制(类似不规则瀑布流的图片形式),高填写为大于0的任意整数数字:xsEECMSPLUS
sys_ResizeImg($r[titlepic],宽,高,3);//新加去黑边生成类似瀑布流格式的方式xsEECMSPLUS

前台调用方式如下<?=sys_ResizeImg($r[titlepic],宽,高,3) ?>xsEECMSPLUS
xsEECMSPLUS
/e/class/gd.php 函数全部代码如下:xsEECMSPLUS

<?phpxsEECMSPLUS
define('InEmpireCMSGd',TRUE);xsEECMSPLUS

//原文件,新文件,宽度,高度,维持比例xsEECMSPLUS
function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){xsEECMSPLUS
        $returnr['file']='';xsEECMSPLUS
        $returnr['filetype']='';xsEECMSPLUS
        if($temp_img_type = @getimagesize($big_image_name)) {preg_match('//([a-z]+)$/i', $temp_img_type[mime], $tpn); $img_type = $tpn[1];xsEECMSPLUS
        }else{xsEECMSPLUS
                preg_match('/.([a-z]+)$/i', $big_image_name, $tpn); $img_type = $tpn[1];xsEECMSPLUS
        }xsEECMSPLUS
        $all_type = array(xsEECMSPLUS
                "jpg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),xsEECMSPLUS
                "gif" => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif" , "exn"=>".gif"),xsEECMSPLUS
                "jpeg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),xsEECMSPLUS
                "png" => array("create"=>"imagecreatefrompng" , "output"=>"imagepng" , "exn"=>".png"),xsEECMSPLUS
                "wbmp" => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")xsEECMSPLUS
        );xsEECMSPLUS

        $func_create = $all_type[$img_type]['create'];xsEECMSPLUS
        if(empty($func_create) or !function_exists($func_create)) {xsEECMSPLUS
                return $returnr;xsEECMSPLUS
        }xsEECMSPLUS
//输出xsEECMSPLUS
        $func_output = $all_type[$img_type]['output'];xsEECMSPLUS
        $func_exname = $all_type[$img_type]['exn'];xsEECMSPLUS
        if(($func_exname=='.gif'||$func_exname=='.png'||xsEECMSPLUS

$func_exname=='.wbmp')&&!function_exists($func_output)) {xsEECMSPLUS
                $func_output='imagejpeg';xsEECMSPLUS
                $func_exname='.jpg';xsEECMSPLUS
        }xsEECMSPLUS
        $big_image = $func_create($big_image_name);xsEECMSPLUS
        $big_width = imagesx($big_image);xsEECMSPLUS
        $big_height = imagesy($big_image);xsEECMSPLUS
        if($big_width <= $max_width and $big_height <= $max_height) {xsEECMSPLUS
                $func_output($big_image, $new_name.$func_exname);xsEECMSPLUS
                $returnr['file']=$new_name.$func_exname;xsEECMSPLUS
                $returnr['filetype']=$func_exname;xsEECMSPLUS
                return $returnr;xsEECMSPLUS
        }xsEECMSPLUS
        $ratiow = $max_width / $big_width;xsEECMSPLUS
        $ratioh = $max_height / $big_height;xsEECMSPLUS
        $new_width = ($ratiow > 1) ? $big_width : $max_width;xsEECMSPLUS
        $new_height = ($ratioh > 1) ? $big_height : $max_height;xsEECMSPLUS
        if($resize == 1) {xsEECMSPLUS
                if($big_width >= $max_width and $big_height >= $max_height) {xsEECMSPLUS
                        if($big_width > $big_height) {xsEECMSPLUS
                                $tempx = $max_width / $ratioh;xsEECMSPLUS
                                $tempy = $big_height;xsEECMSPLUS
                                $srcX = ($big_width - $tempx) / 2;xsEECMSPLUS
                                $srcY = 0;xsEECMSPLUS
                        } else {xsEECMSPLUS
                                $tempy = $max_height / $ratiow;xsEECMSPLUS
                                $tempx = $big_width;xsEECMSPLUS
                                $srcY = ($big_height - $tempy) / 2;xsEECMSPLUS
                                $srcX = 0;xsEECMSPLUS
                        }xsEECMSPLUS
                } else {xsEECMSPLUS
                        if($big_width > $big_height){xsEECMSPLUS
                                $tempx = $max_width;xsEECMSPLUS
                                $tempy = $big_height;xsEECMSPLUS
                                $srcX = ($big_width - $tempx) / 2;xsEECMSPLUS
                                $srcY = 0;xsEECMSPLUS
                        } else {xsEECMSPLUS
                                $tempy = $max_height;xsEECMSPLUS
                                $tempx = $big_width;xsEECMSPLUS
                                $srcY = ($big_height - $tempy) / 2;xsEECMSPLUS
                                $srcX = 0;xsEECMSPLUS
                        }xsEECMSPLUS
                }xsEECMSPLUS
        }elseif($resize == 2){//同比例缩放超出裁切xsEECMSPLUS

                if($big_width >= $max_width and $big_height >= $max_height){xsEECMSPLUS
                        if($max_width >= ($big_width * $ratioh)){xsEECMSPLUS
                                $tempx=$big_width;xsEECMSPLUS
                                $tempy=$max_height / $ratiow;xsEECMSPLUS
                                $srcX=0;xsEECMSPLUS
                                $srcY=($big_height - $tempy) / 2;xsEECMSPLUS
                        }elseif($max_height >= ( $big_height * $ratiow)){xsEECMSPLUS
                                $tempx=$max_width / $ratioh;xsEECMSPLUS
                                $tempy=$big_height;xsEECMSPLUS
                                $srcX=($big_width - $tempx) / 2;xsEECMSPLUS
                                $srcY=0;xsEECMSPLUS
                        }else{xsEECMSPLUS
                                $tempx=$max_width;xsEECMSPLUS
                                $tempy=$big_height;xsEECMSPLUS
                                $srcX=($big_width - $tempx) / 2;xsEECMSPLUS
                                $srcY=0;xsEECMSPLUS
                        }xsEECMSPLUS
                }else{xsEECMSPLUS
                        if($max_height >= $big_height){xsEECMSPLUS
                                $tempx=$max_width;xsEECMSPLUS
                                $tempy=$big_height;xsEECMSPLUS
                                $srcX=($big_width - $max_width) / 2;xsEECMSPLUS
                                $srcY=0;xsEECMSPLUS
                        }elseif($max_width >= $big_width){xsEECMSPLUS
                                $tempx=$big_width;xsEECMSPLUS
                                $tempy=$max_height;xsEECMSPLUS
                                $srcX=0;xsEECMSPLUS
                                $srcY=($big_height - $max_height) / 2;xsEECMSPLUS
                        }xsEECMSPLUS
                }xsEECMSPLUS
        }elseif($resize == 3){//宽度固定 高度同比例任意xsEECMSPLUS
                $srcX = 0;xsEECMSPLUS
                $srcY = 0;xsEECMSPLUS
                $tempx = $big_width;xsEECMSPLUS
                $tempy = $big_height;xsEECMSPLUS
                if($big_width >= $max_width){xsEECMSPLUS
                        $new_height=$big_height*$ratiow;xsEECMSPLUS
                }else{xsEECMSPLUS
                        $new_height=$big_height;xsEECMSPLUS
                }xsEECMSPLUS
        }else { //不保持比例xsEECMSPLUS
                $srcX = 0;xsEECMSPLUS
                $srcY = 0;xsEECMSPLUS
                $tempx = $big_width;xsEECMSPLUS
                $tempy = $big_height;xsEECMSPLUS
        }xsEECMSPLUS
        if(function_exists("imagecopyresampled")){xsEECMSPLUS
                $temp_image = imagecreatetruecolor($new_width, $new_height);xsEECMSPLUS
                //echo $tempx;exit;xsEECMSPLUS
                imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);xsEECMSPLUS
        } else {xsEECMSPLUS
                $temp_image = imagecreate($new_width, $new_height);xsEECMSPLUS
                imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);xsEECMSPLUS
        }xsEECMSPLUS
        /*增加高质量输出图像*/xsEECMSPLUS
        $zhiliang=$func_exname=='.png'?9:100;xsEECMSPLUS
        $func_output($temp_image, $new_name.$func_exname,$zhiliang);xsEECMSPLUS
//$func_output($temp_image, $new_name.$func_exname);xsEECMSPLUS
        ImageDestroy($big_image);xsEECMSPLUS
        ImageDestroy($temp_image);xsEECMSPLUS
        $returnr['file']=$new_name.$func_exname;xsEECMSPLUS
        $returnr['filetype']=$func_exname;xsEECMSPLUS
        return $returnr;xsEECMSPLUS
}xsEECMSPLUS

/*xsEECMSPLUS
* 功能:图片加水印 (水印支持图片或文字)xsEECMSPLUS
* 参数:xsEECMSPLUS
* $groundImage背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;xsEECMSPLUS
* $waterPos水印位置,有10种状态,0为随机位置;xsEECMSPLUS
*1为顶端居左,2为顶端居中,3为顶端居右;xsEECMSPLUS
*4为中部居左,5为中部居中,6为中部居右;xsEECMSPLUS
*7为底端居左,8为底端居中,9为底端居右;xsEECMSPLUS
* $waterImage图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;xsEECMSPLUS
* $waterText文字水印,即把文字作为为水印,支持ASCII码,不支持中文;xsEECMSPLUS
* $textFont文字大小,值为1、2、3、4或5,默认为5;xsEECMSPLUS
* $textColor文字颜色,值为十六进制颜色值,默认为#FF0000(红色);xsEECMSPLUS
*xsEECMSPLUS
* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNGxsEECMSPLUS
* $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。xsEECMSPLUS
* 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。xsEECMSPLUS
* 加水印后的图片的文件名和 $groundImage 一样。xsEECMSPLUS
*/xsEECMSPLUS
function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$textFont=5,$textColor="#FF0000",$myfontpath="../data/mask/cour.ttf",$w_pct,$w_quality){xsEECMSPLUS
        global $fun_r,$editor;xsEECMSPLUS
        if($editor==1){$a='../';}xsEECMSPLUS
        elseif($editor==2){$a='../../';}xsEECMSPLUS
        elseif($editor==3){$a='../../../';}xsEECMSPLUS
        else{$a='';}xsEECMSPLUS
        $waterImage=$waterImage?$a.$waterImage:'';xsEECMSPLUS
        $myfontpath=$myfontpath?$a.$myfontpath:'';xsEECMSPLUS
        $isWaterImage = FALSE;xsEECMSPLUS
        $formatMsg = $fun_r['synotdotype'];xsEECMSPLUS

//读取水印文件xsEECMSPLUS
        if(!empty($waterImage) && file_exists($waterImage)){xsEECMSPLUS
                $isWaterImage = TRUE;xsEECMSPLUS
                $water_info = getimagesize($waterImage);xsEECMSPLUS
                $water_w= $water_info[0];//取得水印图片的宽xsEECMSPLUS
                $water_h= $water_info[1];//取得水印图片的高xsEECMSPLUS

                switch($water_info[2]){//取得水印图片的格式xsEECMSPLUS
                        case 1:$water_im = imagecreatefromgif($waterImage);break;xsEECMSPLUS
                        case 2:$water_im = imagecreatefromjpeg($waterImage);break;xsEECMSPLUS
                        case 3:$water_im = imagecreatefrompng($waterImage);break;xsEECMSPLUS
                        default:echo $formatMsg;return "";xsEECMSPLUS
                }xsEECMSPLUS
        }xsEECMSPLUS

//读取背景图片xsEECMSPLUS
        if(!empty($groundImage) && file_exists($groundImage)) {xsEECMSPLUS
                $ground_info = getimagesize($groundImage);xsEECMSPLUS
                $ground_w= $ground_info[0];//取得背景图片的宽xsEECMSPLUS
                $ground_h= $ground_info[1];//取得背景图片的高xsEECMSPLUS

                switch($ground_info[2]){//取得背景图片的格式xsEECMSPLUS
                        case 1:$ground_im = imagecreatefromgif($groundImage);break;xsEECMSPLUS
                        case 2:$ground_im = imagecreatefromjpeg($groundImage);break;xsEECMSPLUS
                        case 3:$ground_im = imagecreatefrompng($groundImage);break;xsEECMSPLUS
                        default:echo $formatMsg;return "";xsEECMSPLUS
                }xsEECMSPLUS
        }else {xsEECMSPLUS
                echo $fun_r['synotdoimg'];xsEECMSPLUS
                return "";xsEECMSPLUS
        }xsEECMSPLUS

//水印位置xsEECMSPLUS
        if($isWaterImage){//图片水印xsEECMSPLUS
                $w = $water_w;xsEECMSPLUS
                $h = $water_h;xsEECMSPLUS
                $label = "图片的";xsEECMSPLUS
        }else{//文字水印xsEECMSPLUS
                $temp = imagettfbbox(ceil($textFont*2.5),0,$myfontpath,$waterText);//取得使用 TrueType 字体的文本的范围xsEECMSPLUS
                $w = $temp[2] - $temp[6];xsEECMSPLUS
                $h = $temp[3] - $temp[7];xsEECMSPLUS
                unset($temp);xsEECMSPLUS
                $label = "文字区域";xsEECMSPLUS
        }xsEECMSPLUS
        if( ($ground_w<$w) || ($ground_h<$h) ) {xsEECMSPLUS
                echo $fun_r['sytoosmall'];xsEECMSPLUS
                return '';xsEECMSPLUS
        }xsEECMSPLUS
        switch($waterPos) {xsEECMSPLUS
                case 0://随机xsEECMSPLUS
                        $posX = rand(0,($ground_w - $w));xsEECMSPLUS
                        $posY = rand(0,($ground_h - $h));xsEECMSPLUS
                        break;xsEECMSPLUS
                case 1://1为顶端居左xsEECMSPLUS
                        $posX = 0;xsEECMSPLUS
                        $posY = 0;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 2://2为顶端居中xsEECMSPLUS
                        $posX = ($ground_w - $w) / 2;xsEECMSPLUS
                        $posY = 0;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 3://3为顶端居右xsEECMSPLUS
                        $posX = $ground_w - $w;xsEECMSPLUS
                        $posY = 0;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 4://4为中部居左xsEECMSPLUS
                        $posX = 0;xsEECMSPLUS
                        $posY = ($ground_h - $h) / 2;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 5://5为中部居中xsEECMSPLUS
                        $posX = ($ground_w - $w) / 2;xsEECMSPLUS
                        $posY = ($ground_h - $h) / 2;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 6://6为中部居右xsEECMSPLUS
                        $posX = $ground_w - $w;xsEECMSPLUS
                        $posY = ($ground_h - $h) / 2;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 7://7为底端居左xsEECMSPLUS
                        $posX = 0;xsEECMSPLUS
                        $posY = $ground_h - $h;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 8://8为底端居中xsEECMSPLUS
                        $posX = ($ground_w - $w) / 2;xsEECMSPLUS
                        $posY = $ground_h - $h;xsEECMSPLUS
                        break;xsEECMSPLUS
                case 9://9为底端居右xsEECMSPLUS
                        $posX = $ground_w - $w;xsEECMSPLUS
                        $posY = $ground_h - $h;xsEECMSPLUS
                        break;xsEECMSPLUS
                default://随机xsEECMSPLUS
                        $posX = rand(0,($ground_w - $w));xsEECMSPLUS
                        $posY = rand(0,($ground_h - $h));xsEECMSPLUS
                        break;xsEECMSPLUS
        }xsEECMSPLUS

//设定图像的混色模式xsEECMSPLUS
        imagealphablending($ground_im, true);xsEECMSPLUS

        if($isWaterImage){//图片水印xsEECMSPLUS
                if($water_info[2]==3) {xsEECMSPLUS
                        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件xsEECMSPLUS
                }else {xsEECMSPLUS
                        imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h,$w_pct);//拷贝水印到目标文件xsEECMSPLUS
                }xsEECMSPLUS
        }else{//文字水印xsEECMSPLUS
                if( !empty($textColor) && (strlen($textColor)==7) ) {xsEECMSPLUS
                        $R = hexdec(substr($textColor,1,2));xsEECMSPLUS
                        $G = hexdec(substr($textColor,3,2));xsEECMSPLUS
                        $B = hexdec(substr($textColor,5));xsEECMSPLUS
                }else {xsEECMSPLUS
                        echo $fun_r['synotfontcolor'];xsEECMSPLUS
                        return "";xsEECMSPLUS
                }xsEECMSPLUS
                imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));xsEECMSPLUS
        }xsEECMSPLUS

//生成水印后的图片xsEECMSPLUS
        @unlink($groundImage);xsEECMSPLUS
        switch($ground_info[2]){//取得背景图片的格式xsEECMSPLUS
                case 1:imagegif($ground_im,$groundImage);break;xsEECMSPLUS
                case 2:imagejpeg($ground_im,$groundImage,$w_quality);break;xsEECMSPLUS
                case 3:imagepng($ground_im,$groundImage);break;xsEECMSPLUS
                default:echo $formatMsg;return "";xsEECMSPLUS
        }xsEECMSPLUS

//释放内存xsEECMSPLUS
        if(isset($water_info)) unset($water_info);xsEECMSPLUS
        if(isset($water_im)) imagedestroy($water_im);xsEECMSPLUS
        unset($ground_info);xsEECMSPLUS
        imagedestroy($ground_im);xsEECMSPLUS
}xsEECMSPLUS
?>xsEECMSPLUS

如下示例代码:

<p>&lt;?php<br />define(&#39;InEmpireCMSGd&#39;,TRUE);</p><p>//原文件,新文件,宽度,高度,维持比例<br />function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){<br />&nbsp; &nbsp; &nbsp; &nbsp; $returnr[&#39;file&#39;]=&#39;&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; $returnr[&#39;filetype&#39;]=&#39;&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; if($temp_img_type = @getimagesize($big_image_name)) {preg_match(&#39;//([a-z]+)$/i&#39;, $temp_img_type[mime], $tpn); $img_type = $tpn[1];<br />&nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; preg_match(&#39;/.([a-z]+)$/i&#39;, $big_image_name, $tpn); $img_type = $tpn[1];<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; $all_type = array(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;jpg&quot; =&gt; array(&quot;create&quot;=&gt;&quot;ImageCreateFromjpeg&quot;, &quot;output&quot;=&gt;&quot;imagejpeg&quot; , &quot;exn&quot;=&gt;&quot;.jpg&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;gif&quot; =&gt; array(&quot;create&quot;=&gt;&quot;ImageCreateFromGIF&quot; , &quot;output&quot;=&gt;&quot;imagegif&quot; , &quot;exn&quot;=&gt;&quot;.gif&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;jpeg&quot; =&gt; array(&quot;create&quot;=&gt;&quot;ImageCreateFromjpeg&quot;, &quot;output&quot;=&gt;&quot;imagejpeg&quot; , &quot;exn&quot;=&gt;&quot;.jpg&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;png&quot; =&gt; array(&quot;create&quot;=&gt;&quot;imagecreatefrompng&quot; , &quot;output&quot;=&gt;&quot;imagepng&quot; , &quot;exn&quot;=&gt;&quot;.png&quot;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;wbmp&quot; =&gt; array(&quot;create&quot;=&gt;&quot;imagecreatefromwbmp&quot;, &quot;output&quot;=&gt;&quot;image2wbmp&quot; , &quot;exn&quot;=&gt;&quot;.wbmp&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; );</p><p>&nbsp; &nbsp; &nbsp; &nbsp; $func_create = $all_type[$img_type][&#39;create&#39;];<br />&nbsp; &nbsp; &nbsp; &nbsp; if(empty($func_create) or !function_exists($func_create)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $returnr;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />//输出<br />&nbsp; &nbsp; &nbsp; &nbsp; $func_output = $all_type[$img_type][&#39;output&#39;];<br />&nbsp; &nbsp; &nbsp; &nbsp; $func_exname = $all_type[$img_type][&#39;exn&#39;];<br />&nbsp; &nbsp; &nbsp; &nbsp; if(($func_exname==&#39;.gif&#39;||$func_exname==&#39;.png&#39;||</p><p>$func_exname==&#39;.wbmp&#39;)&amp;&amp;!function_exists($func_output)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $func_output=&#39;imagejpeg&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $func_exname=&#39;.jpg&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; $big_image = $func_create($big_image_name);<br />&nbsp; &nbsp; &nbsp; &nbsp; $big_width = imagesx($big_image);<br />&nbsp; &nbsp; &nbsp; &nbsp; $big_height = imagesy($big_image);<br />&nbsp; &nbsp; &nbsp; &nbsp; if($big_width &lt;= $max_width and $big_height &lt;= $max_height) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $func_output($big_image, $new_name.$func_exname);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $returnr[&#39;file&#39;]=$new_name.$func_exname;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $returnr[&#39;filetype&#39;]=$func_exname;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $returnr;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; $ratiow = $max_width / $big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; $ratioh = $max_height / $big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; $new_width = ($ratiow &gt; 1) ? $big_width : $max_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; $new_height = ($ratioh &gt; 1) ? $big_height : $max_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; if($resize == 1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($big_width &gt;= $max_width and $big_height &gt;= $max_height) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($big_width &gt; $big_height) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx = $max_width / $ratioh;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy = $big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX = ($big_width - $tempx) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy = $max_height / $ratiow;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx = $big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY = ($big_height - $tempy) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($big_width &gt; $big_height){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx = $max_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy = $big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX = ($big_width - $tempx) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy = $max_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx = $big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY = ($big_height - $tempy) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }elseif($resize == 2){//同比例缩放超出裁切</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($big_width &gt;= $max_width and $big_height &gt;= $max_height){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($max_width &gt;= ($big_width * $ratioh)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx=$big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy=$max_height / $ratiow;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX=0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY=($big_height - $tempy) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }elseif($max_height &gt;= ( $big_height * $ratiow)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx=$max_width / $ratioh;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy=$big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX=($big_width - $tempx) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY=0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx=$max_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy=$big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX=($big_width - $tempx) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY=0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($max_height &gt;= $big_height){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx=$max_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy=$big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX=($big_width - $max_width) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY=0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }elseif($max_width &gt;= $big_width){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx=$big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy=$max_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX=0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY=($big_height - $max_height) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }elseif($resize == 3){//宽度固定 高度同比例任意<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx = $big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy = $big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($big_width &gt;= $max_width){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $new_height=$big_height*$ratiow;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $new_height=$big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }else { //不保持比例<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $srcY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempx = $big_width;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tempy = $big_height;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; if(function_exists(&quot;imagecopyresampled&quot;)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $temp_image = imagecreatetruecolor($new_width, $new_height);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //echo $tempx;exit;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);<br />&nbsp; &nbsp; &nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $temp_image = imagecreate($new_width, $new_height);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; /*增加高质量输出图像*/<br />&nbsp; &nbsp; &nbsp; &nbsp; $zhiliang=$func_exname==&#39;.png&#39;?9:100;<br />&nbsp; &nbsp; &nbsp; &nbsp; $func_output($temp_image, $new_name.$func_exname,$zhiliang);<br />//$func_output($temp_image, $new_name.$func_exname);<br />&nbsp; &nbsp; &nbsp; &nbsp; ImageDestroy($big_image);<br />&nbsp; &nbsp; &nbsp; &nbsp; ImageDestroy($temp_image);<br />&nbsp; &nbsp; &nbsp; &nbsp; $returnr[&#39;file&#39;]=$new_name.$func_exname;<br />&nbsp; &nbsp; &nbsp; &nbsp; $returnr[&#39;filetype&#39;]=$func_exname;<br />&nbsp; &nbsp; &nbsp; &nbsp; return $returnr;<br />}</p><p>/*<br />* 功能:图片加水印 (水印支持图片或文字)<br />* 参数:<br />* $groundImage背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;<br />* $waterPos水印位置,有10种状态,0为随机位置;<br />*1为顶端居左,2为顶端居中,3为顶端居右;<br />*4为中部居左,5为中部居中,6为中部居右;<br />*7为底端居左,8为底端居中,9为底端居右;<br />* $waterImage图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;<br />* $waterText文字水印,即把文字作为为水印,支持ASCII码,不支持中文;<br />* $textFont文字大小,值为1、2、3、4或5,默认为5;<br />* $textColor文字颜色,值为十六进制颜色值,默认为#FF0000(红色);<br />*<br />* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG<br />* $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。<br />* 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。<br />* 加水印后的图片的文件名和 $groundImage 一样。<br />*/<br />function imageWaterMark($groundImage,$waterPos=0,$waterImage=&quot;&quot;,$waterText=&quot;&quot;,$textFont=5,$textColor=&quot;#FF0000&quot;,$myfontpath=&quot;../data/mask/cour.ttf&quot;,$w_pct,$w_quality){<br />&nbsp; &nbsp; &nbsp; &nbsp; global $fun_r,$editor;<br />&nbsp; &nbsp; &nbsp; &nbsp; if($editor==1){$a=&#39;../&#39;;}<br />&nbsp; &nbsp; &nbsp; &nbsp; elseif($editor==2){$a=&#39;../../&#39;;}<br />&nbsp; &nbsp; &nbsp; &nbsp; elseif($editor==3){$a=&#39;../../../&#39;;}<br />&nbsp; &nbsp; &nbsp; &nbsp; else{$a=&#39;&#39;;}<br />&nbsp; &nbsp; &nbsp; &nbsp; $waterImage=$waterImage?$a.$waterImage:&#39;&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; $myfontpath=$myfontpath?$a.$myfontpath:&#39;&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; $isWaterImage = FALSE;<br />&nbsp; &nbsp; &nbsp; &nbsp; $formatMsg = $fun_r[&#39;synotdotype&#39;];</p><p>//读取水印文件<br />&nbsp; &nbsp; &nbsp; &nbsp; if(!empty($waterImage) &amp;&amp; file_exists($waterImage)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $isWaterImage = TRUE;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $water_info = getimagesize($waterImage);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $water_w= $water_info[0];//取得水印图片的宽<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $water_h= $water_info[1];//取得水印图片的高</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch($water_info[2]){//取得水印图片的格式<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:$water_im = imagecreatefromgif($waterImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:$water_im = imagecreatefromjpeg($waterImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:$water_im = imagecreatefrompng($waterImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:echo $formatMsg;return &quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>//读取背景图片<br />&nbsp; &nbsp; &nbsp; &nbsp; if(!empty($groundImage) &amp;&amp; file_exists($groundImage)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ground_info = getimagesize($groundImage);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ground_w= $ground_info[0];//取得背景图片的宽<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $ground_h= $ground_info[1];//取得背景图片的高</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch($ground_info[2]){//取得背景图片的格式<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:$ground_im = imagecreatefromgif($groundImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:$ground_im = imagecreatefromjpeg($groundImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:$ground_im = imagecreatefrompng($groundImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:echo $formatMsg;return &quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $fun_r[&#39;synotdoimg&#39;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>//水印位置<br />&nbsp; &nbsp; &nbsp; &nbsp; if($isWaterImage){//图片水印<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $w = $water_w;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $h = $water_h;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $label = &quot;图片的&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }else{//文字水印<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $temp = imagettfbbox(ceil($textFont*2.5),0,$myfontpath,$waterText);//取得使用 TrueType 字体的文本的范围<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $w = $temp[2] - $temp[6];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $h = $temp[3] - $temp[7];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unset($temp);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $label = &quot;文字区域&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; if( ($ground_w&lt;$w) || ($ground_h&lt;$h) ) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $fun_r[&#39;sytoosmall&#39;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &#39;&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; switch($waterPos) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 0://随机<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = rand(0,($ground_w - $w));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = rand(0,($ground_h - $h));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1://1为顶端居左<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2://2为顶端居中<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = ($ground_w - $w) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3://3为顶端居右<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = $ground_w - $w;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 4://4为中部居左<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = ($ground_h - $h) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 5://5为中部居中<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = ($ground_w - $w) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = ($ground_h - $h) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 6://6为中部居右<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = $ground_w - $w;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = ($ground_h - $h) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 7://7为底端居左<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h - $h;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 8://8为底端居中<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = ($ground_w - $w) / 2;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h - $h;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 9://9为底端居右<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = $ground_w - $w;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h - $h;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default://随机<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posX = rand(0,($ground_w - $w));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $posY = rand(0,($ground_h - $h));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>//设定图像的混色模式<br />&nbsp; &nbsp; &nbsp; &nbsp; imagealphablending($ground_im, true);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if($isWaterImage){//图片水印<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($water_info[2]==3) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h,$w_pct);//拷贝水印到目标文件<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }else{//文字水印<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( !empty($textColor) &amp;&amp; (strlen($textColor)==7) ) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $R = hexdec(substr($textColor,1,2));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $G = hexdec(substr($textColor,3,2));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $B = hexdec(substr($textColor,5));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $fun_r[&#39;synotfontcolor&#39;];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>//生成水印后的图片<br />&nbsp; &nbsp; &nbsp; &nbsp; @unlink($groundImage);<br />&nbsp; &nbsp; &nbsp; &nbsp; switch($ground_info[2]){//取得背景图片的格式<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:imagegif($ground_im,$groundImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:imagejpeg($ground_im,$groundImage,$w_quality);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:imagepng($ground_im,$groundImage);break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:echo $formatMsg;return &quot;&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>//释放内存<br />&nbsp; &nbsp; &nbsp; &nbsp; if(isset($water_info)) unset($water_info);<br />&nbsp; &nbsp; &nbsp; &nbsp; if(isset($water_im)) imagedestroy($water_im);<br />&nbsp; &nbsp; &nbsp; &nbsp; unset($ground_info);<br />&nbsp; &nbsp; &nbsp; &nbsp; imagedestroy($ground_im);<br />}<br />?&gt;</p>
分享到 :
相关推荐

发表评论

登录... 后才能评论

评论(3)

加入本站VIP会员订阅计划,海量资源免费下载查看

目前为止共有3位优秀的VIP会员加入!

立即加入VIP会员