Files
Serendipity 38be82973e feat: Logo 嵌入 — QR 码中央叠加自定义图片
- PNG 渲染:RgbaImage 上使用 imageops::overlay 叠加 logo
- SVG 渲染:base64 编码 logo 嵌入 <image> 标签
- QrCode::to_png_bytes / to_svg 新增 Option<logo_bytes> 参数
- Logo 默认占 QR 区域 25%,建议配合 H 级纠错使用
2026-06-19 21:12:44 +08:00

31 lines
836 B
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! QRGen 基础示例:生成 QR 码并导出为多种格式
//!
//! 运行: `cargo run --example basic_qr`
use qr_core::qr::{QrCode, QrConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = "https://github.com/LHY0125/QRGen";
// 使用默认配置(M 级纠错,自动版本,4 模块边距)
let qr = QrCode::encode(text, QrConfig::default())?;
println!("版本: {}", qr.version.0);
println!("尺寸: {}×{} 模块", qr.size(), qr.size());
println!("掩码: {}", qr.mask);
// 终端 ASCII 预览
println!("\n--- ASCII 预览 ---");
println!("{}", qr.to_ascii(false));
// 导出 PNG
qr.to_png_bytes(8, None)?;
println!("\nPNG 生成成功");
// 导出 SVG
let svg = qr.to_svg(None);
println!("SVG 长度: {} 字节", svg.len());
Ok(())
}