Home > Article > Backend Development > PHP detects if the photo is upside down and rearranges the photo
When uploading images from Safari, it is possible that the photos obtained by your server are upside down (depending on the position of the photo button). The following code can ensure that all uploaded photos are in the correct position.
$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; } }
Related recommendations: "PHP Tutorial"
The above is the detailed content of PHP detects if the photo is upside down and rearranges the photo. For more information, please follow other related articles on the PHP Chinese website!