Overview
Dubly automatically generates QR codes for every short link. QR codes can be customized with different shapes, colors, and download options.Accessing QR Codes
QR codes are available through the admin web interface and via direct API endpoint:Web Interface
In the admin panel, each link has a QR code button that opens a customization dialog with:- Live preview
- Shape selection (square or circle)
- Color picker for foreground color
- Download button
API Endpoint
shape(optional):square(default) orcirclefg(optional): Hex color code for foreground (e.g.,#FF5733)dl(optional): Set to1to trigger browser download with filename
Implementation Details
QR code generation is handled in internal/web/qr.go:27 using theyeqown/go-qrcode library:
QR Code Options
The following options are applied to every QR code:- Format: PNG
- QR Width: 10 pixels per module
- Border Width: 20 pixels
- Background: Transparent (always)
Color Validation
Hex color codes are validated using a regular expression in internal/web/qr.go:17:#FF5733) are accepted. Invalid colors are ignored and the default black is used.
Response Headers
QR codes are served with appropriate caching and content headers in internal/web/qr.go:77:Cache Control
QR code images are cached for 1 hour (max-age=3600). This reduces server load for frequently accessed QR codes while allowing reasonable update times if the link destination changes.
Download Filenames
Whendl=1 is specified, the Content-Disposition header triggers a browser download with filename format: {slug}-qr.png
For example, a link with slug abc123 will download as abc123-qr.png.
QR Code Generation
The actual QR code encoding and rendering happens in internal/web/qr.go:64:https://short.example.com/abc123).
Examples
Default QR Code
Generate a standard black square QR code:Circular Blue QR Code
Generate a circular QR code with blue foreground:URL-encode the
# in hex colors as %23 when making API requests.Download Red Square QR Code
Generate a red QR code and trigger download:Using curl
Error Handling
Invalid Link ID
If the link ID doesn’t exist or is invalid:QR Generation Failure
If QR code generation fails (extremely rare):Technical Details
Buffer Implementation
The QR code is rendered to an in-memory buffer to avoid filesystem I/O. A customnopCloser wrapper is used in internal/web/qr.go:23:
bytes.Buffer to satisfy the io.WriteCloser interface required by the QR library without actual close semantics.
Image Format
All QR codes are generated as PNG images with:- Transparent background
- Lossless compression
- Optimal size for web display and printing
Best Practices
Color Selection
- Use high contrast colors for reliable scanning (dark foreground, light/transparent background)
- Test QR codes with your chosen colors on actual devices before printing
- Avoid light colors like yellow or cyan for foreground
Size and Printing
The default QR code size (QRWidth: 10, BorderWidth: 20) produces:- Web-friendly images around 300x300 pixels
- Print-ready at 300 DPI for approximately 1 inch square
Embed in Marketing Materials
Dynamic QR Codes
Since QR codes encode the short URL (not the destination), they remain valid even if you update the link’s destination. This makes them true “dynamic QR codes” - update where the link points without reprinting.Unlike typical dynamic QR code services, Dubly doesn’t charge extra for this feature. All QR codes are dynamic by design.