IPad photos do not rotate when uploading to a website directly from the iPad, but normal when downloading from a computer

I am developing a PHP website, and when I upload a photo taken from the iPad in portrait mode, it appears in landscape orientation on the website, but when I upload the same photo from my computer (no changes made to the photo) is displayed in landscape mode. All landscape photos look in landscape orientation just fine.

I tried to find a way to fix this and read about getting the orientation from EXIF ​​data, but the “orientation” tag is always the same (1, if I remember correctly) whether the photo was taken in the landscape or in the portrait.

I tried to upload portrait photo to flickr from ipad and it displays correctly in portrait mode, so what am I missing?

Thanks.

+4
source share
1 answer

Taken from http://www.php.net/manual/en/function.exif-read-data.php#110894 Credit: chadsmith729 on gmail dot com.

I have not tested this solution myself.

<?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 ?> 

This should work with all Apple products (iPod, iPhone, and iPad).

+2
source

Source: https://habr.com/ru/post/1447690/


All Articles