Javascript 如何在Chrome 81+中忽略画布上的图像exif数据;

Javascript 如何在Chrome 81+中忽略画布上的图像exif数据;,javascript,html,css,google-chrome,html5-canvas,Javascript,Html,Css,Google Chrome,Html5 Canvas,当我在Chrome 81+中调用context.drawImage时,它会自动旋转图像。我想禁用这个。我可以使用图像方向:none在img标记中禁用它,但在画布上不起作用 它似乎忽略了图像方向样式。在下面的示例中,img标记不会自动旋转(如预期的那样),但画布会自动旋转,尽管尝试禁用它 如何防止drawImage基于exif数据旋转,或者至少检测到它已旋转 <html> <head> <script> window.onload = funct

当我在Chrome 81+中调用
context.drawImage
时,它会自动旋转图像。我想禁用这个。我可以使用
图像方向:none
在img标记中禁用它,但在画布上不起作用

它似乎忽略了图像方向样式。在下面的示例中,img标记不会自动旋转(如预期的那样),但画布会自动旋转,尽管尝试禁用它

如何防止
drawImage
基于exif数据旋转,或者至少检测到它已旋转

<html>
<head>
    <script>
    window.onload = function() {
      var c = document.getElementById("myCanvas");
      var ctx = c.getContext("2d");
      var img = document.getElementById("imgtest");
      // This style is ignored
      img.style.imageOrientation = 'none';
      ctx.drawImage(img, 0, 0);
    };
    </script>
</head>
<body>
    <p>
        <img id="imgtest" style="image-orientation:none;" src="portrait.jpg"/>
        <canvas id="myCanvas" width="240" height="297"></canvas>    
    </p>
</body>
</html>

window.onload=函数(){
var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
var img=document.getElementById(“imgtest”);
//此样式被忽略
img.style.imageOrientation='none';
ctx.drawImage(img,0,0);
};


我找到了解决自己问题的方法。我正在使用功能检测库modernizr.com查找出的浏览器将自动旋转图像

if(Modernizr.exiforientation) {
  // Browser does the image rotation
} 
我更喜欢一个不需要新库的解决方案,但这是可行的