|
 |
|
เกี่่ยวกับอัพโหลดรูปภาพแล้วปรับขนาดอัตโนมัติ มีปัญหาดังนี้ |
|
 |
|
|
 |
 |
|
Code (PHP)
if ($photo) {
$array_last=explode(".",$photo_name);
$s=count($array_last)-1;
$lastname=strtolower($array_last[$s]) ;
if ($lastname == "jpg" or $lastname== "jpeg" or $lastname =="png" or $lastname=="gif") {
$sql2="select max(id) from store ";
$result2=mysql_db_query($dbname,$sql2);
$row=mysql_fetch_row($result2);
$filename=$row[0].".".$lastname;
if ($lastname =="jpg" or $lastname =="jpeg") {
$ori_img = imagecreatefromjpeg($photo);
} else if ($lastname =="png") {
$ori_img = imagecreatefrompng($photo);
} else if ($lastname =="gif") {
$ori_img = imagecreatefromgif($photo);
}
$ori_size = getimagesize($photo);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
if ($ori_w>=$ori_h) {
$new_w = 300;
$new_h = round(($new_w/$ori_w) * $ori_h);
} else {
$new_h =300;
$new_w = round(($new_h/$ori_h) * $ori_w);
}
$new_img= imagecreatetruecolor($new_w, $new_h);
imagecopyresized( $new_img, $ori_img,0,0,0,0,$new_w, $new_h,$ori_w,$ori_h);
if ($lastname =="jpg" or $lastname =="jpeg") {
imagejpeg($new_img,"images/$filename");
} else if ($lastname =="png") {
imagepng($new_img,"images/$filename");
} else if ($lastname =="gif") {
imagegif($new_img,"images/$filename");
}
imagedestroy($ori_img);
imagedestroy($new_img);
$sql="update store set pic='$filename' where id ='$row[0]' ";
mysql_db_query($dbname,$sql);
}
unlink($photo);
}
จากโค้ดต้องการเช็ดขนาดถ้ามีขนาดกว้างหรือยาวกว่า 300 จะทำการปรับขนาดให้ใกล้เคียงได้แต่ ถ้าภาพนั้นมีขนาดกว้างยาว น้อยกว่า 300 มันก็จะปรับเหมือนให้มีขนาดใกล้เคียง 300*300 กล่าวคือไม่ต้องการให้ภาพที่มีขนาดเล็กกว่าทั้งความกว้างหรือความยาว ปรับขนาด มันทำให้ภาพเปลี่ยนแปลง เช่น ไม่ชัด พื้นหลังเปลี่ยนเป็นสีดำ จะเช็ด if อย่างไร
Tag : PHP, MySQL, HTML/CSS

|
|
 |
 |
 |
 |
Date :
2010-12-15 01:34:57 |
By :
guest |
View :
869 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$ori_size = getimagesize($photo);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
if($ori_w >= 300)
if จากตัวนี้ครับ ถ้ามากกว่า 300 อาจจะไม่ต้องทำการ Resize ครับ
Go to : PHP Resize image
|
 |
 |
 |
 |
Date :
2010-12-15 06:30:21 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|