Vin*_*der 5 javascript angular
林在角7个工作,我的要求是我需要Width,Height和Size (in how much kb or mb)图像,并且还我试着将其转化成blob。
我尝试使用以下代码,但即时通讯未获得确切的输出:
var img_url = "http://snook.ca/files/mootools_83_snookca.png";
var blob = new Blob([img_url]);
let reader = new FileReader;
reader.readAsDataURL(blob); // read file as data url
reader.onload = () => { // when file has loaded
console.log(reader.result)
var img:any = new Image();
img.src = reader.result;
img.onload = () => {
this.uploaded_image_width = img.width; //to get image width
this.uploaded_image_height = img.height; //to get image height
this.uploaded_image_url = reader.result; //to get blob image
console.log(reader.result)
};
}
Run Code Online (Sandbox Code Playgroud)
当im安慰时,blob数据出错(console.log(reader.result)),并且内部img.onload函数未执行。
我提到了这个小提琴来实现这一目标:http : //jsfiddle.net/guest271314/9mg5sf7o/
you can try like this way. i hope it helps you out
var img = new Image();
img.onload = function(){
alert( this.width+' '+ this.height );
};
img.src = "http://lorempixel.com/output/city-q-c-250-250-1.jpg";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
945 次 |
| 最近记录: |