Re: [請益] PHP 上傳圖片時可以制作縮圖嘛?

看板PHP作者 (tad)時間17年前 (2008/11/24 10:05), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #19AWlTmx (PHP)
文章代碼(AID): #19AWlTmx (PHP)