图像获取有关上传自动旋转 [英] Image getting rotated automatically on upload

查看:109
本文介绍了图像获取有关上传自动旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传一个base64连接codeD映像并解码后保存。图片是越来越上传并保存,我可以使用URL访问和everything..but的形象得到了90度逆时针旋转,我不知道为什么!

I'm trying to upload a base64 encoded image and save after decoding it. Image is getting uploaded and saved, and I can access it using a URL and everything..but the image gets rotated by 90 degrees anti-clockwise and I have no idea WHY!!

在那里我得到的EN codeD数据是好的,将它放在&LT的地方; IMG /&GT; <!/ code>正常工作

The place where I get the encoded data is fine, as putting it in <img /> works fine!

function saveImageData($base64Data) {
    $base64_decoded = base64_decode($base64Data);
    $im = imagecreatefromstring($base64_decoded);
    if ($im !== false) {
        $imagepath = '/public/uploads/' . time() . '.jpg';
        imagejpeg($im, $imagepath);
        chmod($imagepath, 0755);
        imagedestroy($im);
    } else {
        return false;
    }
    return $imagepath;
}

我不使用任何旋转的功能,但它仍然得到旋转。我可以使用PHP的GD函数一样imagerotate,但不希望像黑色的背景等原因。

I'm not using any rotation functions, but still its getting rotated. I can use a PHP GD function like imagerotate, but don't want to for reasons like black backgrounds etc.

如果你能help..you r是awesomest人!

If you can help..you r the awesomest person!!

推荐答案

我的猜测是,你要上传的图像实际上是旋转,但被纠正,因为它包含在它的EXIF部分旋转数据。 (例如,照相机可以拍摄照片时意识到纵向的,并保存在EXIF数据的信息;观看时它的一些观看软件知道旋转数据,并会自动旋转的照片)。在这种情况下,图像可能只是的出现的进行旋转你,取决于你使用,以查看它的内容。

My guess would be that the image you're uploading is actually rotated, but is being corrected because it contains rotation data in its EXIF section. (For example, a camera may be aware of portrait orientation when taking a photo, and save that information in the EXIF data; some viewing software is aware of the rotation data and will auto-rotate the photo when viewing it.) In which case, the image might just be appearing to be rotated for you, depending on what you're using to view it.

您使用相同的软件查看上传之前和上传之后的图像?会发生什么,如果你看一下他们两个使用相同的Web浏览器,说什么?

Are you viewing the "before upload" and "after upload" images using the same software? What happens if you look at them both using the same web browser, say?

如果你从不同的来源尝试不同的形象,preferably会发生什么?你有什么软件,让您查看图片的EXIF数据?寻找方向的价值;任何超过1,其他意味着有在图像设置旋转(请参见此页面一个体面的说明。)

What happens if you try a different image, preferably from a different source? Do you have any software that will allow you to view the image's EXIF data? Look for the "Orientation" value; anything other than "1" means there's a rotation set for the image (see this page for a decent description.)

所以,总的来说,我会说,在JPEG文件的基本形象是在错误的方向和EXIF数据中包含的信息来修正显示的旋转。这极有可能是如果源是,例如,一个iPhone,它刚刚演奏与矿,似乎存储横向的底层图像数据,但是,如果该图像被实际采取设置EXIF数据(因此应显示)人像。

So, in summary, I'd say that that the underlying image in the JPEG file is at the "wrong" orientation, and the EXIF data contains information to correct that rotation for display. This is very likely if the source is, for example, an iPhone, which having just played with mine, seems to store its underlying image data in landscape orientation, but set the EXIF data if the image was actually taken (and should therefore be displayed) as portrait.

要解决这个问题最好的办法是几乎可以肯定的检查上上传后该文件的EXIF数据,使用的 PHP的EXIF功能和旋转图像作为所需的保存自己的副本之前,纠正方向。

Best way to fix it is almost certainly to examine the EXIF data on the file after upload, using the PHP EXIF functions and rotate the image as necessary to correct the orientation before saving your own copy.

这篇关于图像获取有关上传自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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