我正在尝试上载图片旋转。但是我无法从图像读取Exif数据,并且旋转无法正常进行。我尝试了很多在Internet上找到的解决方案,但没有任何效果。有人可以帮我吗?
这是我的代码:
<?php
if(isset($_POST['rotate']))
{
$filename = $_FILES['image']['name'];
$tmp_name = $_FILES["image"]["tmp_name"];
$location = 'image/';
echo $exif = exif_read_data($tmp_name); // <----- Notice: Array to string conversion in C:\xampp\htdocs\test\novo\index.php on line 20
if (!empty($exif['Orientation'])) {
$source = imagecreatefromjpeg($tmp_name);
switch ($exif['Orientation']) {
case 3:
$image = imagerotate($source, 180, 0);
break;
case 6:
$image = imagerotate($source, -90, 0);
break;
case 8:
$image = imagerotate($source, 90, 0);
break;
default:
$image = $source;
}
$rotatedImage = imagejpeg($image, $filename, 90);
move_uploaded_file($tmp_name,$location.$rotatedImage);
echo "Success";
}
}
?>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" name="rotate" value="rotate" />
</form>
<table>
<tr><td>UploadImage</td>
<td height="500px" width="500px" align="center">
<img src="image/<?php echo $image; ?>" width="300px" height="300px" />
</td>
<td>RotateImage</td>
<td headers="500px" width="500px" align="center"><img src="rotated/<?php echo $image; ?>" width="300px" height="300px" /></td></tr>
</table>
</html>