【发布时间】:2014-11-05 22:01:15
【问题描述】:
一直在尝试检测从 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 数据。
这仍然让我感到困惑,为什么它在上传之前/上传期间/如何解决这个问题。
【问题讨论】:
-
你为什么要在这里创建一个新的 GD-lib 映像,而不是使用原始上传的未修改文件?如果您只得到一行 EXIF 数据,说明该图像是使用 GD 创建的,那么这很可能是您丢失原始 EXIF 数据的步骤。
-
第一次使用GD和图片上传所以我很抱歉,但不明白你的回复。如果图像数据被删除,那很好,但问题是肖像拍摄的图像在上传时仍会旋转。我在哪里修改代码中的图像而不是使用原始文件?
标签: php ios image-processing gd exif