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

ECMSPLUS | 2020-11-04 |

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

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

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

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

<?phpMs8ECMSPLUS
define('InEmpireCMSGd',TRUE);Ms8ECMSPLUS

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

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

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

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

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

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

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

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

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

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

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

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

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

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

如下示例代码:

<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>

免责/版权声明:

本篇文章给大家谈谈[7.X版] 帝国cms常见问题:缩略图函数改进(GD库改进)以及帝国cms对应的知识,感谢你花时间阅读本站内容,希望对各位有所帮助,你也可以查看更多关于帝国cms的信息。

1、所有来源标注为 ECMSPLUS/zwcms.com的内容版权均为本站所有,若您需要引用、转载,只需要注明来源及原文链接即可,如涉及大面积转载,请来信告知,获取授权。

2、本站所提供的文章资讯、软件资源、素材源码等内容均为作者提供、网友推荐、互联网整理而来(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考,如有侵犯您的版权,请联系我们,本站将在三个工作日内改正。

3、若您的网站或机构从本站获取的一切资源进行商业使用,除来源为本站的资料需与本站协商外,其他资源请自行联系版权所有人。

4、 ECMSPLUS/zwcms.com不保证资源的准确性、安全性和完整性,请您在阅读、下载及使用过程中自行确认,本站亦不承担上述资源对您或您的网站造成的任何形式的损失或伤害

5、未经 ECMSPLUS/zwcms.com允许,不得盗链、盗用本站资源;不得复制或仿造本网站,不得在非 ECMSPLUS/zwcms.com所属的服务器上建立镜像, ECMSPLUS/zwcms.com对其自行开发的或和他人共同开发的所有内容、技术手段和服务拥有全部知识产权,任何人不得侵害或破坏,也不得擅自使用。

6、互联网的本质是自由与分享,我们真诚的希望,每一份有价值的正能量能够在互联网中自由传播,能够为每一个网站提供动力。

标签:
精品源码
  • 二维码种子溯源系统,一物一码防伪验证查询(单用户版) 支持定制开发

    惊爆价¥1500.00

    立即购买
    二维码种子溯源系统,一物一码防伪验证查询(单用户版) 支持定制开发
  • 帝国cms7.5精仿企业信息综合门户《莞商网》(原创)

    惊爆价¥1500.00

    立即购买
    帝国cms7.5精仿企业信息综合门户《莞商网》(原创)
  • 厂房网,厂房出租,厂房出售,仓库出租,园区招商商铺厂房网整站源码

    惊爆价¥1999.00

    立即购买
    厂房网,厂房出租,厂房出售,仓库出租,园区招商商铺厂房网整站源码
看点推荐
精选文章

站长交流群

互联网站长技术交流群
共同学习,共同进步,共同成长!

QQ交流群

推荐文章

EmpireCMS(帝国CMS) 最新版(v7.5)已知漏洞汇总

帝国第三方登陆:微信内部登陆+扫码登陆2.0安装说明与使用方法

帝国cms百度Webupload批量上传组件,支持前台投稿

帝国cms通过用灵动标签的SQL语句查询来调用栏目导航

帝国cms图片集字段morepic分割,自定义图片集显示

帝国cms 技巧整理笔记,持续更新中

帝国cms 技巧整理笔记:常用变量,COOKIE获取和系统模板

最新文章

热门标签

关注我们

微信扫一扫,关注更多精彩

  • 公众号
    全面掌握源码一手资讯

  • 服务号
    精彩活动,推送提醒

垂询热线:18680688182

商务合作:0769-8700 9090
文章投稿: