|
|
|
จะ resize ให้ขนาดภาพที่upload มาเป็นขนาดความกว้างxสูง เป็นขนาดเดียวกันทั้งหมด ทำยังไงคะ รบกวนด้วยค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start() ;
include "startconnect.inc.php" ;
$article_id = $_POST["article_id"] ;
$article_title = $_POST["article_title"] ;
$article_type_id = $_POST["slcarticletype"] ;
$article_subtype_id = $_POST["slcarticlesubtype"] ;
$article_predetail = $_POST["predetail"] ;
$pic_title_old = $_SESSION["pic_title_old"] ; // นำค่าจาก session ไปไว้ในตัวแปร
$pic_title = $_FILES['article_pic_title']['name']; // รับชื่อไฟล์ใหม่มาจากฟอร์ม
list($file_name,$ext_name) = split("\.",$pic_title) ; // แยกชื่อไฟล์กับนามสกุลออกจากกัน
$article_pic_title = time().".".$ext_name ; // สร้างชื่อไฟล์ขึ้นใหม่จากฟังก์ชั่นแล้วเชื่อมต่อเข้ากับนามสกุลที่แยกเอาไว้
$article_detail = $_POST['FCKeditor1'] ;
$member_id = $_SESSION["member_id"] ;
$update_date = date("Y-m-d") ;
$update_time = date("G:i:s") ;
$ip_address = $_SERVER['REMOTE_ADDR'] ;
$path_pic = "article" ;
if($pic_title!=NULL) {
if(($_FILES['article_pic_title']['type'] =="image/pjpeg")or($_FILES['article_pic_title']['type'] =="image/jpeg")or($_FILES['article_pic_title']['type'] =="image/gif")or($_FILES['article_pic_title']['type'] =="image/png")or($_FILES['article_pic_title']['type'] =="application/x-shockwave-flash")) {
if($_FILES['article_pic_title']['size']<=300000) {
if(copy($_FILES['article_pic_title']['tmp_name'],"picture/" . $path_pic . "/" . $article_pic_title)) {
$detail_pic = "Tempname = ".$_FILES['article_pic_title']['tmp_name']."<br>";
$detail_pic .= "Filename = ".$_FILES['article_pic_title']['name']."<br>";
$detail_pic .= "Filetype = ".$_FILES['article_pic_title']['type']."<br>";
$detail_pic .= "Filesize = ".$_FILES['article_pic_title']['size']."<br>";
$detail_pic .= "****************<br>";
$detail_pic .= "<font color = \"yellow\" size = \"4\">Upload Success</font>" ;
$_SESSION['result_upload'] = $detail_pic ;
$complete_upload = "yes" ;
$old_file = "picture/".$path_pic."/".$pic_title_old ;
unlink($old_file) ;
}
else {
$err_upload = "ไม่สามารถ Upload รูปภาพได้ <br>" ;
$_SESSION['result_upload'] = $err_upload ;
$complete_upload = "no" ;
$complete_sql = "ไม่สามารถเพิ่มรูปของ $article_title ได้ <br>" ;
$_SESSION['complete_upload'] = $complete_sql ;
header('Location:admin_article_add.php');
}
}
else {
$err_upload = "ขนาดรูปภาพต้องไม่เกิน 300K <br>" ;
$_SESSION['result_upload'] = $err_upload ;
$complete_upload = "no" ;
$complete_sql = "ไม่สามารถเพิ่มรูปของ $article_title ได้ <br>" ;
$_SESSION['complete_upload'] = $complete_sql ;
header('Location:admin_article_add.php');
}
}
else {
$err_upload = "รูปภาพต้องเป็น .jpg , .png , .gif , .swf เท่านั้น <br>" ;
$err_upload .="Filename = ".$_FILES['banner']['name']." Filetype = ".$_FILES['banner']['type']."ครับ<br>";
$_SESSION['result_upload'] = $err_upload ;
$complete_upload = "no" ;
$complete_sql = "ไม่สามารถเพิ่มรูปของ $article_title ได้ <br>" ;
$_SESSION['complete_upload'] = $complete_sql ;
header('Location:admin_article_add.php');
}
}
else {
$complete_upload = "yes" ;
}
$sql_edit_article = "update tblarticle set article_title = '$article_title' , article_type_id = '$article_type_id' , article_subtype_id = '$article_subtype_id' ,article_predetail = '$article_predetail' , " ;
if ($pic_title != NULL) {
$sql_edit_article .= "article_pic_title = '$article_pic_title' , " ; // ใช้ชื่อไฟล์ใหม่บันทึกลงฐานข้อมูล
}
$sql_edit_article .= "article_detail = '$article_detail' , member_id = '".$_SESSION["member_id"]."' , update_date = '$update_date' , update_time = '$update_time' , ip_address = '$ip_address' where article_id = '$article_id'" ;
//$_SESSION["sql"] = $sql_edit_article;
if ($complete_upload == "yes") {
mysql_query($sql_edit_article);
header('Location:admin_article.php');
}
mysql_close($connect);
?>
จะ resize ให้ขนาดภาพที่upload มาเป็นขนาดความกว้างxสูง เป็นขนาดเดียวกันทั้งหมด ทำยังไงคะ รบกวนด้วยค่ะ
Tag : PHP
|
|
|
|
|
|
Date :
2011-05-12 04:18:09 |
By :
nay12345 |
View :
1164 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
$images = "mygirl.jpg";
$new_images = "MyResize/mygirl.jpg";
$width=200; //*** Fix Width & Heigh (Autu caculate) ***//
$height=200;
$size=GetimageSize($images);
$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,$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
?>
<b>Original Size</b><br>
<img src="<?=$images;?>">
<hr>
<b>New Resize</b><br>
<img src="<?=$new_images;?>">
Go to : PHP Resize image
|
|
|
|
|
Date :
2011-05-12 06:30:35 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$article_predetail = $_POST["predetail"];
$pic_title = $_FILES['article_pic_title']['name'];
list($file_name,$ext_name) = split("\.",$pic_title) ;
$article_pic_title = time().".".$ext_name ;
$article_pic_title='$detail_pic';
$height=200;
$size=GetimageSize($article_pic_title);
$width=round($height*$size[0] / $size[1]);
$images_orig=ImageCreateFromJPEG($article_pic_title);
$photox=ImageX($image_orig);
$photoY=ImageY($image_orig);
$images_fin=imagecreatetruecolor($width,$height);
Imagecopyresampled($images_fin, $images_orig, 0,0,0,0, $width+1,$height+1,$photox,$photoy);
Imagejpeg($images_fin,'$detail_pic');
Iimagedestroy($images_orig);
Image_destroy($images_fin);
$article_detail = $_POST["FCKeditor1"];
$post_by = $_SESSION["memeber_id"] ;
$article_view = 0 ;
$article_vote = 0 ;
$post_date = date("Y-m-d") ;
$post_time = date("G:i:s") ;
$update_date = date("Y-m-d") ;
$update_time = date("G:i:s") ;
$ip_address = $_SERVER['REMOTE_ADDR'] ;
if(($_FILES['article_pic_title']['type'] =="image/pjpeg")or($_FILES['article_pic_title']['type'] =="image/jpeg")or($_FILES['article_pic_title']['type'] =="image/gif")or($_FILES['article_pic_title']['type'] =="image/x-png")or($_FILES['article_pic_title']['type'] =="application/x-shockwave-flash")) {
if($_FILES['article_pic_title']['size']<=2000000) {
if(copy($_FILES['article_pic_title']['tmp_name'],"picture/" . $path_pic . "/" . $article_pic_title)) {
$detail_pic = "Tempname = ".$_FILES['article_pic_title']['tmp_name']."<br>";
$detail_pic .= "Filename = ".$_FILES['article_pic_title']['name']."<br>";
$detail_pic .= "Filetype = ".$_FILES['article_pic_title']['type']."<br>";
$detail_pic .= "Filesize = ".$_FILES['article_pic_title']['size']."<br>";
$detail_pic .= "****************<br>";
$detail_pic .= "<font color = \"yellow\" size = \"4\">Upload Success</font>" ;
$_SESSION['result_upload'] = $detail_pic ;
$complete_upload = "Upload Complete" ;
}
ลองแก้แล้ว มันeror ค่ะ
ช่วยดูโค้ดให้หน่อยค่ะว่าผิดตรงไหนรึป่าว คะ
ขอบคุณมากค่ะ
|
|
|
|
|
Date :
2011-05-14 01:24:40 |
By :
nay12345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http://www.okvee.net/2010/06/28/v-image-class/
Code (PHP)
include(dirname(__FILE__)."/image.php");
$imgfile = dirname(__FILE__)."/image.jpg";
$image = new image($imgfile);
$image->resize(600,500);
$image->save();
|
|
|
|
|
Date :
2011-05-14 04:25:28 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
if(($_FILES['article_pic_title']['type'] =="image/pjpeg")or($_FILES['article_pic_title']['type'] =="image/jpeg")or($_FILES['article_pic_title']['type'] =="image/gif")or($_FILES['article_pic_title']['type'] =="image/png")or($_FILES['article_pic_title']['type'] =="application/x-shockwave-flash")) {
if($_FILES['article_pic_title']['size']<=2000000) {
if($_FILES['article_pic_title']['resize']){
$images = $_FILES['article_pic_title']['tmp_name'];
$new_images = "Thumbnails_".$_FILES['article_pic_title']["resize"];
$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);
if(copy($_FILES['article_pic_title']['tmp_name'],"picture/" . $path_pic . "/" . $article_pic_title)) {
}
$detail_pic = "Tempname = ".$_FILES['article_pic_title']['tmp_name']."<br>";
$detail_pic .= "Filename = ".$_FILES['article_pic_title']['name']."<br>";
$detail_pic .= "Filetype = ".$_FILES['article_pic_title']['type']."<br>";
$detail_pic .= "Filesize = ".$_FILES['article_pic_title']['size']."<br>";
$detail_pic .= "Fileresize = ".$_FILES['article_pic_title']['resize']."<br>";
$detail_pic .= "****************<br>";
$detail_pic .= "<font color = \"yellow\" size = \"4\">Upload Success</font>" ;
$_SESSION['result_upload'] = $detail_pic ;
$complete_upload = "yes" ;
ลองนำโค้ดมาแปลงดู มันไม่ยอม resize ให้น่ะค่ะ วนออกลูปไป ไม่ยอมอัพรูปขึ้นให้เลย
รบกวนช่วยดูโค้ดให้หน่อยน่ะคะ
พึ่งเริ่มหัดเขียนค่ะ มึนมากเลย
|
|
|
|
|
Date :
2011-05-15 13:25:56 |
By :
nay12345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนช่วยดูด้วยค่ะ
นั่งทำทั้งวันแล้ว ไม่ได้เลย
|
|
|
|
|
Date :
2011-05-15 16:38:29 |
By :
nay12345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
if(($_FILES['article_pic_title']['type'] =="image/pjpeg")or($_FILES['article_pic_title']['type'] =="image/jpeg")or($_FILES['article_pic_title']['type'] =="image/gif")or($_FILES['article_pic_title']['type'] =="image/png")or($_FILES['article_pic_title']['type'] =="application/x-shockwave-flash")) {
if($_FILES['article_pic_title']['size']<=2000000) {
if(copy($_FILES['article_pic_title']['tmp_name'],"picture/" . $path_pic . "/" . $article_pic_title)) {
$images = "$article_pic_title";
$new_images = "picture/" . $path_pic . "/" . $article_pic_title;
$width=200; //*** Fix Width & Heigh (Autu caculate) ***//
$height=150;
$size=GetimageSize($images);
$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,$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$detail_pic = "Tempname = ".$_FILES['article_pic_title']['tmp_name']."<br>";
$detail_pic .= "Filename = ".$_FILES['article_pic_title']['name']."<br>";
$detail_pic .= "Filetype = ".$_FILES['article_pic_title']['type']."<br>";
$detail_pic .= "Filesize = ".$_FILES['article_pic_title']['size']."<br>";
$detail_pic .= "****************<br>";
$detail_pic .= "<font color = \"yellow\" size = \"4\">Upload Success</font>" ;
$_SESSION['result_upload'] = $detail_pic ;
$complete_upload = "yes" ;
ลองแก้โค้ดแล้ว มันresize รูปให้แล้วค่ะ แต่มันไม่ยอมขึ้นรูป ขึ้นเป็นภาพสีดำขนาดตามที่กำหนดไว้น่ะค่ะ
รบกวนช่วยดูด้วยนะคะ
|
ประวัติการแก้ไข 2011-05-15 20:05:21
|
|
|
|
Date :
2011-05-15 20:04:19 |
By :
nay12345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนช่วยดูด้วยนะคะ ลองมาสองวันยังไม่ได้เลยค่ะ
|
|
|
|
|
Date :
2011-05-17 20:10:25 |
By :
nay12345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|