[PHP] Resize รูปภาพ

posted on 22 Jan 2008 00:35 by rije  in PHP

แปะงับ กันลืม

----------------------------------

Title : วิธีการย่อรูปด้วย PHP

---------------------------------

<? define (SEP, "\\");

//__FILE__ gives the file system path of the currently executing script
$gallery_home = dirname(__FILE__).SEP;

// This is the images directory
$upload_dir = $gallery_home.'images'.SEP;

//thumbnail directory
$thumbnail_dir = $gallery_home.'thumbs'.SEP;

// Original name of the file that you uploaded
$orig_name = $_FILES['myimage']['name'];
$file_type = $_FILES['myimage']['type'];
$upload_file = $upload_dir . basename($_FILES['myimage']['name']);
if (move_uploaded_file($_FILES['myimage']['tmp_name'], $upload_file)) {
echo "File is valid, and was successfully uploaded.\n";
}

// thumb nail file path
$thumbnail_file = $thumbnail_dir.basename($_FILES['myimage']['name']);

// Create thumb nail
scale_image($upload_file , $thumbnail_file);
function scale_image($image_file_path, $new_file_path) {
// Get new sizes
list($width , $height) = getimagesize($image_file_path);
$newwidth = 200;
$height2 = $width/$newwidth;
$newheight = $height/$height2;

// Load
$thumb = imagecreatetruecolor($newwidth , $newheight);
$source = imagecreatefromgif($image_file_path);

//Transparent for gif
$trnprt_indx = imagecolortransparent($source);
$trnprt_color = imagecolorsforindex($source, $trnprt_indx);
$trnprt_indx = imagecolorallocate($thumb, $trnprt_color['white']);
imagefill($image_resized, 0, 0, $trnprt_indx);
imagecolortransparent($thumb, $trnprt_indx);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagegif($thumb, $new_file_path);
ImageDestroy($source);
ImageDestroy($thumb);
}
?>

เฮ้อ หน่วง ขี้เกียจแปล - -"

นี่เป็นไฟล์ resize.php รับค่ามาจากอีกไฟล์

โดยอีกไฟล์ input type=file name=myimage มา

จบ. นอนดีก่า 

edit @ 22 Jan 2008 00:49:01 by r i j e

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry

โฮ่ สาระ ขบคุนมากค้าบบ

#1 By ~*~Sakura Kaze~*~ on 2008-01-22 00:58

sad smile sad smile กี๊ซซซซ
nana เป็นพวกพ่ายแพ้เทคโนโลยี...หง่าsad smile

#2 By (^_^)/nana on 2008-01-22 15:55

ย่อรูปอย่างยาว

#3 By ชิเมะ ★ on 2008-01-22 20:42

เท่ากับว่าเราใช้ url ลิงค์หลัก

แต่แสดงผลเท่าไซด์ที่กำหนดไว้ใช่หรือไม่คะ

ฮ่ากกกกกกกกกกกกกกกกกกก ลงอีกๆๆ สอนหนูหน่อย ฮือกรี๊ด

#4 By 「 Self + SenSe 」 on 2008-01-22 22:58



hidden hit counter