Go to file
陈小术 e1867eefc4 📖 更新文档 2021-11-12 11:50:34 +08:00
images 📖 新增效果图 2021-11-12 10:59:48 +08:00
.gitignore 🙈 修改.gitignore 2021-10-08 15:52:13 +08:00
LICENSE 🚀 初始版本发布 2021-10-08 13:57:37 +08:00
README.md 📖 更新文档 2021-11-12 11:50:34 +08:00
index.js 📖 更新文档 2021-11-11 10:54:44 +08:00
package-lock.json 🚀 发布新版本 2021-11-11 11:08:34 +08:00
package.json 🚀 发布新版本 2021-11-11 11:08:34 +08:00
test.js 📖 更新文档 2021-11-11 11:09:57 +08:00

README.md

itriton-captcha

star fork

itriton-captcha

介绍

生成滑动验证码拼图图片和背景图片

安装

npm i @itriton/captcha

使用方法

const captcha = require('@itriton/captcha')

// 默认(promise)
captcha.create().then(res=>{
    console.log(res)
})

// 自定义参数(promise)
captcha.create(options).then(res=>{
    console.log(res)
})

// 默认(async/await)
async function captcha(){
   const result = await captcha.create()
}

// 自定义参数(async/await)
async function captcha(){
   const result = await captcha.create(options)
}

参数

属性名 类型 默认值 说明
size Number 30 默认拼图大小
width Number 270 图片宽度(px)
height Number 144 图片高度(px)
url String - 图片路径(支持在线地址)

返回值

属性名 类型 说明
backgroundImage Base64 背景图片
jigsawImage Base64 拼图图片
x Number x轴距离

安装sharp失败的解决方案

切换成淘宝镜像再执行npm install sharp命令

npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"

npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"

npm install sharp

效果图

结合 @itriton/uniapp 组件库的 行为验证captcha组件的实际效果