No orientation in exif data - PHP image upload

☆樱花仙子☆ 提交于 2019-12-23 12:46:05

问题


been trying to detect the image orientation of uploaded images from iPhones and then adjust their orientation from that.

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.

The issue i see is that their is no orientation in the exif data.

I am doing so:

$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);
}

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"

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;
        }
    }

Any help?

EDIT: 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.


回答1:


I guess the "Orientation" value presents in the returned data of exif_read_data function in case when you upload the picture from your iOS device only. It won't work in desktop browser. I might be wrong.




回答2:


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.

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.

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.



来源:https://stackoverflow.com/questions/25796170/no-orientation-in-exif-data-php-image-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!