When using Apple's iOS system to take pictures and upload pictures, you may encounter the problem of the picture being rotated, which mainly depends on the position of the photo button when you take pictures. Suppose you rotate your phone over and the bottom is facing up when taking a photo, the photos taken will also be rotated.
The following code will ensure that all uploaded photos are correctly uploaded when uploading:
<?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 ?>
After testing, the Orientation attributes of Android photography are all 1, and it is impossible to determine whether it has been rotated.