直接从iPad上传到网站时,Ipad照片不会旋转,但从计算机上传时可以正常 [英] Ipad photos not rotated when uploaded to a website directly from iPad but ok when uploaded from the computer

查看:110
本文介绍了直接从iPad上传到网站时,Ipad照片不会旋转,但从计算机上传时可以正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个PHP网站,当我以纵向模式上传从ipad拍摄的照片时,它会在网站上以横向显示,但是当我从计算机上传相同的照片时(不对其进行任何更改)照片)它在横向模式下正确显示。所有风景照片都以横向方式显示。

I'm developing a PHP website, and when I upload a photo taken from the ipad in portrait mode, it appears in landscape on the website, yet when I upload the very same photo from the computer (no changes made to the photo) it appears correctly in landscape mode. All landscape photos appear in landscape orientation just fine.

我试图找到解决此问题的方法,并阅读有关从EXIF数据获取方向的信息,但是orientation标签实际上总是相同的(如果我没记错的话,是1)照片是以横向还是纵向拍摄的。

I've tried to find a way to fix this, and read about getting the orientation from the EXIF data, but the "orientation" tag is actually always the same (1 if I remember correctly) whether the photo has been taken in landscape or portrait.

我试图上传一幅肖像从ipad flickr的照片,它在肖像模式下正确显示,所以我错过了什么?

I've tried to upload a portrait photo to flickr from the ipad and it appears correctly in portrait mode, so what am I missing?

谢谢。

推荐答案

取自 http://www.php.net/manual/en/function.exif-read-data.php#110894
来源:gds dot com的chadsmith729。

Taken from http://www.php.net/manual/en/function.exif-read-data.php#110894 Credit: chadsmith729 at gmail dot com.

我自己没有测试过这个解决方案..

I haven't tested this solution myself..

<?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
?>

这适用于所有Apple产品(iPod,iPhone和iPad)

This should work with all Apple products (iPod, iPhone and iPad)

这篇关于直接从iPad上传到网站时,Ipad照片不会旋转,但从计算机上传时可以正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆