澶嶅埗浠g爜 浠g爜濡備笅:
//瀹氫箟缂╃暐鍥剧墖灏哄
$picSize = array(
'100_100'=> 1,
'200_100'=> 1
);
$imagePath = "../image/";
function parseUrl($url){
preg_match("/(?P[\w\d]+)_w(?P\d+)_h(?P\d+)\.(?P\w+)/",$url,$match);
return $match;
}
$urlArr = explode("/",$_SERVER['REQUEST_URI']);
$imgName = $urlArr[count($urlArr)-1];
$picInfo = parseUrl($imgName);
//閿欒灏哄
if(empty($picInfo['width']) || empty($picInfo['height']) ||
!array_key_exists($picInfo['width'].'_'.$picInfo['height'],$picSize)) die('涓嶅瓨鍦ㄨ灏哄鍥剧墖');
$originalPic = $imagePath.$picInfo['name'].'/'.$picInfo['name'].'.'.$picInfo['ext'];
//鍘熷鍥句笉瀛樺湪
if(!file_exists($originalPic)) die("鍥剧墖涓嶅瓨鍦紒");
/**
*绛夋瘮渚嬪帇缂╁浘鐗?BR> */
switch($picInfo['ext']){
case 'jpg':
$orgImg = ImageCreateFromJpeg($originalPic);
break;
default:
break;
}
$owidth = ImageSX($orgImg); //鍘熷灏哄
$oheight = ImageSY($orgImg);
$tW = $picInfo['width'];
$tH = $picInfo['height'];
//鑾峰彇缂╃暐鍥惧昂瀵?BR>if($owidth/$oheight > $tW/$tH){
$tH = intval($tW * $oheight/$owidth);
}else{
$tW = intval($tH * $owidth/$oheight);
}
//鐢熸垚鑳屾櫙鍥?BR>$new_img = ImageCreateTrueColor($picInfo['width'], $picInfo['height']);
$bgColor = imagecolorallocate($new_img,255,255,255);
if (!@imagefilledrectangle($new_img, 0, 0, $picInfo['width']-1, $picInfo['height']-1, $bgColor)) {
echo "鏃犳硶鍒涘缓鑳屾櫙鍥?; //@todo璁板綍鏃ュ織
exit(0);
}
if (!@imagecopyresampled($new_img, $orgImg, ($picInfo['width']-$tW)/2, ($picInfo['height']-$tH)/2, 0, 0, $tW, $tH, $owidth, $oheight)) {
echo "鐢熸垚鍥剧墖澶辫触";
exit(0);
}
//鐢熸垚鍥剧墖
ob_start();
imagejpeg($new_img);
$_newImg = ob_get_contents();
ob_end_clean();
file_put_contents($imagePath.$picInfo['name']."/".$imgName, $_newImg);
header("Content-type:image/jpeg; charset=utf-8");
imagejpeg($new_img);
?>
浣跨敤鏃跺€欑粦瀹歛pache conf 鐨?documentError 404 鐨刪andler 涓烘鏂囦欢銆傘€?BR>
http://www.bkjia.com/PHPjc/327724.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327724.htmlTechArticle澶嶅埗浠g爜 浠g爜濡備笅: ?php //瀹氫箟缂╃暐鍥剧墖灏哄 $picSize = array( '100_100'= 1, '200_100'= 1 ); $imagePath = "../image/"; function parseUrl($url){ preg_match("/(?Pname[\...