怎么在PHP中利用Orientation 属性判断上传的图片是否需要旋转

怎么在PHP中利用Orientation 属性判断上传的图片是否需要旋转

怎么在PHP中利用Orientation 属性判断上传的图片是否需要旋转?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

php有什么用

php是一个嵌套的缩写名称,是英文超级文本预处理语言,它的语法混合了C、Java、Perl以及php自创新的语法,主要用来做网站开发,许多小型网站都用php开发,因为php是开源的,从而使得php经久不衰。

<?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
?>

看完上述内容,你们掌握怎么在PHP中利用Orientation 属性判断上传的图片是否需要旋转的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!