当用户注册图像时。现在我要做的就是旋转他上传的图片,我只需要获取所有带有名称和图像的用户。当获取用户的详细信息时,这就是我需要图像进行正确旋转的事情。用户上传的是风景还是其他天使,我都希望它正确。我尝试了很多方法,例如 exif_read_data ,但是它在最新的php中不起作用,当我尝试使用旧版本的php时,出现错误 IFD大小非法 >。是他们的另一种方法。让我们来编写代码。
<?php
$host="localhost";
$uname="root";
$upass="";
$link=mysqli_connect($host,$uname,$upass,"test");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
var table = $('#example').DataTable();
} );
</script>
</head>
<body>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Salary</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<?php
$sql="select * from imageproblem";
$result=mysqli_query($link,$sql) or die('mysqli error:query is wrong');
while($row=mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td>';
echo $row['id'];
echo '</td>';
echo '<td>';
echo $row['name'];
echo '</td>';
echo '<td>';
echo $row['salary'];
echo '</td>';
$destination='images/'.$row['image'];
$exif = exif_read_data($destination);
if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 8:
$command = 'mogrify -rotate "90" -auto-orient ' . $destination;
exec("$command");
break;
case 3:
$command = 'mogrify -rotate "180" -auto-orient ' . $destination;
exec("$command");
break;
case 6:
$command = 'mogrify -rotate "-90" -auto-orient ' . $destination;
exec("$command");
break;
}
}
echo '<td>';
echo '<img src="images/'.$row['image'].'" width="50" />';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</body>
</html>