Home >Backend Development >PHP Tutorial >The Orientation attribute in PHP determines whether the uploaded image needs to be rotated, _PHP tutorial

The Orientation attribute in PHP determines whether the uploaded image needs to be rotated, _PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 09:07:101101browse

The Orientation attribute in PHP determines whether the uploaded image needs to be rotated.

When using Apple’s iOS system to take photos and upload images, you may encounter the problem of the image being rotated. This is mainly It depends on the position of the photo button when you take a photo. If you rotate the phone with the bottom facing up when taking a photo, the photo will also be rotated.

The following code will ensure that all uploaded photos are oriented correctly when uploaded:

<&#63;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
&#63;>

After testing, the Orientation attribute of Android photos is all 1, and it cannot be determined whether it has been rotated.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1062032.htmlTechArticleThe Orientation property in PHP determines whether the uploaded image needs to be rotated. When using Apple's iOS system to take photos and upload images, it may You will encounter the problem of the image being rotated, which mainly depends on...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn