This article describes how to use php to determine whether to rotate images based on the orientation attribute of uploaded images. if you are interested, let's take a look at it. when using Apple's iOS system to upload images, the image may be rotated, depending on the location of the photo button when you take the photo. Assume that you rotate the mobile phone to the bottom up when taking the photo, and the photo is also rotated.
The following code ensures that all uploaded photos are correctly targeted when being uploaded:
<? 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 attribute of Android photos is 1, and it cannot be determined whether the image is rotated.