Generate and recognize QR codes, supporting formats such as text, URLs, WiFi credentials, and business cards (vCard).
Use Cases
- The user says "Help me generate a QR code" or "Turn this link into a QR code"
- The user says "Generate a WiFi QR code so guests can connect easily"
- The user says "Recognize the content in this QR code image"
Execution Method
Generate QR Code
import qrcode
Basic Usage
img = qrcode.make("https://example.com") img.save("/tmp/qr.png")
Custom Stylesqr = qrcode.QRCode(version=1, box_size=10, border=4) qr.add_data("https://example.com") qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") img.save("/tmp/qr.png")
### WiFi QR 码
```python
wifi_data = "WIFI:T:WPA;S:MyNetwork;P:MyPassword;;"
img = qrcode.make(wifi_data)
img.save("/tmp/wifi_qr.png")
Format:WIFI:T:{加密类型};S:{SSID};P:{密码};;
Encryption type:WPA、WEP、nopass
Business Card QR Code (vCard)
vcard = """BEGIN:VCARD
VERSION:3.0
FN:张三
TEL:+86-138-0000-0000
EMAIL:zhangsan@example.com
END:VCARD"""
img = qrcode.make(vcard)
img.save("/tmp/contact_qr.png")
Recognize QR Code
from PIL import Image
from pyzbar.pyzbar import decode
img = Image.open("qr_image.png")
results = decode(img)
for r in results:
print(r.data.decode("utf-8"))
Note: The recognition feature requires additional installation of pyzbar(pip install pyzbar) and the system library zbar。
Output Specifications
- After generation, return the image file path
- For WiFi QR codes, explain how to use them (scan with a phone camera to connect)
- Do not log WiFi passwords