php產生縮圖範例程式碼分享(使用gd庫實現)_PHP教程

來源:互聯網
上載者:User
複製代碼 代碼如下:

header("content-type:text/html;charset=gbk");
ini_set("date.timezone","Asia/chong");
//判斷檔案是否為空白
if(empty($_FILES)){
echo"上傳檔案過大";
exit;
}
//判斷檔案上傳是否有錯誤
if($_FILES['pic']['error']){
echo "上傳檔案";
exit;
}
//判斷檔案類型是否非法擷取檔案尾碼
$allowtype=array("jpg","png","jpeg","gif");
$a=explode('.',$_FILES['pic']['name']);
$index=count($a)-1;
$ex=strtolower($a[$index]);
if(!in_array($ex,$allowtype)){
echo "上傳檔案非法";
exit;
}
$file=date('YmdHis').rand().".".$ex;
$src=$_FILES['pic']['tmp_name'];
$des="upload/".$file;
$rs=move_uploaded_file($src,$des);

//縮圖
//讀取已經上傳圖片
$image=imagecreatefromjpeg($des);
$a=getimagesize($des);
$w=$a[0];
$h=$a[1];
if($w>$h){
$width=300;
$height=$width/$w*$h;
}else if($w<$h){
$height=300;
$width=$height/$h*$w;
}else{
$width=300;
$height=300;
} www.jbxue.com
//建立空白新圖片
$newimage=imagecreatetruecolor($width, $height);
//copy源圖片內容 copy新圖片
imagecopyresized($newimage, $image, 0,0, 0,0, $width, $height, $w, $h);
$filename="upload/s_".$file;
imagejpeg($newimage,$filename);

http://www.bkjia.com/PHPjc/718620.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/718620.htmlTechArticle複製代碼 代碼如下: form method="post" action="suo_do.php" enctype="multipart/form-data" input type="file" name="pic" / input type="submit" value="上傳1" / /form ?php head...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.