PHP 中 Orientation 屬性判斷上傳圖片是否須要旋轉(轉)

<?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,判斷不出是否被旋轉了。php

相關文章
相關標籤/搜索