上传时 Laravel 正在旋转图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50277697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel is rotating the image when uploaded
提问by Wai Yan Hein
I am developing a web application that involves the feature of uploading image to server. I am using Laravel. The problem is when I upload a photo, Laravel is rotating the image.
我正在开发一个 Web 应用程序,它涉及将图像上传到服务器的功能。我正在使用 Laravel。问题是当我上传照片时,Laravel 正在旋转图像。
This is my code to upload image file.
这是我上传图像文件的代码。
$request->file('image_file')->store('images');
Just one line of code for uploading the image.
只需一行代码即可上传图像。
I uploaded this image.
我上传了这张图片。
Then, the photo is rotated on the server and becomes like this. I display the image in the HTML tag.
然后,照片在服务器上旋转,变成这个样子。我在 HTML 标签中显示图像。
So, what is wrong. How can I stop the photo from being rotated?
那么,怎么了。如何阻止照片旋转?
回答by Adnan Mumtaz
This happen when you capture the image with Mobile camera.
当您使用移动相机拍摄图像时会发生这种情况。
you can see the image data using exif_read_data()
您可以使用exif_read_data()查看图像数据
But if you want to store it in an orignal way you can use intervention/image
package.
但是如果你想以一种原始的方式存储它,你可以使用intervention/image
package。
and use orientate()to change it. Here is an example
并使用orientate()来改变它。这是一个例子
$img = \Image::make($request->file('image_file')->getRealpath());
$img->orientate();
But if you dont want to use the Package
you can try
但如果你不想使用Package
你可以尝试
$exif = exif_read_data($request->file('image_file'));
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;
}
}
Hope this helps.
希望这可以帮助。
回答by ZDayla
i found an easy way to do it its work for me you just upload your image in google drive then download it again that s it if it doesnt work i m sorry but it s work for me
我找到了一个简单的方法来对我来说有效,你只需将你的图片上传到谷歌驱动器然后再次下载它如果它不起作用我很抱歉但它对我有用