abstrait:<?php// http://localhost/exa5/thumb_image/thumb_stand.php?w=200&h=200// 把大圖縮略到縮略圖指定的范圍內(nèi),可能有留白(原圖細(xì)節(jié)不丟失)$w = $_GET['w']?$_GET['w']:200;$h = $_GET['h']?$_GET['h']:2
<?php
// http://localhost/exa5/thumb_image/thumb_stand.php?w=200&h=200
// 把大圖縮略到縮略圖指定的范圍內(nèi),可能有留白(原圖細(xì)節(jié)不丟失)
$w = $_GET['w']?$_GET['w']:200;
$h = $_GET['h']?$_GET['h']:200;
$filename = "stand_test_".$w."_".$h.".jpg";//輸出到的位置
$loc_img='test.jpg';//本地圖片
image_resize( $loc_img,$filename, $w, $h);
header("content-type:image/png");//設(shè)定生成圖片格式
echo file_get_contents($filename);
function image_resize($f, $t, $tw, $th){
// 按指定大小生成縮略圖,而且不變形,縮略圖函數(shù)
$temp = array(1=>'gif', 2=>'jpeg', 3=>'png');
list($fw, $fh, $tmp) = getimagesize($f);
if(!$temp[$tmp]){
return false;
}
$tmp = $temp[$tmp];
$infunc = "imagecreatefrom$tmp";
$outfunc = "image$tmp";
$fimg = $infunc($f);
// 使縮略后的圖片不變形,并且限制在 縮略圖寬高范圍內(nèi)
if($fw/$tw > $fh/$th){
$th = $tw*($fh/$fw);
}else{
$tw = $th*($fw/$fh);
}
$timg = imagecreatetruecolor($tw, $th);
imagecopyresampled($timg, $fimg, 0,0, 0,0, $tw,$th, $fw,$fh);
if($outfunc($timg, $t)){
return true;
}else{
return false;
}
}
?>
Professeur correcteur:查無此人Temps de correction:2019-04-08 16:03:39
Résumé du professeur:完成的不錯(cuò)。圖片計(jì)算比較麻煩,這個(gè)要多學(xué)習(xí)下。繼續(xù)加油