note 110894 added to function.exif-read-data

From: Date: Thu, 20 Dec 2012 13:34:33 +0000
Subject: note 110894 added to function.exif-read-data
Groups: php.notes 
Request: Send a blank email to php-notes+get-192614@lists.php.net to get a copy of this message
When the new update came out from Apple for iOS6 it provided the ability for iPad, iPod, and iPhones to be able to upload files from the device through Safari. Obviously this will open up an array of implementations where at one point it was just not possible. The issue comes when a photo is uploaded it will be dependent on the location of the "button" when the photo was taken. Imagine if you will that you have your iPhone turned with the button at the top and you take a photo. The photo when uploaded to your server might be "upside down". The following code will ensure that all uploaded photos will be oriented correctly upon upload: <?php $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name'])); $exif = exif_read_data($_FILES['image_upload']['tmp_name']); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: $image = imagerotate($image,90,0); break; case 3: $image = imagerotate($image,180,0); break; case 6: $image = imagerotate($image,-90,0); break; } } // $image now contains a resource with the image oriented correctly ?> What you do with the image resource from there is entirely up to you. I hope that this helps you identify and orient any image that's uploaded from an iPad, iPhone, or iPod. Orientation for the photo is the key to knowing how to rotate it correctly. ---- Server IP: 69.147.83.199 Probable Submitter: 209.195.135.122 ---- Manual Page -- http://php.net/manual/en/function.exif-read-data.php Edit -- https://master.php.net/note/edit/110894 Del: integrated -- https://master.php.net/note/delete/110894/integrated Del: useless -- https://master.php.net/note/delete/110894/useless Del: bad code -- https://master.php.net/note/delete/110894/bad+code Del: spam -- https://master.php.net/note/delete/110894/spam Del: non-english -- https://master.php.net/note/delete/110894/non-english Del: in docs -- https://master.php.net/note/delete/110894/in+docs Del: other reasons-- https://master.php.net/note/delete/110894 Reject -- https://master.php.net/note/reject/110894 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192614) next »