|
 |
|
อัพโหลดรูปภาพแล้วเสียคุณภาพ เขียนคำสั่งดักเกินขนาดแล้ว แล้วลองอัพขนาดที่ไม่ต้อง resize แต่ก็ยังเสียคุณภาพ |
|
 |
|
|
 |
 |
|
โอเค ครับ รู้สาเหตุละ
    
|
 |
 |
 |
 |
Date :
2014-07-23 22:46:26 |
By :
anirut_yam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กลับมาบอกด้วยครับว่าเพราะอะไร รอติดตามอยู่ครับ
|
 |
 |
 |
 |
Date :
2014-07-23 22:48:49 |
By :
cowboycnx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การอัพโหลดรูป จะมีการดักอยู่
1. ดักนามสกุล (เพื่อไม่ให้ผ่าน)
2. ตรวจสอบว่ารูปที่จะอัพนั้นมีขนาดตามที่เรากำหนดหรือไม่ หากรูปที่เรากำหนดมีความกว้างมากกว่าที่กำหนดให้ทำการ resize ก่อน (ซึ่งเดิมผมแยกโค้ด แค่บางตัว คือ กรองแต่ละขั้น
อันนี้ แก้แล้ว โอเลย
Code (PHP)
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = date("YmdHis").$rjpg; //ไม่ใส่ข้อความใหม่ใน ฟันหนู เพื่อให้ชื่อภาพตรงกัน เป็นภาพเดียวกัน $new_images =
$size = getimagesize($images);
if ($size[0] > $txt_size) {
$width=$txt_size; //*** Fix Width & Heigh (Autu caculate) ***//
$height=round($width*$size[1]/$size[0]);
$images_orig = imagecreatefromjpeg($images);
$photoX = imagesx($images_orig);
$photoY = imagesy($images_orig);
$images_fin = imagecreatetruecolor($width, $height);
imagecopyresampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
imagejpeg($images_fin,"../โฟลด์เดอที่เก็บภาพ/".$new_images);
imagedestroy($images_orig);
imagedestroy($images_fin);
} else {
//list($width, $height) = $size;
//echo"รูปกว้าง $width สูง $height"; ขนาดน้อยกว่าที่กำหนดไม่ต้องผ่านคำสั่งรีไซด์ ไม่งั้นคุณภาพเสีย
move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"โฟลด์เดอที่เก็บภาพ/".$new_images);
}
อันนี้ตัวที่ว่าคุณภาพเสีย
Code (PHP)
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = date("YmdHis").$rjpg; //ไม่ใส่ข้อความใหม่ใน ฟันหนู เพื่อให้ชื่อภาพตรงกัน เป็นภาพเดียวกัน $new_images =
$size = getimagesize($images);
if ($size[0] > $txt_size) {
$width=$txt_size; //*** Fix Width & Heigh (Autu caculate) ***//
$height=round($width*$size[1]/$size[0]);
} else {
list($width, $height) = $size;
}
$images_orig = imagecreatefromjpeg($images);
$photoX = imagesx($images_orig);
$photoY = imagesy($images_orig);
$images_fin = imagecreatetruecolor($width, $height);
imagecopyresampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
imagejpeg($images_fin,"../picture_from_upload/".$new_images);
imagedestroy($images_orig);
imagedestroy($images_fin);
*** สรุปง่ายๆ คือ รูปที่ขนาดไม่ใหญ่เกินที่เรากำหนด ไม่ต้องผ่านคำสั่งใดๆ ทั้งสิ้น
ทำคำสั่งนี้เลย
Code (PHP)
move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"โฟลด์เดอที่เก็บภาพ/".$new_images);
|
 |
 |
 |
 |
Date :
2014-07-23 23:16:40 |
By :
anirut_yam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|