|
 |
|
จะupload รูปภาพ และ resize ด้วย มีปัญหาที่ ถ้าเป็น gif กับ png มันไม่upload ขึ้นให้รบกวนดูให้ทีครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
if(trim($_FILES["filUpload"]["tmp_name"]) != "")
{
if ($_FILES["file"]["type"] == "image/jpg")
{
$images = $_FILES["filUpload"]["tmp_name"];
$new_images = "pic_".$_FILES["filUpload"]["name"];
copy($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]);
$width=700; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=300;
$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,"myfile/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
@unlink("myfile/".$_FILES["filUpload"]);
//echo "Resize Successful.<br>";
}elseif($_FILES["file"]["type"] == "image/gif")
{
$images = $_FILES["filUpload"]["tmp_name"];
$new_images = "pic_".$_FILES["filUpload"]["name"];
copy($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]);
$width=700; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=300;
$images_orig = ImageCreateFromGIF($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);
ImageGIF($images_fin,"myfile/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
@unlink("myfile/".$_FILES["filUpload"]);
}elseif($_FILES["file"]["type"] == "image/png")
{
$images = $_FILES["filUpload"]["tmp_name"];
$new_images = "pic_".$_FILES["filUpload"]["name"];
copy($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]);
$width=700; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=300;
$images_orig = ImageCreateFromGIF($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);
ImagePNG($images_fin,"myfile/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
@unlink("myfile/".$_FILES["filUpload"]);
}
$strSQL = "UPDATE tabe ";
$strSQL .=" SET pic = '$new_images' WHERE im = '$im' ";
$objQuery = mysql_query($strSQL);
}
ถ้า upload JPG ก็ปกติดีครับ แต่ ถ้า เป็น gif กับ png มันไม่ขึ้นเลย ไปดูใน host ก็ไม่เห็น file ครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-06-10 20:21:32 |
By :
tonkonk |
View :
1925 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนเงื่อนไขเอาครับ ถ่้านามสกุล .gif ก็ให้ใช้อีก function
Code (PHP)
$images =""; //ใส่รูป
$size = getimagesize($images);
$img_type=strtolower(end(explode('.',$images)));
if($size[2] == 1) {
$images_orig = imagecreatefromgif($images); //resize GIF
} else if($size[2] == 2) {
$images_orig = imagecreatefromjpeg($images); //resize JPEG
}
else if($size[2] == 3) {
$images_orig = imagecreatefrompng($images); //resize png
}
$width=100;
$height=100;
$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);
imagegif($images_fin);
imagedestroy($images_orig);
imagedestroy($images_fin);
?>
Go to : code ตัวนี้ เขียนต่อยังไงครับ ?? เป็น code resize รูปภาพ ถ้าหากอยากได้ gif กับ png ...
Go to : ถามเรื่องโค๊ด php resize ภาพอ่าครับ โค๊ดข้างต้น resize ได้แค่ไฟล์ .jpg หรอครับ ผมลอง resize ไฟล์ .gif ดูอ่าครับ
|
 |
 |
 |
 |
Date :
2012-06-10 20:25:06 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|