123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <?php
- define('InEmpireCMSGd',TRUE);
- function ResizeImage($big_image_name, $new_name, $max_width = 400, $max_height = 400, $resize = 1){
- $returnr['file']='';
- $returnr['filetype']='';
- if($temp_img_type = @getimagesize($big_image_name)) {preg_match('/\/([a-z]+)$/i', $temp_img_type[mime], $tpn); $img_type = $tpn[1];}
- else {preg_match('/\.([a-z]+)$/i', $big_image_name, $tpn); $img_type = $tpn[1];}
- $all_type = array(
- "jpg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),
- "gif" => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif" , "exn"=>".gif"),
- "jpeg" => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg" , "exn"=>".jpg"),
- "png" => array("create"=>"imagecreatefrompng" , "output"=>"imagepng" , "exn"=>".png"),
- "wbmp" => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
- );
- $func_create = $all_type[$img_type]['create'];
- if(empty($func_create) or !function_exists($func_create))
- {
- return $returnr;
- }
-
- $func_output = $all_type[$img_type]['output'];
- $func_exname = $all_type[$img_type]['exn'];
- if(($func_exname=='.gif'||$func_exname=='.png'||$func_exname=='.wbmp')&&!function_exists($func_output))
- {
- $func_output='imagejpeg';
- $func_exname='.jpg';
- }
- $big_image = $func_create($big_image_name);
- $big_width = imagesx($big_image);
- $big_height = imagesy($big_image);
- if($big_width <= $max_width and $big_height <= $max_height)
- {
- $func_output($big_image, $new_name.$func_exname);
- $returnr['file']=$new_name.$func_exname;
- $returnr['filetype']=$func_exname;
- return $returnr;
- }
- $ratiow = $max_width / $big_width;
- $ratioh = $max_height / $big_height;
- if($resize == 1) {
- if($big_width >= $max_width and $big_height >= $max_height)
- {
- if($big_width > $big_height)
- {
- $tempx = $max_width / $ratioh;
- $tempy = $big_height;
- $srcX = ($big_width - $tempx) / 2;
- $srcY = 0;
- } else {
- $tempy = $max_height / $ratiow;
- $tempx = $big_width;
- $srcY = ($big_height - $tempy) / 2;
- $srcX = 0;
- }
- } else {
- if($big_width > $big_height)
- {
- $tempx = $max_width;
- $tempy = $big_height;
- $srcX = ($big_width - $tempx) / 2;
- $srcY = 0;
- } else {
- $tempy = $max_height;
- $tempx = $big_width;
- $srcY = ($big_height - $tempy) / 2;
- $srcX = 0;
- }
- }
- } else {
- $srcX = 0;
- $srcY = 0;
- $tempx = $big_width;
- $tempy = $big_height;
- }
- $new_width = ($ratiow > 1) ? $big_width : $max_width;
- $new_height = ($ratioh > 1) ? $big_height : $max_height;
- if(function_exists("imagecopyresampled"))
- {
- $temp_image = imagecreatetruecolor($new_width, $new_height);
- imagecopyresampled($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);
- } else {
- $temp_image = imagecreate($new_width, $new_height);
- imagecopyresized($temp_image, $big_image, 0, 0, $srcX, $srcY, $new_width, $new_height, $tempx, $tempy);
- }
- $func_output($temp_image, $new_name.$func_exname);
- ImageDestroy($big_image);
- ImageDestroy($temp_image);
- $returnr['file']=$new_name.$func_exname;
- $returnr['filetype']=$func_exname;
- return $returnr;
- }
-
- function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$textFont=5,$textColor="#FF0000",$myfontpath="../data/mask/cour.ttf",$w_pct,$w_quality){
- global $fun_r,$editor;
- if($editor==1){$a='../';}
- elseif($editor==2){$a='../../';}
- elseif($editor==3){$a='../../../';}
- else{$a='';}
- $waterImage=$waterImage?$a.$waterImage:'';
- $myfontpath=$myfontpath?$a.$myfontpath:'';
- $isWaterImage = FALSE;
- $formatMsg = $fun_r['synotdotype'];
-
- if(!empty($waterImage) && file_exists($waterImage))
- {
- $isWaterImage = TRUE;
- $water_info = getimagesize($waterImage);
- $water_w = $water_info[0];
- $water_h = $water_info[1];
- switch($water_info[2])
- {
- case 1:$water_im = imagecreatefromgif($waterImage);break;
- case 2:$water_im = imagecreatefromjpeg($waterImage);break;
- case 3:$water_im = imagecreatefrompng($waterImage);break;
- default:echo $formatMsg;return "";
- }
- }
-
- if(!empty($groundImage) && file_exists($groundImage))
- {
- $ground_info = getimagesize($groundImage);
- $ground_w = $ground_info[0];
- $ground_h = $ground_info[1];
- switch($ground_info[2])
- {
- case 1:$ground_im = imagecreatefromgif($groundImage);break;
- case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
- case 3:$ground_im = imagecreatefrompng($groundImage);break;
- default:echo $formatMsg;return "";
- }
- }
- else
- {
- echo $fun_r['synotdoimg'];
- return "";
- }
-
- if($isWaterImage)
- {
- $w = $water_w;
- $h = $water_h;
- $label = "图片的";
- }
- else
- {
- $temp = imagettfbbox(ceil($textFont*2.5),0,$myfontpath,$waterText);
- $w = $temp[2] - $temp[6];
- $h = $temp[3] - $temp[7];
- unset($temp);
- $label = "文字区域";
- }
- if( ($ground_w<$w) || ($ground_h<$h) )
- {
- echo $fun_r['sytoosmall'];
- return '';
- }
- switch($waterPos)
- {
- case 0:
- $posX = rand(0,($ground_w - $w));
- $posY = rand(0,($ground_h - $h));
- break;
- case 1:
- $posX = 0;
- $posY = 0;
- break;
- case 2:
- $posX = ($ground_w - $w) / 2;
- $posY = 0;
- break;
- case 3:
- $posX = $ground_w - $w;
- $posY = 0;
- break;
- case 4:
- $posX = 0;
- $posY = ($ground_h - $h) / 2;
- break;
- case 5:
- $posX = ($ground_w - $w) / 2;
- $posY = ($ground_h - $h) / 2;
- break;
- case 6:
- $posX = $ground_w - $w;
- $posY = ($ground_h - $h) / 2;
- break;
- case 7:
- $posX = 0;
- $posY = $ground_h - $h;
- break;
- case 8:
- $posX = ($ground_w - $w) / 2;
- $posY = $ground_h - $h;
- break;
- case 9:
- $posX = $ground_w - $w;
- $posY = $ground_h - $h;
- break;
- default:
- $posX = rand(0,($ground_w - $w));
- $posY = rand(0,($ground_h - $h));
- break;
- }
-
- imagealphablending($ground_im, true);
- if($isWaterImage)
- {
- if($water_info[2]==3)
- {
- imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);
- }
- else
- {
- imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h,$w_pct);
- }
- }
- else
- {
- if( !empty($textColor) && (strlen($textColor)==7) )
- {
- $R = hexdec(substr($textColor,1,2));
- $G = hexdec(substr($textColor,3,2));
- $B = hexdec(substr($textColor,5));
- }
- else
- {
- echo $fun_r['synotfontcolor'];
- return "";
- }
- imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
- }
-
- @unlink($groundImage);
- switch($ground_info[2])
- {
- case 1:imagegif($ground_im,$groundImage);break;
- case 2:imagejpeg($ground_im,$groundImage,$w_quality);break;
- case 3:imagepng($ground_im,$groundImage);break;
- default:echo $formatMsg;return "";
- }
-
- if(isset($water_info)) unset($water_info);
- if(isset($water_im)) imagedestroy($water_im);
- unset($ground_info);
- imagedestroy($ground_im);
- }
- ?>
|