javascript - 在全局变量中存储图像尺寸
问题描述
所以使用 papa parse,我将我的文件解析为本地 CSV 文件。因此,当我将更新的对象打印到控制台时,我让对象返回我根据某些条件应用的更改值。我的问题是获取图像尺寸:宽度和高度。
var w;
var h;
let testString = "s2345232";
if (/^[s]\d+$/.test(testString) == true) {
url = baseUrl + testString + suffix;
getMeta(url, function (width, height) {
w = width;
h = height;
console.log(w, h); //works
});
}
console.log(w, h); //doesn't work
//Here is the function to retrieve the image data
function getMeta(url, callback) {
var img = new Image();
img.src = url;
img.addEventListener("load", function () {
callback(this.naturalWidth, this.naturalHeight);
});
};
解决方案
推荐阅读
- powerbi - 使用同一列 DAX 中的日期进行日期差异
- quarkus - 如何将 GraalVM 原生镜像代理与 Quarkus 一起使用?
- c# - Ajax.BeginForm 向控制器操作 ASP.NET MVC 发送空值
- java - 如何使用 Spring WebClient 进行具有不同标头设置的后续调用?
- excel - 我需要在一行代码中添加文本(段落、粗体字等),但我找不到方法
- javascript - 将 p5 画布设置为父 div 的最大宽度
- java - 如何发现具有rabbitmq 消费者的服务器已关闭?
- vue.js - 如何使用带有原生 HTML 元素的 VUE 路由器作为组件?
- javascript - 匹配数组中所有可能的子串组合
- python - 通过子实例访问父类方法