uniapp图片选择压缩并转换base64身份证识别

wx.chooseImage({
		   count: 1,
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: function (res) {
			  
			            let path = res.tempFilePaths[0];   
			            plus.zip.compressImage({    
			                src:path,    
			                dst:path,    
			                overwrite:true,    
			                quality:20,    
			                width: '780px',      
			                height:'1040px',      
			                format: 'jpg'    
			                },    
			                function(res) {      
			                    let imgPathUrl = res.target;   
			                    let imgPathSize = res.size;  
			        
			                    let reader = new plus.io.FileReader();   
			                    // 文件读取操作完成时的回调函数  
			                    reader.onloadend = (fileData)=> {  
			                        uni.hideLoading();  
			                        console.log('文件读取完成!');      
			                        let speech = fileData.target.result;//base64图片   
			                        // 去除base64文件头  
			                        let imgData = speech.replace(/^data:image\/\w+;base64,/, "");  
			wx.request({
			                    url: WXAPI.API_BASE_URL+'scan/idcard',
			                    method:'POST',
			                    data:{'image':imgData},header:{
			                          'Content-Type': 'application/x-www-form-urlencoded'
			                        },success(res){
			console.log(res)
			if(res.statusCode==500){
			  wx.showToast({
			    title: "图片格式错误",
			    icon: 'none'
			  })
			}
			if(res.data.Name != null){
			    console.log(res.data.Name)
			        var url ='../register/index?address='+res.data.Address+'&name='+res.data.Name+'&sex='+res.data.Sex+'&idcard='+res.data.IdNum
			          wx.navigateTo({
			        url: url
			           })
			                    }
			                  }
			                  })
			            }     
			                    reader.readAsDataURL(res.target);  
			                },    
			                function(error) {    
			                    console.log("Compress error!",error);   
			                    return;   
			
			            });  
						}
						})

 

你可能感兴趣的:(HTML)