Fri 12 May 2006 16:54:05
ดูcode ของผมนะครับ คือถ้าโพสรูปต่ำกว่าขนาด 97x97 มันจะไม่ติดอะคับ Eror แต่นอกนั้นได้ครับ พี่ลองแก้โค๊ดให้ทีครับ งง
อิอิรอบกวนพี่อีกทีครับ ขอบคุณมากๆเลยนะครับ
//เริ่มการ resize
$max_x = 97; //กำหนดความสูง
$max_y = 97; //กำหนดความกว้าง
$size = Getimagesize($myfile); //$myfile หมายถึงไฟล์รูปภาพที่ได้จากฟอร์ม
//เริ่มหาค่าขนาดของรูปภาพเพื่อนำไป resize
$x=$size[0]; // หาค่า ความสูง
$y=$size[1]; // หาค่าความกว้าง
$x_ratio=$max_x / $x;
$y_ratio=$max_x / $y;
if(($x <= $max_x)&&($y <= $max_y)){
$new_x = $x;
}
else if(($x_ratio * $y)<$max_y){
$new_x = $max_x;
$new_y = ceil($x_ratio * $y);
}
else{
$new_x = ceil($y_ratio * $x);
$new_y = $max_y;
}
$src = imagecreatefromjpeg($myfile); //ทำการ copy รูปภาพจาก Source เก็บไว้เป็น image resource
$dst = imagecreatetruecolor($new_x,$new_y); //จากนั้นก็สร้าง Image Resource มารองรับรูปใหม่ที่ทำการ resize แล้ว
imagecopyresized($dst,$src,0,0,0,0,$new_x,$new_y,$x,$y);
//เริ่มทำการ buffer image stream ครับเพื่อนำลงฐานข้อมูลไม่ใช่ไฟล์ทั่วไป
ob_start();
imagejpeg($dst);
$binData = ob_get_contents();
ob_end_clean();
imagedestroy($src);
imagedestroy($dst);
//นำข้อมูลที่ resize แล้วลงฐานข้อมูล
mysql_connect($host,$user,$passwd);
$sql = "insert into yourfild (img_resize) values ('".addslashes($binData)."')";
mysql_db_query($dbname,$sql);
Fri 12 May 2006 19:03:41
ok พี่ไม่ต้องละครับ หาเจอละ บรรทัดนี้ๆๆ
if(($x <= $max_x)&&($y <= $max_y)){
$new_x = $x;
$new_y = $y;
}
เพิ่มบรรทัดนีเข้าไป ผมลืม อิอิ มะต้องรบกวนพี่ละ ขอบคุนนะค๊าบ !!^_^!!

















