一直在尝试检测从 iPhone 上传的图像的图像方向,然后据此调整它们的方向。
我正在尝试解决以肖像拍摄的图像以 -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 数据都在上传过程中被删除。
这仍然让我困惑为什么它在上传之前/期间旋转/如何解决这个问题。