一、应用小程序云函数,进行图片检测处理
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
1)问题:图片大小限制1M ,图片尺寸不超过 750px x 1334px ;
2)解决:上传云存储,然后使用云函数进行检测
二、相册或是拍照后的图片,1)上传到云存储后 2)cloud替换成https开头的url 3) 云开发CloudBase图像处理扩展
https://cloud.tencent.com/document/product/876/42103
4) 再进行图片安全检测
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
sizeType: ['compressed'],
success: res => {
const tempFilePaths = res.tempFiles[0].tempFilePath
const cloudPath = `act/original-${Math.floor(Math.random() * 1000000000)}.jpg`
wx.cloud.uploadFile({
cloudPath,
filePath: tempFilePaths
}).then(res => {
console.log('原临时路径换原图云存储路径', res)
const pictureOrignial = res.fileID
wx.cloud.getTempFileURL({ // cloud替换成https开头的url
fileList: [pictureOrignial],
success: res => {
console.log(res)
const url = res.fileList[0].tempFileURL
this.setData({
src: `${url}?imageMogr2/thumbnail/258x258`
}, () => {
wx.getImageInfo({
src: this.data.src,
success: res => {
console.log('检测的图片信息', res, res.width, res.height)
wx.getFileInfo({
filePath: res.path,
success: res1 => {
console.log('检测的图片的大小', res1.size)
handleImg.checkImg(res.path).then(res => { // 图片检测封装成工具函数,多处需要调用
console.log(res)
// if (res === 'ok') {
// wx.hideLoading()
// getApp().globalData.imgSrc = tempFilePaths
// } else {
// wx.hideLoading()
// utils.showTip()
// utils.backNoReloadPage()
// }
})
}
})
}
})
})
}
})
}).catch(err => {
console.log(err)
wx.hideLoading()
})
}
})
你好,微信云开发已上线「图片处理」功能,欢迎体验
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/imagepro.html