PHPにおけるOrientation属性はアップロード画像が回転する必要があるかどうかを判断する

697 ワード

<?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で、回転されたかどうかは判断できません.