【发布时间】:2018-09-09 16:11:14
【问题描述】:
嘿伙计,我有一个小问题......
我有一个在 PC 上运行良好的图像上传加载器,全部移动-调整大小-缩略图。
但问题是当我使用单元格上传时,它会将图像旋转 90 度..
我了解到这是手机的常见问题...
所以我需要制作一个编辑器来按用户旋转图像..所以如果他使用单元格,他会编辑图像以正确旋转...
可以这样做吗?
我似乎有很多图像旋转器,但是当它上传时没有编辑?
这是我的代码:
session_start();
include_once 'config/dbconnect.php';
if (!isset($_SESSION['userSession'])) {
header("Location: index.php");
}
if(isset($_POST["submit"])) {
if(is_array($_FILES)) {
$User=$_POST['User'];
//$product_name=$_POST['Name'];
$product_desc=$_POST['Desc'];
$product_date_exp=$_POST['Exp'];
$product_qty=$_POST['QTY'];
$product_folder=$_POST['Folder'];
$product_cat=$_POST['Cat'];
$product_month=$_POST['Month'];
$status ="Public";
$product_code="1";
$product_type="Coupons";
$file = $_FILES['image']['tmp_name'];
$sourceProperties = getimagesize($file);
$fileNewNTime = time();
$fileNewName =$User."_".$product_month."_".$fileNewNTime;
$folderPath = "Folders/".$product_folder."/";
$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
$imageType = $sourceProperties[2];
switch ($imageType) {
case IMAGETYPE_PNG:
$imageResourceId = imagecreatefrompng($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagepng($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
break;
case IMAGETYPE_GIF:
$imageResourceId = imagecreatefromgif($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagegif($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
break;
case IMAGETYPE_JPEG:
$imageResourceId = imagecreatefromjpeg($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagejpeg($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
break;
default:
echo "Invalid Image type.";
exit;
break;
}
move_uploaded_file($file, $folderPath. $fileNewName. ".". $ext);
$Coupons = $folderPath + "/"+ $fileNewName. ".". $ext;
$CouponsNom = $fileNewName. ".". $ext;
$CouponThumb =$fileNewName. "_thump.". $ext;
//$product_cat = $product_folder;
//insert client
mysqli_query($DBcon,"INSERT INTO Coupon_list (product_name,product_desc,product_code,product_date_exp,product_user,
product_image,product_image_thumb,product_status,product_qty,product_folder,product_cat,product_type,product_month)
VALUES ('$fileNewName','$product_desc','$product_code','$product_date_exp','$User',
'$CouponsNom','$CouponThumb','$status','$product_qty','$product_folder','$product_cat','$product_type','$product_month')");
//echo "Image Resize Successfully. to $folderPath";
echo "<meta http-equiv=Refresh content=1;url=Upload.php?success=1>";
}
}
function imageResize($imageResourceId,$width,$height) {
$targetWidth =200;
$targetHeight =200;
$targetLayer=imagecreatetruecolor($targetWidth,$targetHeight);
imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$targetWidth,$targetHeight, $width,$height);
return $targetLayer;
}
?>
我可以用一个简单的旋转脚本来解决我的问题。我调用它来旋转图片并将名称保存回我的数据库中。
$degrees = -270;
$path = $_GET['Folder'];
$file =$_GET['Pic'];
$fileid =$_GET['id'];
$image = $path.'/'.$file;
$imageN = $path.'/New_'.$file;
//load the image
$source = imagecreatefromjpeg($image);
//rotate the image
$rotate = imagerotate($source, $degrees, 0);
$NewImg='New_'.$file ;
//set the Content type
//header('Content-type: image/jpeg');
//display the rotated image on the browser
//imagejpeg($rotate);
imagejpeg($rotate,$imageN,100);
//free the memory
imagedestroy($source);
imagedestroy($rotate);
保存的东西在这里
【问题讨论】:
-
请展示您的代码,以便人们查看您使用的是 GD、ImageMagick、GraphicsMagick 还是 php_vips 来旋转你的图片。
-
我没有使用任何东西来旋转图像。但我会编辑.thx
-
见us1.php.net/manual/en/imagick.getimageorientation.php。不幸的是,我没有看到命令行 -auto-orient 的等效项。所以你必须得到方向并做一个条件来旋转正确的量。