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

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

  1. <?php
  2. $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
  3. $exif = exif_read_data($_FILES['image_upload']['tmp_name']);
  4. if(!empty($exif['Orientation'])) {
  5. switch($exif['Orientation']) {
  6. case 8:
  7. $image = imagerotate($image,90,0);
  8. break;
  9. case 3:
  10. $image = imagerotate($image,180,0);
  11. break;
  12. case 6:
  13. $image = imagerotate($image,-90,0);
  14. break;
  15. }
  16. }
  17. // $image now contains a resource with the image oriented correctly
  18. ?>

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

相关评论(0)
您是不是忘了说点什么?

友情提示:垃圾评论一律封号...

还没有评论,快来抢沙发吧!