拥抱开源世界|滑动验证码拼图图片和背景图片生成插件

963 阅读1分钟

介绍

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

安装

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)
}

参数

属性名类型默认值说明
sizeNumber30默认拼图大小
widthNumber270图片宽度(px)
heightNumber144图片高度(px)
urlString-图片路径(支持在线地址)

返回值

属性名类型说明
backgroundImageBase64背景图片
jigsawImageBase64拼图图片
xNumberx轴距离

安装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)组件的实际效果

screenshot.png

其他开源项目

ibaleine-weapp

基于原生小程序框架的小程序商城

@itriton/uniapp

@itriton/uniapp,是基于uni-app生态开发的组件库