exif数据没有方向 – PHP图像上传

我一直试图从iPhone上检测上传图像的图像方向,然后从中调整它们的方向。

我正在尝试解决在potrait中拍摄的图像以-90度旋转上传的问题。 我尝试了许多无效的switch语句,所以决定在我的JSON返回中返回exif数据。

我看到的问题是它们在exif数据中没有方向。

我这样做:

$imagefile = $fileToUpload["tmp_name"]; $destinationImage = imagecreatefromstring(file_get_contents($imagefile)); $exif = exif_read_data($imagefile); $moveUploadedFile = imagejpeg($destinationImage, $this->uploadDir . "/" . $newFileName, 100); imagedestroy($destinationImage); if ($moveUploadedFile) { $return['ort'] = $exif; echo json_encode($return); } 

我在回归中看到的(使用萤火虫)是:

 FileName:"phpUQZFHh" FileDateTime:1410465904 FileSize:473421 FileType:2 MimeType:"image/jpeg" SectionsFound:"COMMENT" Computed: OBJECT: Height:700 Width:933 IsColor:1 Comment: ARRAY: 0:"CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 100" 

我希望能够像这样使用exif数据:

  if (!empty($exif['Orientation'])){ //get the orientation $ort = $exif['Orientation']; //determine what oreientation the image was taken at switch($ort){ case 2: // horizontal flip break; case 3: // 180 rotate left $destinationImage = imagerotate($destinationImage, 180, -1); break; } } 

有帮助吗?

编辑:下载了已上传的图像并检查其属性后,似乎在上传过程中删除了所有exif数据。

这仍然让我感到困惑的是为什么它在上传之前/期间轮换/如何解决这个问题。

我想在您从iOS设备上传图片时,exif_read_data函数的返回数据中会显示“Orientation”值。 它不适用于桌面浏览器。 我可能错了。

我遇到了同样的问题。 事实certificate一些图像根本没有关于Orientation任何exif数据 – 通常具有“正确”方向的图像没有它。 我试过用iPhone拍摄的一张风景照片。

在您的情况下,照片可能首先没有exif数据。 我也有一些这样的照片(旋转-90度,但没有Orientation信息)。 我可能是错的,但没有exif数据,没有编程方式来知道图像是否错误定向。

对于没有Orientation信息的错误定向照片,我建议您确保用户看到(预览)要上传的内容。 IME,大多数用户都非常愿意为了解决油漆/ photoshop /等问题。 只是为了确保他们有漂亮的照片。