当前位置:Gxlcms > PHP教程 > 鍩轰簬PHP鏈嶅姟绔浘鐗囩敓鎴愮缉鐣ュ浘鐨勬柟娉曡瑙PHP鏁欑▼|甯涔嬪

鍩轰簬PHP鏈嶅姟绔浘鐗囩敓鎴愮缉鐣ュ浘鐨勬柟娉曡瑙PHP鏁欑▼|甯涔嬪

时间:2021-07-01 10:21:17 帮助过:3人阅读

澶嶅埗浠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>

www.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[\...

人气教程排行