A Chromium Style QR Code Generator using Rust.
https://github.com/chromium-style-qrcode/generator
Chromium Style QR Code Generator (WebAssembly Version)
This is a high-performance QR code generator developed with Rust and WebAssembly technology. The project combines the efficiency of Rust with the cross-platform capabilities of WebAssembly to provide fast and efficient QR code generation for web applications.
Features
- ⚡️ High Performance: Utilizing Rust and WebAssembly for high-speed QR code generation
- 🔄 Real-time Preview: Instantly updates QR codes as input changes
- 📋 Smart Copy Function: Copies QR code images directly to clipboard (with text fallback)
- 💾 Perfect Downloads: Downloads QR codes as crisp 450×450 pixel PNG images
- 🦖 Chromium-Style Dino: Supports dinosaur center images with white backgrounds
- 📱 Responsive Design: Adapts to different device screen sizes
- ✨ High DPI Support: Crystal clear rendering on retina and high-DPI displays
- 🎯 Chromium Compliance: Pixel-perfect implementation matching Chrome's QR generator
Quality Improvements
Technical Specifications
- Module Style: Circular dots (
ModuleStyle::kCircles) matching Chrome - Locator Style: Rounded corners (
LocatorStyle::kRounded) matching Chrome - Center Image: Dino with exact pixel data from Chromium source code
- Canvas Size: 240×240 pixels (
GetQRCodeImageSize()equivalent) - Module Size: 10 pixels per module (
kModuleSizePixels) - Dino Scale: 4 pixels per dino pixel (
kDinoTileSizePixels)
Technology Stack
- Rust: Core QR code generation logic
- WebAssembly: Compiles Rust into a format that can run in browsers
- JavaScript: Front-end interaction and rendering
- HTML5/CSS: User interface
Installation and Usage
Prerequisites
Build Steps
Build the WebAssembly module
pnpm build:wasmInstall frontend dependencies
pnpm installStart the development server
pnpm dev-
Open the project in your browser (default: http://localhost:5173)
How to Use
- Enter any text, URL, or data in the input field (up to 2000 characters)
- The QR code will be automatically generated and displayed with real-time updates
- Use the "Copy" button to copy the QR code image directly to clipboard
- Use the "Download" button to save the QR code as a crisp 450×450 PNG image
Project Structure
├── src/ # Source code directory
│ ├── lib.rs # Rust WebAssembly module core code
│ ├── app.js # Frontend JavaScript logic
│ └── app.css # Stylesheet
├── public/ # Static resources
├── index.html # Main HTML page
├── Cargo.toml # Rust project configuration
└── package.json # JavaScript project configuration
How It Works
This QR code generator uses Rust's qr_code library to generate QR code data and exposes it to JavaScript via WebAssembly. The generation process includes:
- Receiving text data input from users
- Generating the corresponding QR code two-dimensional matrix in Rust
- Adding appropriate quiet zones
- Returning the two-dimensional matrix data to JavaScript
- Rendering the QR code image using the Canvas API
Development
Modifying Rust Code
If you modify lib.rs or other Rust code, you need to rebuild the WebAssembly module:
pnpm build:wasmModifying Frontend Code
from https://github.com/liuliangsir/chromium-style-qrcode-generator-with-wasm
No comments:
Post a Comment