Re: [請益] PHP 上傳圖片時可以制作縮圖嘛?
※ 引述《CoMix (CoMix)》之銘言:
: 我想要讓我的圖片上傳網頁
: 可以在上傳圖片時產生 小的縮圖
: 這個功能 PHP 有辦法做到嘛??
小弟自己寫的PHP函數,請笑納
//做縮圖
function
thumbnail($filename="",$thumb_name="",$type="image/jpeg",$width="160"){
set_time_limit(0);
ini_set('memory_limit', '100M');
// Get new sizes
list($old_width, $old_height) = getimagesize($filename);
//檢查是否是180度的相片
$pic180=(($old_width/$old_height) > 2 and ($old_width/$width) > 2
)?true:false;
if($pic180){
$height=$width * 0.75;
$percent = round($height/$old_height,2);
$newwidth = round($old_width * $percent,0);
$newheight = round($old_height * $percent,0);
}else{
$percent=($old_width>$old_height)?round($width/$old_width,2):round($width/$old_height,2);
$newwidth = ($old_width>$old_height)?$width:round($old_width * $percent,0);
$newheight = ($old_width>$old_height)?round($old_height *
$percent,0):$width;
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
if($type=="image/jpeg" or $type=="image/jpg" or $type=="image/pjpg" or
$type=="image/pjpeg"){
$source = imagecreatefromjpeg($filename);
$type="image/jpeg";
}elseif($type=="image/png"){
$source = imagecreatefrompng($filename);
$type="image/png";
}elseif($type=="image/gif"){
$source = imagecreatefromgif($filename);
$type="image/gif";
}else{
die($type);
}
// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight,
$old_width, $old_height);
// Output
if($type=="image/jpeg"){
imagejpeg($thumb,$thumb_name,90);
}elseif($type=="image/png"){
imagepng($thumb,$thumb_name);
}elseif($type=="image/gif"){
imagegif($thumb,$thumb_name);
}
imagedestroy($source);
imagedestroy($thumb);
}
--
什麼是簽名檔啊?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.68.102.60
推
11/26 09:44, , 1F
11/26 09:44, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
-3
10