exif数据中没有方向-PHP图像上载
一直在尝试检测iPhone上传图像的图像方向,然后根据该方向调整它们的方向 我正试图解决在potrait拍摄的图像以-90度旋转上传的问题。我尝试了许多不起作用的switch语句,因此决定在JSON返回中返回exif数据 我看到的问题是,它们在exif数据中没有方向 我正在这样做:exif数据中没有方向-PHP图像上载,php,ios,image-processing,gd,exif,Php,Ios,Image Processing,Gd,Exif,一直在尝试检测iPhone上传图像的图像方向,然后根据该方向调整它们的方向 我正试图解决在potrait拍摄的图像以-90度旋转上传的问题。我尝试了许多不起作用的switch语句,因此决定在JSON返回中返回exif数据 我看到的问题是,它们在exif数据中没有方向 我正在这样做: $imagefile = $fileToUpload["tmp_name"]; $destinationImage = imagecreatefromstring(file_get_contents($imagefi
$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);
}
我在我的回报(使用firebug)中看到的是:
我希望能够像这样使用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函数返回的数据中会出现“方向”值。它在桌面浏览器中不起作用。我可能错了。我遇到了同样的问题。事实证明,有些图像实际上根本没有任何关于
方向的exif数据,通常方向“正确”的图像没有。我试过一张用iPhone拍摄的风景图片,结果发现有
在您的情况下,这些照片一开始可能没有exif数据。我也有一些这样的照片(旋转-90度,但没有方向)。我可能是错的,但如果没有exif数据,就无法通过编程方式知道图像的方向是否错误
对于没有Orientation
info的定向错误的照片,我建议您只需确保用户看到(获得预览)将要上传的内容。在IME中,大多数用户都非常愿意不厌其烦地启动paint/photoshop/等,只是为了确保他们拥有好看的照片。在将文件移动到服务器目录之前,您可以获得方向
值(也适用于iPhone)
为什么要在这里创建一个新的GD-lib映像,而不是只使用原始上传的未修改文件?如果您只收到一行EXIF数据,表明图像是使用GD创建的,那么这可能是您丢失原始EXIF数据的步骤。第一次使用GD和图像上载,因此我很抱歉,但不清楚您的答复。如果图像数据被删除,那就没问题了,但问题是上传时拍摄的肖像图像仍然会旋转。我在哪里修改代码中的图像而不是使用原始文件?嗨,John。仅需确认,方向
,即使图像未从iOS设备上传,也会显示。
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;
}
}
$image = $_FILES["image"]["tmp_name"];
$orientation = '';
if (function_exists('exif_read_data'))
{
$exif = exif_read_data(image);
if($exif && isset($exif['Orientation']))
$orientation = $exif['Orientation'];
}