orientation属性 PHP 中 Orientation 属性判断上传图片是否需要旋转

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

orientation属性 PHP 中 Orientation 属性判断上传图片是否需要旋转

  2021-03-20 我要评论
想了解PHP 中 Orientation 属性判断上传图片是否需要旋转的相关内容吗,在本文为您仔细讲解orientation属性 的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:orientation属性,orientation,下面大家一起来学习吧。

当使用苹果的iOS系统拍照上传图片的时候,可能会遇到图片被旋转的问题,这主要是取决于你拍照时拍照按钮的位置。假设拍照时你把手机旋转过来底部朝上,那拍出来的照片也是被旋转了的。

下面的代码将确保所有上传的照片在上传时都能是正确定向:

<?php
$image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
 switch($exif['Orientation']) {
  case 8:
   $image = imagerotate($image,90,0);
   break;
  case 3:
   $image = imagerotate($image,180,0);
   break;
  case 6:
   $image = imagerotate($image,-90,0);
   break;
 }
}
// $image now contains a resource with the image oriented correctly
?>

经测试,Android拍照的 Orientation 属性都是1,判断不出是否被旋转了。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们