While iPhones and many modern cameras save images with orientation information in their EXIF data, the correct display of these images can sometimes be an issue on other devices or in browsers. Being aware of this and employing the appropriate solutions can help ensure that images are displayed correctly across various platforms. Here is a PHP code snippet that allows you to rotate an image based on its EXIF orientation data, using the GD library in PHP.
Source code viewer
function exif_orientation_rotate($file_path, $file_mime) { // Ensure that the Orientation key|value exists, otherwise leave. return; } // Orientation numbers and corresponding degrees. // @note: Odd numbers are flipped images, would need different process. switch ($file_exif['Orientation']) { case 3: $degrees = 180; break; case 6: $degrees = 90; break; case 8: $degrees = 270; break; default: $degrees = 0; } if ($degrees > 0) { // Load the image object for manipulation. $file_image = image_load($file_path); if (image_rotate($file_image, $degrees, 0xffffff)) { image_save($file_image); } } } }Programming Language: PHP