问题描述
一直试图从iPhone上检测上传图片的图像方向,然后从中调整它们的方向。
been trying to detect the image orientation of uploaded images from iPhones and then adjust their orientation from that.
我正在尝试解决在potrait中拍摄的图像的问题,以-90度旋转上传。我尝试了许多无效的switch语句,因此决定在我的JSON返回中返回exif数据。
I am trying to fix the issue where images taken in potrait, are uploaded with a -90 degree rotate. I tried numerous switch statements which were not working, so decided to return the exif data in my JSON return.
我看到的问题是他们在exif中没有方向数据。
The issue i see is that their is no orientation in the exif data.
我这样做:
$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)是:
What i am seeing in my return (using firebug) is:
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数据:
I want to be able use the exif data like so:
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数据。
After downloaded an image that had been uploaded and checking its properties it appears that all exif data was removed in the upload process.
这仍然让我感到困惑的是为什么在上传/上传之前轮换它/如何解决这个问题。
This still baffles me as to why it is rotated before / during upload / how to fix this.
推荐答案
我遇到了同样的问题。事实证明一些图像确实没有任何exif数据 Orientation
- 通常具有正确方向的图像没有它。我尝试用iPhone拍摄一张风景图像,然后就有了。
I ran into the same problem. Turns out some images really did not have any exif data on Orientation
at all -- usually ones with the "correct" orientation do not have it. I tried one landscape image taken with an iPhone and there was.
在你的情况下,照片可能首先没有exif数据。我也有一些这样的照片(旋转-90度,但没有方向
信息)。我可能错了,但没有exif数据,没有编程方式可以知道图像是否定向错误。
In your case, the photos may have had no exif data in the first place. I had some photos like that as well (rotated -90 degrees but no Orientation
info). I could be wrong but without exif data, there's no programmatic way to know if an image is incorrectly oriented.
对于没有方向错误定向的照片
info,我建议您确保用户看到(预览)要上传的内容。 IME,大多数用户都非常愿意为了解决油漆/ photoshop /等问题。只是为了确保他们有漂亮的照片。
For incorrectly oriented photos without Orientation
info, I suggest you just make sure the user sees (gets a preview) of what about to be uploaded. IME, most users are more than willing to get out of their way to fire up paint/photoshop/etc. just to ensure they have good looking photos.
这篇关于exif数据没有方向 - PHP图像上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!