#qrcode #generator #standard #image #content #generate #generate-image

qirust

A simple QR code generator written in Rust using standard library

9 releases

0.1.8 Mar 11, 2024
0.1.7 Mar 9, 2024

#153 in Images

Download history 215/week @ 2024-03-01 464/week @ 2024-03-08 147/week @ 2024-03-15 17/week @ 2024-03-22 2/week @ 2024-03-29

845 downloads per month

MIT license

76KB
1K SLoC

qirust

crates.io

A simple QR code generator written in Rust using standard library.

Contents

Installation

  1. Add qirust to your cargo.toml
[dependencies]
qirust = "0.1.8"
  1. Then run cargo build command
cargo build

Usage

generate_svg_string(content)

generate_svg_string(content: &str) -> String

content parameter is required

generate_image(content, directory, filename)

generate_image(content: &str, directory: Option<&str>, filename: Option<&str>)

content parameter is required, directory, and filename are optional, if you prefer to use default option set as None

generate_image("hello world", None, None);

mix_colors(pixel, foreground, background)

mix_colors(pixel: u8, foreground: u8, background: u8) -> u8

pixel, foreground, and background parameters are required

generate_image_buffer(content, border, fg_color, bg_color)

generate_image_buffer(
    content: &str,
    border: Option<i32>,
    fg_color: Option<Rgb<u8>>,
    bg_color: Option<Rgb<u8>>
) -> ImageBuffer<Rgb<u8>, Vec<u8>>

content parameter is required, border, fg_color, and bg_color are optional, if you prefer to use default option set as None

Example

use qirust::helper::{generate_image, generate_svg_string};

fn main() {
    generate_image("hello world", None, None); // generate_image("hello world", Some("your_image_directory"), Some("image_name"));
    generate_svg_string("hello world");
}

or you can customize the appearance of the generated QR code as desired using the generate_image_buffer function.

use qirust::helper::generate_image_buffer;
use image::Rgb;

fn main() {
    let foreground_color = Rgb([255, 0, 0]); // Red foreground color
    let background_color = Rgb([0, 0, 0]); // Black background color
    let colored_image_buffer = generate_image_buffer(
        "Hello, World!",
        None,
        Some(foreground_color),
        Some(background_color)
    );

    let colored_image_path = "./colored_image.png";
    colored_image_buffer.save(colored_image_path).unwrap();
}

License

MIT License

Copyright (c) 2024 Ashaffah

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Back to top

Dependencies

~11MB
~51K SLoC