[英]Get width height of remote image from url
所以警报给出了未定义的宽度和高度值。 我认为来自 img.onload 计算的图像的 w 和 h 值没有传递给要返回的值,或者它可能在 onload 计算它们之前返回 w 和 h:
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
如何让警报显示正确的宽度和高度?
所以警报给出了宽度和高度的未定义值。 我认为来自 img.onload 计算的图像的 w 和 h 值没有传递给要返回的值,或者它可能在 onload 计算它们之前返回 w 和 h:
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
如何让警报显示正确的宽度和高度?
所以警报给出了宽度和高度的未定义值。 我认为来自 img.onload 计算的图像的 w 和 h 值没有传递给要返回的值,或者它可能在 onload 计算它们之前返回 w 和 h:
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
如何让警报显示正确的宽度和高度?
所以警报给出了宽度和高度的未定义值。 我认为来自 img.onload 计算的图像的 w 和 h 值没有传递给要返回的值,或者它可能在 onload 计算它们之前返回 w 和 h:
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
如何让警报显示正确的宽度和高度?
所以警报给出了宽度和高度的未定义值。 我认为来自 img.onload 计算的图像的 w 和 h 值没有传递给要返回的值,或者它可能在 onload 计算它们之前返回 w 和 h:
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
如何让警报显示正确的宽度和高度?
所以警报给出了宽度和高度的未定义值。 我认为来自 img.onload 计算的图像的 w 和 h 值没有传递给要返回的值,或者它可能在 onload 计算它们之前返回 w 和 h:
function getMeta(url){
var w; var h;
var img=new Image;
img.src=url;
img.onload=function(){w=this.width; h=this.height;};
return {w:w,h:h}
}
// "http://snook.ca/files/mootools_83_snookca.png" //1024x678
// "http://shijitht.files.wordpress.com/2010/08/github.png" //128x128
var end = getMeta("http://shijitht.files.wordpress.com/2010/08/github.png");
var w = end.w;
var h = end.h;
alert(w+'width'+h+'height');
如何让警报显示正确的宽度和高度?
您可以尝试package 。
import getImageSize from 'image-size-from-url';
const {width, height} = await getImageSize('URL');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.