In PHP, the Orientation attribute determines whether the uploaded image needs to be rotated. _ PHP Tutorial

Source: Internet
Author: User
In PHP, the Orientation attribute determines whether the uploaded image needs to be rotated ,. In PHP, the Orientation attribute determines whether the image to be uploaded needs to be rotated. when using the iOS system to upload images, the image may be rotated, this mainly depends on the Orientation attribute in PHP to determine whether the uploaded image needs to be rotated,

When using the iOS system to upload images, you may encounter image rotation problems. this is mainly determined by the location of the photo button when you take the image. 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.

The Orientation attribute in http://www.bkjia.com/PHPjc/1062032.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1062032.htmlTechArticlePHP determines whether to rotate the uploaded image. when using the iOS system of Apple to upload the image, the image may be rotated...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.