QR codes
QR codes as SVG for links, tickets, Wi-Fi and two-factor set-up, in any colours, or drawn as text.
Version 1.0.0 · 4 functions · 1 crate
Functions
What use qr.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use qr_svg, qr_svg_colors from qr (Quillo 0.6).
qr_svg(text: str, size: int) → stror an errorAn SVG image of text as a QR code, at least size pixels wide, dark on light; put it in a page with raw(...) or serve it as image/svg+xml.
qr_svg_colors(text: str, size: int, dark: str, light: str) → stror an errorThe same, in the colours given (CSS colours), with error correction "M"; use a dark colour on a light one for scanners.
qr_text(text: str) → stror an errorThe QR code drawn in text, for a terminal or a log: quillo run printing a link to scan.
wifi_qr_text(ssid: str, password: str) → strThe text a phone's camera joins a Wi-Fi network from (WPA security), for a QR code by the door.
Get it
$ quillo install qr # qr.qwer into this folder$ quillo install qr --example # and its example, qr.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/qr.qwer$ curl -O https://quillolang.org/plugins/files/qr.qweThen, in your program, all of it or only what you call:
use qr.qweruse qr_svg, qr_svg_colors from qr // Quillo 0.6: only theseIt uses this crate, which cargo fetches the first time the plugin is built:
qrcode = { version = "0.14", default-features = false, features = ["svg"] }Example
// A QR code for a link, served as an image and shown in a page.//// quillo run qr.qwe then open http://localhost:8080/use "qr.qwer"route GET /qr.svg ? { text: str = "https://quillolang.org" } = respond(200, qr_svg(text, 256)?, { "content-type": "image/svg+xml", "cache-control": "max-age=86400" })route GET / = <html><body> <h1>Scan to open the docs</h1> <div style="width: 200px">{raw(qr_svg_colors("https://quillolang.org/docs/", 200, "#1b1630", "#f7f3e8")?)}</div> <img src="/qr.svg?text=WIFI%3AT%3AWPA%3BS%3ACafe%3BP%3Asecret%3B%3B" width="160" alt="Join the café's Wi-Fi"/></body></html>$ quillo run qr.qwe$ curl 'localhost:8080/qr.svg?text=hello'$ curl 'localhost:8080/'Source
//! QR codes as SVG: links, tickets, payments, Wi-Fi and two-factor set-up, sharp at any size.//! version: 1.0.0//!//! [dependencies]//! qrcode = { version = "0.14", default-features = false, features = ["svg"] }use qrcode::render::svg;use qrcode::{EcLevel, QrCode};fn code(text: &str, level: &str) -> Result<QrCode, String> { let ec = match level { "L" | "l" => EcLevel::L, "Q" | "q" => EcLevel::Q, "H" | "h" => EcLevel::H, _ => EcLevel::M }; QrCode::with_error_correction_level(text.as_bytes(), ec).map_err(|e| e.to_string())}/// An SVG image of `text` as a QR code, at least `size` pixels wide, dark on light; put it in a page with `raw(...)` or serve it as image/svg+xml.pub fn qr_svg(text: &str, size: i64) -> Result<String, String> { qr_svg_colors(text, size, "#000000", "#ffffff")}/// The same, in the colours given (CSS colours), with error correction "M"; use a dark colour on a light one for scanners.pub fn qr_svg_colors(text: &str, size: i64, dark: &str, light: &str) -> Result<String, String> { let s = size.clamp(32, 4096) as u32; Ok(code(text, "M")?.render::<svg::Color>().min_dimensions(s, s).dark_color(svg::Color(dark)).light_color(svg::Color(light)).build())}/// The QR code drawn in text, for a terminal or a log: `quillo run` printing a link to scan.pub fn qr_text(text: &str) -> Result<String, String> { Ok(code(text, "L")?.render::<char>().quiet_zone(true).module_dimensions(2, 1).dark_color('█').light_color(' ').build())}/// The text a phone's camera joins a Wi-Fi network from (`WPA` security), for a QR code by the door.pub fn wifi_qr_text(ssid: &str, password: &str) -> String { let esc = |s: &str| s.replace('\\', "\\\\").replace(';', "\\;").replace(',', "\\,").replace(':', "\\:").replace('"', "\\\""); format!("WIFI:T:WPA;S:{};P:{};;", esc(ssid), esc(password))}Related
placeholder.qwer · 1.0.0Placeholder images as SVG: a box of any size with its dimensions or your text in your colours, as markup or a data: URL.8 views · 8 downloadsQR and barcode reader qr_read.qwer · 1.0.0QR codes and barcodes read from pictures: QR, Data Matrix, PDF417, EAN-13, UPC-A, Code 128 and more, for tickets, parcels and products.8 views · 7 downloadsSprite sheets sprites.qwer · 1.0.0Sprite sheets: small pictures packed into one PNG with a CSS class or a JSON frame for each, retina sheets too, and SVG icons gathered into one SVG of symbols to draw with <use href>.8 views · 6 downloadsSVG to PNG svg_png.qwer · 1.0.0SVG drawn to PNG at the size you ask, text included with a built-in font: link previews, email images, icons and charts.7 views · 7 downloadsAnimated GIF gif.qwer · 1.0.0Animated GIFs made from a list of pictures with the delay and size you choose, and GIFs read back: frames, size and length.6 views · 7 downloadsASCII art ascii_art.qwer · 1.0.0Pictures turned into ASCII art: characters from light to dark, plain for terminals and emails, or coloured as HTML.6 views · 10 downloadsThread 0 posts
On QR codes: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.