[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













