js图片尺寸大小获取

//图片流作为参数传递 获取图片尺寸大小提示
    function getImgTip(bdImgBase) {
        (async () => {
            let size = await getImageSize(bdImgBase);
            $('#imgTip').html("当前图片宽高尺寸为[" + size.width + "px * " + size.height + "px]");
        })();
    }

    //参数为二进制图片流
    function getImageSize(url) {
        return new Promise(function (resolve, reject) {
            let image = new Image();
            image.onload = function () {
                resolve({
                    width: image.width,
                    height: image.height
                });
            };
            image.onerror = function () {
                reject(new Error('error'));
            };
            image.src = url;
        });
    }

你可能感兴趣的:(javascript,前端,开发语言)