|
 |
|
การ upload แบบ resite เราจะแทรกโคดให้ขนาดภาพลดได้ตรงไหนครับ |
|
 |
|
|
 |
 |
|
อันนี้ในแนวทางของผมนะใช้ function ลองปรับใช้ดูครับ
Code (PHP)
function fixResize($ImageTmp,$Rename,$Width,$Height,$Path,$Type){
$ImageFin=imagecreatetruecolor($Width,$Height);
if($Type == 'jpg'){
$ImageOri=imagecreatefromjpeg($ImageTmp);
}else if($Type == 'png'){
$ImageOri=imagecreatefrompng($ImageTmp);
}else{
$ImageOri=imagecreatefromgif($ImageTmp);
}
$ImageX=imagesx($ImageOri);
$ImageY=imagesy($ImageOri);
$ImageResize=imagecopyresampled($ImageFin,$ImageOri,0,0,0,0,$Width,$Height,$ImageX,$ImageY);
if($ImageResize){
if($Type == 'jpg'){
$ImageComplate=imagejpeg($ImageFin,$Path.$Rename);
}else if($Type == 'png'){
$ImageComplate=imagepng($ImageFin,$Path.$Rename);
}else{
$ImageComplate=imagegif($ImageFin,$Path.$Rename);
}
}
if($ImageComplate){
return $Complate="Success";
}
}
$ImageTmp=_FILES["fileUpload".$i]["tmp_name"],
$ImageName=_FILES["fileUpload".$i]["name"],
$explodeName=explode(".",$ImageName);
$Type=$explodeName[1];
$Resize=fixResize($ImageTmp,$ImageName,100,100,"thaicreate/",$Typle);
if($Resize=="Success"){
$insertImage=mysql_query("INSERT INTO galery (Image) VALUES ('".$Rename."')") or die mysql_error();
if($insertImage){
echo "image resize Success";
}
}
|
 |
 |
 |
 |
Date :
2013-01-10 16:03:24 |
By :
Ex-[S]i[L]e[N]t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลักการมันคือ upload รูปต้นฉบับไปก่อน
แล้วเอารูปต้นฉบับนั้นไปสร้างรูปใหม่
แล้วลบรูปถาพต้นฉบับทิ้ง
|
 |
 |
 |
 |
Date :
2013-01-10 16:13:45 |
By :
Krungsri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูตัวนี้ครับ
Code (PHP)
<?
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["name"]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$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,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
}
?>
Go to : PHP Upload and Resize Image
|
 |
 |
 |
 |
Date :
2013-01-10 16:45:30 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|