I have an issue with iOS Photo recently not being displayed properly after uploading. After googling around, I’ve managed to found a workaround for this issue.
Imagine this scenario: You have a working website with file uploader and then strange phenomenon happens when you upload a photo from iPhone in portrait. The photo is uploaded properly, but the orientation is landscape.
What is the problem with iOS Photo?
The problem was that image rotation was added to the photo as EXIF data not used by most browsers. If you’re using CodeIgniter, you can use CodeIgniter’s Image_lib library to help you fix this.
Solving the Rotation Issue with CodeIgniter Image_lib
Open your controller file or the file where you handle the image after upload. Add the below code to rotate the image and replace it in the same file destination.
Please note that you might have different requirements hence need to change any parts of the code to your needs.
// Assuming that you store your file in this variable
$filename = "yourimagefile.jpg";
// Resize the image
$config['image_library'] = 'gd2';
$config['source_image'] = $filename;
$config['new_image'] = $filename;
// -- Check EXIF
$exif = exif_read_data($config['source_image']);
if($exif && isset($exif['Orientation']))
$ort = $exif['Orientation'];
if ($ort == 6 || $ort == 5)
$config['rotation_angle'] = '270';
if ($ort == 3 || $ort == 4)
$config['rotation_angle'] = '180';
if ($ort == 8 || $ort == 7)
$config['rotation_angle'] = '90';
if ( ! $this->image_lib->rotate())
// Error Message here
Now all images from iOS devices (iPhone and iPad) should display properly.