QR Code Generator — Developer Code Samples
Generate QR codes programmatically for URLs, contact cards, WiFi credentials, and plain text. Python's qrcode library and the qrcode npm package produce QR code images. For web use, qrcode.js renders directly to canvas without a server round-trip.
Try the interactive version online:
Open QR Code Generator Tool →
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| data | str | Yes | Content to encode: URL, text, vCard, WiFi string, etc. |
| error_correction | str | No | Error correction level: L (7%), M (15%), Q (25%), H (30%) (default: M) |
| box_size | int | No | Pixels per QR module/box (default: 10) |
| border | int | No | Quiet zone width in boxes (default: 4) |
Returns: QR code image as PIL Image object, PNG bytes, Base64 data URI, or SVG string
Code Examples
# Install: pip install qrcode[pil]
# Install: pip install qrcode[pil]
import qrcode
from qrcode.image.pure import PyPNGImage
import io
import base64
# Basic QR code
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=10,
border=4,
)
qr.add_data("https://toolpilot.dev")
qr.make(fit=True)
# Save as PNG file
img = qr.make_image(fill_color="black", back_color="white")
img.save("qr_code.png")
print("Saved qr_code.png")
# Generate as Base64 data URI (for web embedding)
buffer = io.BytesIO()
img.save(buffer, format="PNG")
b64 = base64.b64encode(buffer.getvalue()).decode('ascii')
data_uri = f"data:image/png;base64,{b64}"
print(f"Data URI length: {len(data_uri)}")
# Generate WiFi QR code
wifi_string = "WIFI:T:WPA;S:MyNetwork;P:MyPassword;;"
qr_wifi = qrcode.make(wifi_string)
qr_wifi.save("wifi_qr.png")
# Generate vCard QR code
vcard = (
"BEGIN:VCARD
"
"VERSION:3.0
"
"FN:Alice Smith
"
"ORG:Acme Corp
"
"EMAIL:[email protected]
"
"TEL:+1-555-1234
"
"END:VCARD"
)
qr_vcard = qrcode.make(vcard)
qr_vcard.save("contact_qr.png")
# Custom colors
img_colored = qr.make_image(fill_color="#0066CC", back_color="#F0F8FF")
img_colored.save("colored_qr.png")