简体   繁体   English

如何避免在Angle 4应用中旋转图像

[英]How to avoid image rotation in angular 4 app

I have an angular application that allows you to choose a profile picture. 我有一个角度应用程序,可让您选择个人资料图片。 Performing tests I noticed that when I take images from an iPhone in portrait mode and upload the image to my app it is shown rotated, however if I take the photo in landscape mode the image shows correctly. 执行测试时,我注意到当我以肖像模式从iPhone拍摄图像并将其上传到我的应用程序时,图像显示为旋转,但是如果以横向模式拍摄照片,则图像可以正确显示。 Additionally, perform this same test on an android device, and the result is that both in portrait mode or landscape mode the image shows correctly. 此外,在android设备上执行相同的测试,结果是无论在纵向模式还是横向模式下,图像都能正确显示。 My question is how to avoid this behavior since I want the images to always be displayed without rotations. 我的问题是如何避免这种行为,因为我希望图像始终显示为不旋转。 Below is an example of the problem mentioned: 下面是提到的问题的一个示例:

在此处输入图片说明

All images uploaded should be displayed this way: 上传的所有图像应以这种方式显示:

在此处输入图片说明

I check the files uploaded from ios physically on the server and none of them are rotated. 我从服务器上物理检查了从ios上传的文件,但这些文件都没有旋转。 The problem seems to be the visualization from the app. 问题似乎出在应用程序的可视化上。

What should I do so that the images are always displayed without rotation from my angular application? 我应该怎么做才能使图像始终显示为不受角度应用程序的旋转?

I have done a stackblitz to show the implementation made for this component 我已经做了一个堆栈闪电展示该组件的实现

stackblitz 突击

I appreciate that someone can help me, and explain to me why this strange behavior is due. 我感谢有人可以帮助我,并向我解释为什么这种奇怪的行为是应有的。

Many Thanks! 非常感谢!

The problem here is with something called EXIF data. 这里的问题在于所谓的EXIF数据。 This is an extra set of metadata captured with the image which has location, time, apereture but also orientation . 这是用图像捕获的额外的元数据集,具有位置,时间,孔径和orientation

If you want to display the image correctly after uploading it to the server, you could simply rotate the image based on the exif orientation, and then strip the exif data. 如果要在将图像上传到服务器后正确显示图像,则可以简单地根据exif方向旋转图像,然后剥离exif数据。 This way, the image is always displayed "correctly", both in browsers that understand EXIF and browsers that don't. 这样,在理解EXIF的浏览器和不了解EXIF的浏览器中,图像始终“正确”显示。 This is explained here: Fix iOS picture orientation after upload PHP 此处说明: 上载PHP后修复iOS图片方向

If you want to display the image correctly before uploading (eg preview), your best bet is using a HTML canvas and then rotating the image based on it's orientation. 如果要在上之前正确显示图像(例如预览),最好的选择是使用HTML画布,然后根据其方向旋转图像。 Please see this topic for more information: JS Client-Side Exif Orientation: Rotate and Mirror JPEG Images 请参阅本主题以获取更多信息: JS客户端Exif方向:旋转和镜像JPEG图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM