|
 |
|
รบกวนสอบถามโค้ด Resize รุปภาพหน่อยครับ รีไซต์แล้วภาพเบลอมากๆ |
|
 |
|
|
 |
 |
|
รบกวนสอบถามโค้ด Resize รุปภาพหน่อยครับ รีไซต์แล้วภาพเบลอมากๆ อยากจะปรับรีแล้ว รักษาคุณภาพของรูปเอาไว้ จะต้องทำไงครับ รีแล้วเบลอจนรูปไม่สวยเลย
อันนี้เป็นโค้ดครับ
Code (PHP)
$path = $imgPath; //กำหนดที่เก็บรูปภาพใหม่
$width = $imgWidth; //กำหนดความกว้างของรูปใหม่
//ตรวจสอบว่าไฟล์ที่รับมาเป็นสกุล jpg หรือ gif หรือ png หรือเปล่า
if($photo_type == "image/pjpeg" || $photo_type == "image/gif" || $photo_type == "image/x-png")
{
if($photo_type == "image/pjpeg") $images_orig = ImageCreateFromJPEG($photo);
else if($photo_type == "image/gif") $images_orig = ImageCreateFromGIF($photo);
else if($photo_type == "image/x-png") $images_orig = ImageCreateFromPNG($photo);
$size=GetimageSize($photo); // get ขนาดรูป
$height=round($width*$size[1]/$size[0]); //คำนวนความสูง อัตโนมัติ
$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);
// เซฟชื่อไฟล์ ที่อัพโหลดมา เป็น thumb_รหัสmd5.นามสกุลไฟล์
if($photo_type == "image/pjpeg"){ $photoType = "jpg"; }
elseif($photo_type == "image/gif"){ $photoType = "gif"; }
elseif($photo_type == "image/x-png"){ $photoType = "png"; }
$datetime = date("Ymd") . date("His");
$photoName = MD5($photo_name);
$photo_name = "thumb_" . $i . $datetime . $photoName . "." .$photoType;
//คัดลอกไฟล์ที่อัพโหลดมา ไปเก็บที่โฟลเดอร์
$imageOriginal = $i . $datetime . $photoName . "." . $photoType;
copy($_FILES["photo"]["tmp_name"], "$path". $imageOriginal );
if($photo_type == "image/pjpeg") ImageJPEG($images_fin,$path.$photo_name);
else if($photo_type == "image/gif") ImageGIF($images_fin,$path.$photo_name);
else if($photo_type == "image/x-png") ImagePNG($images_fin,$path.$photo_name);
}
Tag : PHP

|
ประวัติการแก้ไข 2011-10-14 15:57:00
|
 |
 |
 |
 |
Date :
2011-10-14 15:46:37 |
By :
banktt |
View :
1714 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณอย่างสูงครับ สุโครยยยยยยยยย......
|
 |
 |
 |
 |
Date :
2011-10-14 16:43:48 |
By :
banktt |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|