|
|
|
อยากสอบถามเรื่องการ upload รูปแล้วผมต้องการที่จะให้หมุน auto โดยดูจากค่า exif อะครับ |
|
|
|
|
|
|
|
Code (PHP)
if(!is_array($_FILES["photo"]['name'])) //single file
{
$RandomNum = time();
$random_digit=rand(0000,9999);
$images = $_FILES["photo"]["tmp_name"];
$ImageName = str_replace(' ','-',strtolower($_FILES['photo']['name']));
$ImageType = $_FILES['photo']['type']; //"image/png", image/jpeg etc.
$Imagesize = $_FILES['photo']['size'];
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.','',$ImageExt);
$ImageName = str_replace($ImageName,$job_no,$ImageName);
$ImageName = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
$NewImageName = "Photo_".$ImageName.'_'.$RandomNum.'.'.$ImageExt;
//$ret[$fileName]= $output_dir.$NewImageName;
//$new_images = "photo_".$_FILES["photo"]["name"];
//move_uploaded_file($_FILES["photo"]["tmp_name"],$output_dir. $new_images);
//copy($_FILES["fileUpload"]["tmp_name"],$output_dir.$_FILES["fileUpload"]["name"]);
//-------------------------------------------------------------------------------
$new_images = "Thumbnails_".$ImageName.'_'.$RandomNum.'.'.$ImageExt;
// copy($_FILES["photo"]["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,$output_dir."/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//------------------------------------------------------------------------------- Thumbnails
if($Imagesize > '500000'){
$width=1024; //*** 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,$output_dir."/".$NewImageName,75);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//------------------------------------------------------------------------------- size more 500kb
}else {
move_uploaded_file($_FILES["photo"]["tmp_name"],$output_dir. $NewImageName);
//------------------------------------------------------------------------------- size less 500kb
}
อันนี้ของผมมี resize แล้ว มี Thumbnails แล้วแต่หาวิธีที่จะหมุนรูปไม่ได้เลยครับ
Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2015-08-17 15:56:14 |
By :
wahahaboy |
View :
1679 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผม งงเรื่องการใช้ function อันนี้ มันคือ Tag script หรือป่าว หรือว่าจัดยัดไปใน php เลย
|
|
|
|
|
Date :
2015-08-17 17:49:40 |
By :
wahahaboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองหลายแบบละไม่หมุนสะที
|
|
|
|
|
Date :
2015-08-18 10:25:15 |
By :
wahahaboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$width=1024; //*** 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);
function image_fix_orientation($images) {
$exif = exif_read_data($images);
if (!empty($exif['Orientation'])) {
$image = imagecreatefromjpeg($images);
switch ($exif['Orientation']) {
case 3:
$image = imagerotate($image, -180, 0);
break;
case 6:
$image = imagerotate($image, 90, 0);
break;
case 8:
$image = imagerotate($image, -90, 0);
break;
}
ImageJPEG($images,$output_dir."/".$NewImageName,75);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
}
ลองใส่แบบนี้ไปภาพไม่ออกเลยครับ งงมากว่ามันจะกลับแบบไหน
|
|
|
|
|
Date :
2015-08-21 16:16:28 |
By :
wahahaboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับลองแกะ ดูก่อน
|
|
|
|
|
Date :
2015-09-01 11:36:29 |
By :
wahahaboy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|