PHP Orientation property to determine whether the upload picture needs to rotate _php instance

Source: Internet
Author: User

When you use an Apple iOS system to photograph and upload images, you may experience a problem with the image being rotated, depending on the position of the camera button when you take the picture. Let's say you rotate your phone around the bottom while you're taking a picture, and the picture is rotated.

The following code will ensure that all uploaded photos are correctly directed as they are 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, Android photographed the Orientation property is 1, can not determine whether it was 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.