Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,030

HOME > PHP > PHP Forum > ช่วยอธิบาย code Resize ให้หน่วยครับ พอดีได้ code แปลงขนาด flie มานะ ครับ ทีนี้คือผมใช้ PHP เลยอยากให้ พี่ๆ คนเก่งช่วยอธิบาย



 

ช่วยอธิบาย code Resize ให้หน่วยครับ พอดีได้ code แปลงขนาด flie มานะ ครับ ทีนี้คือผมใช้ PHP เลยอยากให้ พี่ๆ คนเก่งช่วยอธิบาย

 



Topic : 019541

Guest




พอดีได้ code แปลงขนาด flie มานะ ครับ ทีนี้คือผมใช้ PHP ไม่ค่อยเก่งครับ
เลยอยากให้ พี่ๆ คนเก่งช่วยอธิบาย ให้ผมหน่อยครับว่า มันทำงานยังไง ขอบ
คุณอย่างสูงๆๆๆๆๆ ครับผม

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if($_FILES['image'])
{preg_match('/\.([A-Za-z]+?)$/', $_FILES['image']['name'], $matches);
$matches[1] = strtolower($matches[1]);
if($matches[1] == 'png' && function_exists('imagecreatefrompng') || $matches[1] == 'jpg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'jpeg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'gif' && function_exists('imagecreatefromgif') || $matches[1] == 'bmp' && function_exists('imagecreatefromwbmp')) {
list($owidth, $oheight) = getimagesize($_FILES['image']['tmp_name']);
if($_POST['resizeby'] == 'height') {
$nheight = ($_POST['size']>1)?$_POST['size']:600;
$nwidth = $nheight / $oheight * $owidth;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
else {
$nwidth = ($_POST['size']>1)?$_POST['size']:800;
$nheight = $nwidth / $owidth * $oheight;
$resized = imagecreatetruecolor($nwidth, $nheight);
}
if($matches[1] == 'png')
$original = imagecreatefrompng($_FILES['image']['tmp_name']);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
$original = imagecreatefromjpeg($_FILES['image']['tmp_name']);
if($matches[1] == 'gif')
$original = imagecreatefromgif($_FILES['image']['tmp_name']);
if($matches[1] == 'bmp')
$original = imagecreatefromwbmp($_FILES['image']['tmp_name']);
imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight);
header('Content-Disposition: attachment; filename="'.$_FILES['image']['name'].'"');
header('Content-type: image/'.(($matches[1] == 'jpg')?'jpeg':$matches[1]));
if($matches[1] == 'png')
imagepng($resized);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
imagejpeg($resized);
if($matches[1] == 'gif')
imagegif($resized);
if($matches[1] == 'bmpg')
imagewbmp($resized);
exit();

} else
$error = 'File type not supported!';
} else
$error = 'No image uploaded!';
}
?>
<?php print '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>Resize Image</title>
<link rel="stylesheet" href="resize.css" type="text/css" />
</head>
<body>
<h1>Resize Image</h1>
<?php
if($error)
print '<p>'.$error.'</p>';
?>
<form action="" method="post" enctype="multipart/form-data" >
<p>Upload your JPG, JPEG, GIF, PNG or BMP image: <br />
<input type="file" name="image" /></p>
<p>Choose a height or width you want your image to be: <br />
<select name="resizeby">
<option value="width" selected="true">Width:</option>
<option value="height">Height:</option>
</select>
<input type="text" name="size" id="size" value="800" /> pixels</p>
<p><input type="submit" value="Submit" id="submit" /></p>
</form>
<p id="footer">
<!--You may not remove the following line without permission!-->
Powered by <a href="http://www.dxldev.info/">DXL dev'</a>.
</p>
</body>
</html>


Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 18 เม.ย. 2551 12:45:45 By : เด็กตาดำๆ View : 1936 Reply : 2
 

 

No. 1



โพสกระทู้ ( 1,008 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook



<?


if($_SERVER['REQUEST_METHOD'] == 'POST') { // ตรวจสอบว่า มีการส่งฟอร์มมาแบบไหน POST / GET
if($_FILES['image']) // ดูว่าไ้ด้มีการแนบไฟ์มาหรือเปล่า
{preg_match('/\.([A-Za-z]+?)$/', $_FILES['image']['name'], $matches); // แยก ชื่อไฟล์ อกมาเพื่อหาประเภทไฟล์ เอา แต่ ส่วนที่อยุ่หลัง .
$matches[1] = strtolower($matches[1]); // strtolower เปลี่ยนตัวอักษรเป็นตัวเล็กทั้งหมด
if($matches[1] == 'png' && function_exists('imagecreatefrompng') || $matches[1] == 'jpg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'jpeg' && function_exists('imagecreatefromjpeg') || $matches[1] == 'gif' && function_exists('imagecreatefromgif') || $matches[1] == 'bmp' && function_exists('imagecreatefromwbmp')) {
list($owidth, $oheight) = getimagesize($_FILES['image']['tmp_name']);
if($_POST['resizeby'] == 'height') {
$nheight = ($_POST['size']>1)?$_POST['size']:600; //
$nwidth = $nheight / $oheight * $owidth;// กำหนดขนาดภาพขึ้นมาใหม่
$resized = imagecreatetruecolor($nwidth, $nheight);//
}
else {
$nwidth = ($_POST['size']>1)?$_POST['size']:800;//
$nheight = $nwidth / $owidth * $oheight;//
$resized = imagecreatetruecolor($nwidth, $nheight);//
}

?>



<?
if($matches[1] == 'png')//สรวจสอบ ประเภทไฟล์
$original = imagecreatefrompng($_FILES['image']['tmp_name']);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
$original = imagecreatefromjpeg($_FILES['image']['tmp_name']);
if($matches[1] == 'gif')
$original = imagecreatefromgif($_FILES['image']['tmp_name']);
if($matches[1] == 'bmp')
$original = imagecreatefromwbmp($_FILES['image']['tmp_name']); //เริ่มสร้างไฟล์
imagecopyresampled($resized, $original, 0, 0, 0, 0, $nwidth, $nheight, $owidth, $oheight); //รีขนาดตามที่ได้กำหนดไว้
header('Content-Disposition: attachment; filename="'.$_FILES['image']['name'].'"');
header('Content-type: image/'.(($matches[1] == 'jpg')?'jpeg':$matches[1]));//แสดงรูปภาพ
if($matches[1] == 'png')
imagepng($resized);
if($matches[1] == 'jpg' || $matches[1] == 'jpeg')
imagejpeg($resized);
if($matches[1] == 'gif')
imagegif($resized);
if($matches[1] == 'bmpg')
imagewbmp($resized);
exit();

} else
$error = 'File type not supported!';
} else
$error = 'No image uploaded!';
}


?>


ประมาณนี้มั้ง






Date : 18 เม.ย. 2551 19:43:52 By : arsachi
 


 

No. 2

Guest


ขอบคุณมากครับ ท่าน
Date : 20 เม.ย. 2551 18:25:52 By : เด็กตาดำๆ
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยอธิบาย code Resize ให้หน่วยครับ พอดีได้ code แปลงขนาด flie มานะ ครับ ทีนี้คือผมใช้ PHP เลยอยากให้ พี่ๆ คนเก่งช่วยอธิบาย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่