javascript创建大尺寸图像导致显示问题

标签 javascript

我用 javascript 读取大图并附加到文档中,图像是垂直的,大小为 3024 * 4032:

Here is the original image

这是我的代码:

var image = new Image()
image.onload = function () {
  var width = image.width
  var height = image.height
  document.body.appendChild(image)
  console.log('width: ' + width, 'height: ' + height)
}
image.src = 'images/01vertical.jpg'

但是输出了console.log:

width: 4032 height: 3024

并且图像水平显示:

Here is the display image

有没有人遇到过这个?我该如何解决?谢谢!

最佳答案

您可以旋转图像:

let image = new Image()
image.onload = function (e) {
    let width = image.width;
    let height = image.height;
    document.body.appendChild(image);
    let el = e ? e.target : window.event.srcElement;
    el.style.transform = 'rotate(+90deg)';
    console.log('width: ' + width, 'height: ' + height)
}
image.src = '/image/OeGAY.png'

关于javascript创建大尺寸图像导致显示问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44587800/

相关文章:

javascript - 在 ng-repeat 上下文中选择性使用 ng-show

javascript - 改进 $(document).ready 和 $( window ).resize 并使其更紧凑

javascript - 如何使网站正文标签内的内容完全可扩展?

javascript - 通过浏览器的 "BACK"函数加载页面时触发 onload 脚本(js 或 jQuery)

javascript - 在 Chrome 扩展程序中创建自定义事件的最惯用方法

javascript - 动态添加成员到对象

javascript - 通过 python 套接字将 JSON 传递给 Javascript

php - Mootools ajax 请求

javascript - 如何创建没有成员名称的 JavaFX WebBrowser javascript 监听器

JavaScript 对象 indexOf,返回父位置?