图像旋转

时间:2017-01-06 11:46:51

标签: php jquery

我有一个非常奇怪的问题。

在我的网站上有一个文件字段,允许用户上传他们的个人资料图片。

使用JQuery上传,然后使用PHP保存。

如果我从PC / MAC / iPhone上传,那么没有任何问题,但是如果我使用Android设备上传图像就会轮换。

旋转不均匀,可能是90%180%或270%,这是在拍摄图像或从图库中选择时发生的。

为什么会这样?并且有可能解决吗?

1 个答案:

答案 0 :(得分:0)

这解决了问题

来自PHPDocs

<?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
?>
相关问题