小程序获取图片大小

data:{
    img:[], //设置一个数组
}
 
add_img:function(){
    var that = this,
    img = that.data.img;
        if(img.length < 3){  //如果图片数量小于3张,可以直接获取图片
            wx.chooseImage({
                count:1,     //默认9
                sizeType:[\'compressed\'], //可以指定原图还是压缩图,默认二者都有
                sourceType:[\'album\',\'camera\'],//可以指定来源相册还是相机,默认二者都有
                success:function(res){
                    var tempFilesSize = res.tempFiles[0].size;  //获取图片的大小,单位B
                    if(tempFilesSize <= 2000000){   //图片小于或者等于2M时 可以执行获取图片
                        var tempFilePaths = res.tempFilePaths[0]; //获取图片
                        that.data.img.push(tempFilePaths);   //添加到数组
                        that.setData({
                            img:that.data.img
                        })
                    }else{    //图片大于2M,弹出一个提示框
                        wx.showToast({
                            title:\'上传图片不能大于2M!\',  //标题
                            icon:\'none\'       //图标 none不使用图标,详情看官方文档
                        })
                    }
                }
            })
        }else{  //大于三张时直接弹出一个提示框
             wx.showToast({
                 title:\'上传图片不能大于3张!\',
                 icon:\'none\'   
             })
 
        }
 
}