{"spec_id":"qrcode-basic","library":"pygal","language":"python","code":"\"\"\" anyplot.ai\nqrcode-basic: Basic QR Code Generator\nLibrary: pygal 3.1.3 | Python 3.13.14\nQuality: 88/100 | Updated: 2026-06-24\n\"\"\"\n\nimport os\nimport sys\n\nimport qrcode\n\n\n# Avoid name collision: pygal.py filename shadows the pygal package\n_cwd = sys.path[0] if sys.path[0] else \".\"\nif _cwd in sys.path:\n    sys.path.remove(_cwd)\n\nimport pygal\nfrom pygal.style import Style\n\n\nsys.path.insert(0, _cwd)\n\n# --- Theme ---\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\nMODULE_DARK = INK  # high-contrast QR dark modules, theme-adaptive\nMODULE_LIGHT = PAGE_BG  # QR light modules match page background\nFRAME_ACCENT = \"#009E73\"  # Imprint brand green — quiet-zone frame annotation\n\n# --- Data ---\nqr_content = \"https://anyplot.ai\"\nqr = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=1, border=0)\nqr.add_data(qr_content)\nqr.make(fit=True)\nqr_matrix = qr.get_matrix()\nmatrix_size = len(qr_matrix)\n\n# 4-cell ISO-spec quiet zone + 2-cell brand-green frame annotation (wider = more solid)\ninner_quiet = 4\nouter_frame = 2\ntotal_cells = matrix_size + 2 * (inner_quiet + outer_frame)\n\n# Slight oversize per cell closes SVG sub-pixel rendering gaps between rows\nCELL = 1.05\n\n# --- Style (2400×2400 square canvas — Imprint palette sizing) ---\ncustom_style = Style(\n    background=PAGE_BG,\n    plot_background=PAGE_BG,\n    foreground=INK,\n    foreground_strong=INK,\n    foreground_subtle=INK_MUTED,\n    colors=(MODULE_DARK, MODULE_LIGHT, FRAME_ACCENT),\n    title_font_size=66,\n    label_font_size=56,\n    major_label_font_size=44,\n    legend_font_size=44,\n    value_font_size=36,\n    font_family=\"'Helvetica Neue', Helvetica, Arial, sans-serif\",\n    opacity=1.0,\n    opacity_hover=1.0,\n    transition=\"0s\",\n    stroke_width=0,\n)\n\ncustom_css = (\n    \"inline:\"\n    \"rect { stroke-width: 0 !important; stroke: none !important;\"\n    \" shape-rendering: crispEdges !important; }\"\n    \" .title { font-weight: 600 !important; }\"\n)\n\nchart = pygal.StackedBar(\n    width=2400,\n    height=2400,\n    style=custom_style,\n    title=\"qrcode-basic · python · pygal · anyplot.ai\",\n    show_legend=False,\n    show_x_labels=False,\n    show_y_labels=False,\n    show_x_guides=False,\n    show_y_guides=False,\n    spacing=0,\n    margin=80,\n    margin_top=150,\n    margin_bottom=220,\n    print_values=False,\n    range=(0, total_cells * CELL),\n    x_title=f\"{qr_content} · EC: M · {matrix_size}×{matrix_size}\",\n    css=[\"file://style.css\", \"file://graph.css\", custom_css],\n)\n\n# --- Build rows (StackedBar stacks bottom-to-top) ---\nfull_frame = [FRAME_ACCENT] * total_cells\nside_frame = (\n    [FRAME_ACCENT] * outer_frame + [MODULE_LIGHT] * (total_cells - 2 * outer_frame) + [FRAME_ACCENT] * outer_frame\n)\n\n\n# Bottom outer frame then quiet zone\nfor _ in range(outer_frame):\n    chart.add(\"\", [{\"value\": CELL, \"color\": c} for c in full_frame])\nfor _ in range(inner_quiet):\n    chart.add(\"\", [{\"value\": CELL, \"color\": c} for c in side_frame])\n\n# QR matrix rows (reversed so matrix row 0 ends up at the top)\nfor row_idx in reversed(range(matrix_size)):\n    row = (\n        [FRAME_ACCENT] * outer_frame\n        + [MODULE_LIGHT] * inner_quiet\n        + [MODULE_DARK if qr_matrix[row_idx][c] else MODULE_LIGHT for c in range(matrix_size)]\n        + [MODULE_LIGHT] * inner_quiet\n        + [FRAME_ACCENT] * outer_frame\n    )\n    chart.add(\"\", [{\"value\": CELL, \"color\": c} for c in row])\n\n# Top quiet zone then outer frame\nfor _ in range(inner_quiet):\n    chart.add(\"\", [{\"value\": CELL, \"color\": c} for c in side_frame])\nfor _ in range(outer_frame):\n    chart.add(\"\", [{\"value\": CELL, \"color\": c} for c in full_frame])\n\n# --- Save ---\nchart.render_to_png(f\"plot-{THEME}.png\")\nwith open(f\"plot-{THEME}.html\", \"wb\") as f:\n    f.write(chart.render())\n"}