脚本宝典收集整理的这篇文章主要介绍了如何在使用PHP上传图像之前检查/修复图像旋转,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我的HTML代码:
<form class="form-horizontal" method="post" enctyPE="multipart/form-data"> <div class="form-group"> <div class="col-md-9"> <div class="input-group"> <span class="input-group-BTn"> <span class="btn btn-default btn-file"> Choose img<input type="file" name="file" id="imginp"> </span> </span> </div> </div> </div> <button type="submIT">Send</button> </form>
我正在使用的PHP代码:
还返回错误:警告:imagerotate()期望参数1是资源,字符串在.
任何人都有这个场景的工作代码?
<?PHP $filename = $_FILES['file']['name']; $exif = exif_read_data($_FILES['file']['tmp_name']); if (!empty($exif['orientation'])) { switch ($exif['Orientation']) { case 3: $image = imagerotate($filename,-180,0); break; case 6: $image = imagerotate($filename,90,0); break; case 8: $image = imagerotate($filename,-90,0); break; } } imagejpeg($image,$filename,90); ?>
试试这个:
<?PHP $filename = $_FILES['file']['name']; $filePath = $_FILES['file']['tmp_name']; $exif = exif_read_data($_FILES['file']['tmp_name']); if (!empty($exif['Orientation'])) { $imageResource = imagecreatefromjpeg($filePath); // PRovided that the image is jpeg. Use relevant function otherwise switch ($exif['Orientation']) { case 3: $image = imagerotate($imageResource,180,0); break; case 6: $image = imagerotate($imageResource,0); break; case 8: $image = imagerotate($imageResource,0); break; default: $image = $imageResource; } } imagejpeg($image,90); ?>
不要忘记通过添加以下两行来释放内存:
imagedestroy($imageResource); imagedestroy($image);
以上是脚本宝典为你收集整理的如何在使用PHP上传图像之前检查/修复图像旋转全部内容,希望文章能够帮你解决如何在使用PHP上传图像之前检查/修复图像旋转所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。