simple-imagedetect
v1.0.0
Published
判断图片明暗、模糊度工具
Downloads
1
Readme
simple-imagedetect
install
npm install simple-imagedetect
usage
小程序
import utils from 'simple-imagedetect';
wx.chooseMedia({
...
success: async (res) => {
const files = res.tempFiles || []
const file = files[0]
/**
* checkLuminance
* @return Promise
* {
* brightness: Number, // 明暗值
* isBright: Boolean, // 是否过亮
* isGray: Boolean, // 是否过暗
* }
*
*/
const luminance = await utils.checkLuminance(file?.tempFilePath)
/**
* checkDim
* @return Promise
* {
* averageDiff: Number, // 模糊值
* isClear: Boolean, // 是否清晰
* }
*/
const dim = await utils.checkDim(file?.tempFilePath)
}
})
react demo
import React, { useState } from 'react'
import utils from 'simple-imagedetect';
import { ImageUploader } from 'antd-mobile'
export default () => {
const [fileList, setFileList] = useState([])
const handleDetect = async (files) => {
const url = files[files?.length - 1]?.url
const luminance = await checkLuminance(url)
const dim = await checkDim(url)
}
return <ImageUploader value={fileList} onChange={handleDetect} />
}