亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

所縮略圖模塊的相關處理

原創(chuàng) 2019-04-08 11:43:47 239
摘要:<?php// http://localhost/exa5/thumb_image/thumb_stand.php?w=200&h=200// 把大圖縮略到縮略圖指定的范圍內,可能有留白(原圖細節(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

// 把大圖縮略到縮略圖指定的范圍內,可能有留白(原圖細節(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");//設定生成圖片格式

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


    // 使縮略后的圖片不變形,并且限制在 縮略圖寬高范圍內

    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;

    }

}

?>



批改老師:查無此人批改時間:2019-04-08 16:03:39
老師總結:完成的不錯。圖片計算比較麻煩,這個要多學習下。繼續(xù)加油

發(fā)布手記

熱門詞條