返回顶部
q

qrcode-scan 二维码扫描

QR code scanning and generation. Invoke when user needs to scan/decode QR codes from images, generate QR codes (text, URL, WiFi), or mentions QR code related tasks.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
172
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

qrcode-scan

二维码扫描与生成

基于 qrcodepyzbar 的二维码扫描和生成工具。

何时使用此技能

当用户有以下请求时,应该激活此技能:

  • - 扫描/解码二维码
- 扫描这个二维码图片 - 解码二维码 - 读取二维码内容 - 这个二维码是什么
  • - 生成二维码
- 生成一个二维码 - 创建二维码 - 把这段文字转成二维码 - 生成网址二维码
  • - WiFi 二维码
- 生成 WiFi 二维码 - 创建 WiFi 分享码 - 解析 WiFi 二维码

依赖安装

bash
pip install qrcode pillow pyzbar

注意:Windows 用户可能需要安装 Visual C++ Redistributable,详见 pyzbar 文档

支持的输入格式

扫描二维码输入

  • - 文件路径:本地图片文件路径
  • URL:网络图片地址
  • Base64:Base64 编码的图片数据

生成二维码输出

  • - PNG 图片文件:保存到指定路径
  • Base64 字符串:返回 Base64 编码的图片

命令行使用

(注意:如果想要更快速和节省Token,你应该优先使用命令行的方式!)

扫描二维码

bash
python scripts/main.py scan [--format json]

参数:

  • - input:图片路径、URL 或 base64 数据
  • --format json:以 JSON 格式输出结果

生成二维码

bash
python scripts/main.py generate --output [--type text|url|wifi]

参数:

  • - content:要编码的内容
  • --output:输出文件路径(可选,不指定则输出 base64)
  • --type:二维码类型(text/url/wifi,默认 text)

生成 WiFi 二维码

bash
python scripts/main.py wifi --ssid --password --security WPA --output

参数:

  • - --ssid:WiFi 名称
  • --password:WiFi 密码
  • --security:加密类型(WPA/WEP/NONE,默认 WPA)
  • --output:输出文件路径(可选)

Python API 使用

快速开始

python
from scripts.main import scanqrcode, generateqrcode, generatewifiqrcode

扫描二维码

result = scan_qrcode(qrcode.png) print(result) # 解码内容

生成文字二维码

generateqrcode(Hello World, outputpath=output.png)

生成 URL 二维码

generateqrcode(https://example.com, qrtype=url, outputpath=urlqr.png)

生成 WiFi 二维码

generatewifiqrcode(MyWiFi, password123, security=WPA, outputpath=wifiqr.png)

从 Base64 扫描

python
from scripts.main import scan_qrcode

base64 字符串(支持带或不带 data:image 前缀)

result = scan_qrcode(data:image/png;base64,iVBORw0KGgo...)

或纯 base64

result = scanqrcode(iVBORw0KGgo..., inputtype=base64)

从 URL 扫描

python
from scripts.main import scan_qrcode

result = scan_qrcode(https://example.com/qrcode.png)

解析 WiFi 二维码

python
from scripts.main import scanqrcode, parsewifi_qrcode

result = scanqrcode(wifiqr.png)
wifiinfo = parsewifi_qrcode(result)
print(wifi_info)

{ssid: MyWiFi, password: password123, security: WPA}

API 参考

scanqrcode(inputdata, inputtype=None, formatjson=False)

扫描并解码二维码图片。

参数:

参数类型必需说明
inputdatastr图片路径、URL 或 base64 数据
inputtype
str | 否 | 输入类型:file/url/base64,自动检测 |
| format_json | bool | 否 | 是否返回 JSON 格式结果 |

返回值:

  • - str 或 dict:解码内容,多个二维码时返回列表

异常:

  • - FileNotFoundError:文件不存在
  • ValueError:无法解码二维码
  • ImportError:缺少依赖库

generateqrcode(content, outputpath=None, qr_type=text, size=10, border=4)

生成二维码图片。

参数:

参数类型必需说明
contentstr要编码的内容
output_path
str | 否 | 输出文件路径,不指定则返回 base64 |
| qr_type | str | 否 | 二维码类型:text/url/wifi |
| size | int | 否 | 二维码尺寸(每个模块的像素数) |
| border | int | 否 | 边框宽度(模块数) |

返回值:

  • - str:base64 编码的图片(未指定 outputpath 时)
  • None:保存到文件(指定 outputpath 时)

generatewifiqrcode(ssid, password, security=WPA, output_path=None, hidden=False)

生成 WiFi 配置二维码。

参数:

参数类型必需说明
ssidstrWiFi 名称
password
str | 是 | WiFi 密码 |
| security | str | 否 | 加密类型:WPA/WEP/NONE |
| output_path | str | 否 | 输出文件路径 |
| hidden | bool | 否 | 是否隐藏网络 |

返回值:

  • - str:base64 编码的图片或 None

parsewifiqrcode(content)

解析 WiFi 二维码内容。

参数:

参数类型必需说明
contentstr二维码解码内容

返回值:

  • - dict:包含 ssid、password、security 的字典
  • None:如果不是有效的 WiFi 二维码

最佳实践

  1. 1. 扫描二维码
- 确保图片清晰,分辨率足够 - 支持常见格式:PNG、JPEG、BMP、GIF - 图片中可以有多个二维码,会全部返回
  1. 2. 生成二维码
- 内容越长,二维码越复杂 - 建议使用 size=10 以上保证可扫描性 - URL 类型会自动验证格式
  1. 3. WiFi 二维码
- 使用 WPA 加密最常见 - 密码可能包含特殊字符,会自动处理 - 扫描后手机可直接连接 WiFi

完整示例

python
from scripts.main import scanqrcode, generateqrcode, generatewifiqrcode, parsewifiqrcode

生成并扫描 URL 二维码

generateqrcode(https://github.com, outputpath=github_qr.png) result = scanqrcode(githubqr.png) print(f扫描结果: {result})

生成 WiFi 二维码

generatewifiqrcode( ssid=MyHomeWiFi, password=MySecurePassword123, security=WPA, outputpath=wifiqr.png )

解析 WiFi 二维码

wificontent = scanqrcode(wifi_qr.png) wifiinfo = parsewifiqrcode(wificontent) print(fWiFi 信息: SSID={wifiinfo[ssid]}, 密码={wifiinfo[password]})

从 base64 生成并获取 base64 输出

base64qr = generateqrcode(Hello World) print(fBase64 QR: {base64_qr[:50]}...)

扫描网络图片

result = scan_qrcode(https://example.com/qrc

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 qrcode-scan-1776107888 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 qrcode-scan-1776107888 技能

通过命令行安装

skillhub install qrcode-scan-1776107888

下载

⬇ 下载 qrcode-scan v1.0.0(免费)

文件大小: 6.7 KB | 发布时间: 2026-4-14 10:12

v1.0.0 最新 2026-4-14 10:12
- Initial release with QR code scanning and generation capabilities.
- Supports QR code decoding from images, URLs, and Base64.
- Generates QR codes for text, URLs, and WiFi credentials.
- Includes command-line and Python API usage examples.
- Handles multiple QR codes in one image and WiFi QR code parsing.
- Documentation provided in both English and Chinese.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部