No orientation in exif data - loading image from PHP

tried to detect the image orientation of downloaded images from iPhone and then adjust their orientation.

I am trying to fix an issue where images taken in a potrait are loaded with a rotation of -90 degrees. I tried a lot of switch statements that didn't work, so decided to return the exif data in my JSON return.

The problem I see is that they are not orientation in exif data.

I am doing this:

$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 see 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 use exif data like this:

    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 loading the uploaded image and checking its properties, it appears that all exif data has been removed during the upload process.

It still puzzles me why it spins before / at boot time / how to fix it.

+3


source to share


2 answers


I am assuming that the Orientation value is present in the return data of exif_read_data in case you are loading an image only from an iOS device. It won't work in a desktop browser. Maybe I'm wrong.



0


source


I faced the same problem. It turns out that some images don't really have any exif data at Orientation

all - usually those with the "correct" orientation don't have it. I tried one album made with iPhone and it was.

In your case, the photos may not have had any exif data. I also had some photos (rotated 90 degrees, but no Orientation

info). I could be wrong, but without exif data, there is no programmatic way to tell if the image is oriented incorrectly.



For misdirected photos without Orientation

info, I suggest you just make sure the user sees (gets a preview) of what will be loaded. IME, most users are more than willing to go out of their way to run paint / photoshop / etc. just to make sure they have beautiful photos.

0


source







All Articles