Ipad photos not rotated when uploaded to a website directly from iPad but ok when uploaded from the computer

假如想象 提交于 2020-01-03 15:59:11

问题


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.

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.

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?

Thanks.


回答1:


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

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



来源:https://stackoverflow.com/questions/13509650/ipad-photos-not-rotated-when-uploaded-to-a-website-directly-from-ipad-but-ok-whe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!