81179

No orientation in exif data - PHP image upload

Question:

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.

Answer1:

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.

Answer2:

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.

Recommend

  • $_FILES is null, $_POST is not null
  • open last modified excel spreadsheet using vba
  • Can't call VBA built in function with Application.Run
  • Session flash messages only showing after a separate refresh and not on POST in express
  • $_FILES i don't recive all the information from the form
  • How to sequence events in PHP for uploading files to amazon S3
  • No orientation in exif data - PHP image upload
  • How to get DateTime stamp of a textfile using VB 6
  • Vim and snipMate (plugin) - adding new snippet won't work
  • Compressing UTF-8(or other 8-bit encoding) to 7 or fewer bits
  • Save mail with subject as filename
  • “EntityCollection already initialized” error with entity as model in Asp.Net MVC?
  • UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb9 in position 14: invalid star
  • PHP can't upload file from HTML form
  • My javascript web workers are dying silently at random places. How can I debug this?
  • urllib2 returns a different page the browser does?
  • Need tricky idea to use JS variable in php
  • Java: Issue with available() method of BufferedInputStream
  • jQuery not recognizing Symfony JSON?
  • Stored data can't access in Yii
  • Is there a MySQL query that can encode to JSON in exactly this way?
  • FCM on app closed
  • Get uniq random lines from file and write them to another file using php
  • getElementsByClassName and AJAX
  • get iframe content as string
  • List images(01.png) and descriptions(01.txt) from directory
  • how to upload multiple files in c# windows application
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • json Serialization in asp
  • reshape alternating columns in less time and using less memory