PHP 中 Orientation 属性判断上传图片是否需要旋转,_PHP教程

WBOY
Release: 2016-07-12 09:07:10
Original
1025 people have browsed it

PHP 中 Orientation 属性判断上传图片是否需要旋转,

当使用苹果的iOS系统拍照上传图片的时候,可能会遇到图片被旋转的问题,这主要是取决于你拍照时拍照按钮的位置。假设拍照时你把手机旋转过来底部朝上,那拍出来的照片也是被旋转了的。

下面的代码将确保所有上传的照片在上传时都能是正确定向:

<&#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;>
Copy after login

经测试,Android拍照的 Orientation 属性都是1,判断不出是否被旋转了。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1062032.htmlTechArticlePHP 中 Orientation 属性判断上传图片是否需要旋转, 当使用苹果的iOS系统拍照上传图片的时候,可能会遇到图片被旋转的问题,这主要是取决...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!