是否可以获取不在 DOM 中的图像的高度/宽度?
是否可以使用 JavaScript 获取文件系统中图像的高度和宽度(即不属于 DOM 的图像)?或者我是否必须使用 JavaScript 将图像注入 DOM 并以这种方式获取尺寸?
我问这个问题是因为我正在编写一个 JavaScript 方法来动态渲染 Raphaël 生成的 UI 组件,该方法将三个图像路径作为方法参数的一部分。然后将它们用于渲染上述 UI 组件,并且我需要图像的尺寸来进行定位。
提前致谢。
Is it possible to get the height and width of an image in the file system using JavaScript (i.e. an image that is not part of the DOM)? Or would I have to use JavaScript to inject the image into the DOM and grab the dimensions that way?
I ask because I'm writing a JavaScript method to render a UI component on the fly generated by Raphaël, which takes three image paths as part of the method parameters. These are then used to render the aforementioned UI component, and I need the dimensions of the images for positioning purposes.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为只要图像已加载,您就可以获取宽度和高度 - 不过您不必将其注入到 DOM 中。例如:
I think as long as the image has loaded you can grab the width and height - you shouldn't have to inject it into the DOM though. For example:
你不一定能到达“文件系统”,但你可以这样做:
你会把它算作“添加到 DOM”吗?
You cannot necessarily get to "the file system", but you can do this:
Would you count that as "adding to the DOM"?
您可以使用代码下载图像:
You can download image with code:
是否可以使用 JavaScript 获取文件系统中图像的高度和宽度(即不属于 DOM 的图像)?
或者我必须使用 JavaScript 将图像注入 DOM 并以这种方式获取尺寸?
Is it possible to get the height and width of an image in the file system using JavaScript (i.e. an image that is not part of the DOM)?
Or would I have to use JavaScript to inject the image into the DOM and grab the dimensions that way?