# QRCode
QRCode is a Rust library that provides easy-to-use functions for generating QR code images in PNG or SVG format.
# Usage
To use the QRCode library, add the following to your Cargo.toml file:
[dependencies]
qrcode = "0.8"
Next, add the following to your Rust code:
extern crate image;
extern crate qrcode;
use image::{ImageBuffer, Rgb, RgbImage};
use qrcode::render::svg;
use qrcode::QrCode;
Then, you can create a new QRCode struct with the data you want to encode in the QR code:
let qr_code = QRCode::new(vec![1, 2, 3]);
You can also create a QRCode struct from a string or a vector of bytes:
let qr_code = QRCode::from_string("Hello, world!".to_string());
let qr_code = QRCode::from_bytes(vec![72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]);
Once you have a QRCode
struct, you can use the following methods to
generate QR code images:
to_qrcode
: creates a newQrCode
value using the data stored in theQRCode
structto_png
: creates a newPNG
image of the QR code using the data stored in theQRCode
structto_svg
: creates a newSVG
image of the QR code using the data stored in theQRCode
structcolorize
: creates a newPNG
image of the QR code using the data stored in theQRCode
struct and a given color value to colorize the QR code
# Examples
Here's an example of generating a PNG image of a QR code:
let qr_code = QRCode::new(vec![1, 2, 3]);
let png_image = qr_code.to_png();
And here's an example of generating an SVG image of a QR code:
let qr_code = QRCode::new(vec![1, 2, 3]);
let svg_image = qr_code.to_svg();
# License
QRCode is licensed under the Apache License, Version 2.0 and the MIT License.