前端js处理图片格式为base64位的 获取宽高。

新手上路,请多包涵

后台返回的图片为base64格式的 现在需要获取他的宽高 请问怎么获取
或者把base64的先转为普通图片格式 然后再获取 请大佬指点。

阅读 7.6k
3 个回答
var img = new Image();
img.src = `${base64}`;
img.onload = () => {
    console.log(img.width, img.height);
}
var img = new Image();
img.src = 'base64 img';
img.width;
img.height;
const imgData = 'data:image/png;base64,........'
let img = new Image()
img.src = imgData; 
img.onload = function(){
 console.log('height',img.height)
 console.log('width',img.width)
};
推荐问题