Index of /research/qr

      Name                    Last modified      Size  Description
Parent Directory - test.html 2025-12-23 06:12 7.5K 1.html 2025-12-23 06:12 1.6K qr-KfxhPA.png 2025-07-30 10:45 405 qr-ogDIlu.png 2025-07-30 10:45 402
QR Code Generator and Documentation

QR Code Generator and Documentation

Table of Contents

Overview

QR code generator with support for standard and ambiguous QR codes.

Configuration

(require 'qrencode)

(defgroup qr nil
  "QR code generation and analysis tools"
  :group 'tools)

(defcustom qr-base-urls 
  '("http://localhost:8080"
    "https://example.com")
  "Base URLs for QR code generation"
  :type '(repeat string)
  :group 'qr)

(defcustom qr-output-dir "/tmp/qr-diff"
  "Directory for QR code output files"
  :type 'directory
  :group 'qr)

(defun qr-ensure-output-dir ()
  "Ensure output directory exists"
  (unless (file-exists-p qr-output-dir)
    (make-directory qr-output-dir t)))

(defun qr-generate-url (base-url path)
  "Generate full URL for QR code"
  (concat base-url path))

(defun qr-encode-url-to-ascii (url)
  "Create ASCII QR code from URL"
  (qr-ensure-output-dir)
  (with-temp-buffer
    (call-process "qrencode" nil t nil 
                 "-t" "ASCII" 
                 "-o" "-"
                 url)
    (buffer-string)))

(provide 'qr-config)

Analysis

Test QR Codes

#!/bin/bash

set -euo pipefail

LOCAL_HOST="http://localhost:8080"
PATHS=("/1" "/2")
TMP_DIR="/tmp/qr-test"

test_local() {
    mkdir -p "$TMP_DIR"
    for path in "${PATHS[@]}"; do
        url="$LOCAL_HOST$path"
        outfile="$TMP_DIR/$(basename "$path").png"
        qrencode -o "$outfile" -s 10 "$url"
        qrencode -t ASCII -o - "$url" > "$TMP_DIR/$(basename "$path").txt"
    done
    
    compare "$TMP_DIR/1.png" "$TMP_DIR/2.png" "$TMP_DIR/diff.png"
    diff "$TMP_DIR/1.txt" "$TMP_DIR/2.txt" || true
}

test_local

Ambiguous QR Codes

The script supports generating ambiguous QR codes that encode two different URLs using a lenticular pattern.

String-based Implementation

#!/usr/bin/env python3

import qrcode

def generate_ambiguous_qr(host="example.com", paths=["/1", "/2"]):
    qr1 = qrcode.QRCode(version=1, box_size=1, border=4)
    qr2 = qrcode.QRCode(version=1, box_size=1, border=4)
    
    qr1.add_data(f"https://{host}{paths[0]}")
    qr2.add_data(f"https://{host}{paths[1]}")
    
    str1 = qr1.get_matrix()
    str2 = qr2.get_matrix()
    
    for i in range(len(str1)):
        for j in range(len(str1[0])):
            if str1[i][j] != str2[i][j]:
                str1[i][j] = "▚" if (i + j) % 2 else "▞"
    
    for row in str1:
        print("".join("█" if cell else " " for cell in row))

if __name__ == "__main__":
    hosts = ["localhost:8080", "example.com"]
    for host in hosts:
        print(f"\nAmbiguous QR for {host}:")
        generate_ambiguous_qr(host)

Development

Requirements

  • qrencode
  • imagemagick
  • python3, qrcode
  • emacs 25+

Installation

# macOS
brew install qrencode imagemagick
pip install qrcode

# Debian/Ubuntu
apt-get install qrencode imagemagick
pip install qrcode

Usage

  1. Load the configuration
  2. Generate QR codes with qr-encode-url-to-ascii
  3. Create ambiguous codes with generate_ambiguous_qr

Author: Jason Walsh

jwalsh@nexus

Last Updated: 2025-12-21 18:10:36

build: 2025-12-23 09:12 | sha: e32f33e