Fix test spec.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/qrcodegen-image/src/lib.rs b/qrcodegen-image/src/lib.rs
index 376730b..b37eac4 100644
--- a/qrcodegen-image/src/lib.rs
+++ b/qrcodegen-image/src/lib.rs
@@ -2,7 +2,11 @@
//! to a canvas provided by the `image` crate.
use image::Luma;
-pub(crate) fn get_qr_draw_canvas(qr: qrcodegen::QrCode) -> image::ImageBuffer<Luma<u8>, Vec<u8>> {
+pub use image;
+pub use qrcodegen;
+
+/// Draw a QR code to an image buffer.
+pub fn draw_canvas(qr: qrcodegen::QrCode) -> image::ImageBuffer<Luma<u8>, Vec<u8>> {
let size = qr.size() as u32;
// "+ 8 * 8" is here to add padding (the white border around the QRCode)
// As some QRCode readers don't work without padding
@@ -42,7 +46,7 @@ pub(crate) fn get_qr_draw_canvas(qr: qrcodegen::QrCode) -> image::ImageBuffer<Lu
canvas
}
-/// Convert text to a PNG QR code.
+/// Draw text to a PNG QR code.
pub fn draw_png(text: &str) -> Result<Vec<u8>, String> {
use image::ImageEncoder;
@@ -64,7 +68,7 @@ pub fn draw_png(text: &str) -> Result<Vec<u8>, String> {
// As some QRCode readers don't work without padding
let image_size = (code.size() as u32) * 8 + 8 * 8;
- let canvas = get_qr_draw_canvas(code);
+ let canvas = draw_canvas(code);
// Encode the canvas into a PNG
let encoder = image::codecs::png::PngEncoder::new(&mut vec);
@@ -79,7 +83,7 @@ pub fn draw_png(text: &str) -> Result<Vec<u8>, String> {
}
}
-/// Convert text to a base64 encoded PNG QR code.
+/// Draw text to a Base64-encoded PNG QR code.
#[cfg(feature = "base64")]
pub fn draw_base64(text: &str) -> Result<String, String> {
use base64::{engine::general_purpose, Engine as _};
diff --git a/src/lib.rs b/src/lib.rs
index 130f5aa..272a7e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1197,6 +1197,7 @@ mod tests {
#[test]
#[cfg(feature = "qr")]
fn generates_qr() {
+ use qrcodegen_image::qrcodegen;
use sha2::{Digest, Sha512};
let totp = TOTP::new(
@@ -1212,7 +1213,7 @@ mod tests {
let url = totp.get_url();
let qr = qrcodegen::QrCode::encode_text(&url, qrcodegen::QrCodeEcc::Medium)
.expect("could not generate qr");
- let data = qr::get_qr_draw_canvas(qr).into_raw();
+ let data = qrcodegen_image::draw_canvas(qr).into_raw();
// Create hash from image
let hash_digest = Sha512::digest(data);