xzImage.js 928 字节
Newer Older
1 2 3 4 5
/**
* @Author: xiaozuo28
* @Date: 2022年5月13日08:05:20
* @LastEditors: xiaozuo28
* @LastEditTime: 2022年7月17日08:42:42
6
* @Description: Image数据处理
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
**/

export default {
    /**
     * @Description 获取图片大小
     * @Date 2022年7月17日11:52:41
     * @Param {String} imageUrl 图片地址
     * @Return {Object} 图片的宽高
    **/
    getImageSize(imageUrl) {
        return new Promise(function (resolve, reject) {
            let image = new Image();
            image.src = imageUrl;
            image.onload = function () {
                resolve({
                    width: image.width,
                    height: image.height
                });
            };
            image.onerror = function () {
                reject({
                    width: 0,
                    height: 0
                });
                // reject(new Error('error'));
            };
        });
    }
}