diff --git a/Cargo.lock b/Cargo.lock index 5911ea61..c60800f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,9 +814,9 @@ dependencies = [ [[package]] name = "qrcode" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e719ca51966ff9f5a8436edb00d6115b3c606a0bb27c8f8ca74a38ff2b036d" +checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" dependencies = [ "image", ] diff --git a/Cargo.toml b/Cargo.toml index 111cfbee..3f49e308 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ clap_complete_nushell = "4.5.2" csscolorparser = "0.6.2" image = { version = "0.25.1", default-features = false, features = ["png", "rayon"] } oxipng = { version = "9.1.1", default-features = false, features = ["parallel", "zopfli"], optional = true } -qrcode = "0.14.0" +qrcode = "0.14.1" resvg = { version = "0.42.0", default-features = false, optional = true } rqrr = "0.7.1" sysexits = "0.8.1" diff --git a/src/app.rs b/src/app.rs index db7fcdbb..23bf90fc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -75,7 +75,7 @@ pub fn run() -> anyhow::Result<()> { .unwrap_or_else(|| if code.version().is_micro() { 2 } else { 4 }); let module_size = arg.size.map(NonZeroU32::get); match arg.output_format { - format @ (OutputFormat::Svg | OutputFormat::Terminal) => { + format @ (OutputFormat::Pic | OutputFormat::Svg | OutputFormat::Terminal) => { let string = if format == OutputFormat::Svg { encode::to_svg( &code, @@ -83,6 +83,8 @@ pub fn run() -> anyhow::Result<()> { &(arg.foreground, arg.background), module_size, ) + } else if format == OutputFormat::Pic { + encode::to_pic(&code, margin, module_size) } else { encode::to_terminal(&code, margin, module_size) }; diff --git a/src/cli.rs b/src/cli.rs index c2d5204d..557229c6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -389,6 +389,9 @@ impl From for qrcode::EcLevel { #[derive(Clone, Debug, Default, Eq, PartialEq, ValueEnum)] pub enum OutputFormat { + /// PIC markup language. + Pic, + /// Portable Network Graphics. /// /// This outputs 32-bit RGBA PNG image. diff --git a/src/encode.rs b/src/encode.rs index 00b4289d..abb51a21 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -6,7 +6,7 @@ use csscolorparser::Color; use image::{Rgba, RgbaImage}; use qrcode::{ bits::Bits, - render::{svg, unicode, Renderer}, + render::{pic, svg, unicode, Renderer}, types::QrError, EcLevel, QrCode, QrResult, Version, }; @@ -51,6 +51,16 @@ pub fn push_data_for_selected_mode( } } +/// Renders the QR code into a PIC image. +pub fn to_pic(code: &QrCode, margin: u32, module_size: Option) -> String { + let c = code.to_colors(); + let mut renderer = &mut Renderer::::new(&c, code.width(), margin); + if let Some(size) = module_size { + renderer = renderer.module_dimensions(size, size); + } + renderer.build() +} + /// Renders the QR code into an image. pub fn to_svg( code: &QrCode,