qrcode-rust icon indicating copy to clipboard operation
qrcode-rust copied to clipboard

wrong qrcode size

Open patrickelectric opened this issue 1 year ago • 1 comments

let qr = QrCode::new(metadata).unwrap();
dbg!(qr.to_colors().len()); // 441

How it gets to 441 ? If the image is a square, it should be an even number.

I believe this is also affects the images as well:

qr.render::<Luma<u8>>().min_dimensions(200, 200).module_dimensions(0, 0).build();

Creates an image where the total number of pixels does not match dimensions and color type. E.g: 200x200*3 = 120000, but I'm getting crazy things like 127321

patrickelectric avatar Apr 09 '24 15:04 patrickelectric

If the image is a square, it should be an even number.

Huh.

441 = 21 x 21.

The .to_colors() method returns a vector of Color. The QR code here can be divided into 21x21 = 441 little squares each being either light (white) or dark (black). It has nothing to do with the size of image produced by .render().

Creates an image where the total number of pixels does not match dimensions and color type. E.g: 200x200*3 = 120000, but I'm getting crazy things like 127321

How did you even get that 127321. A Luma<u8> is a grayscale pixel so will only occupy 1 byte per pixel i.e. you don't need to multiply be 3. And 127321 is not a square number (127449 is, but no QR code can be this large).

kennytm avatar Apr 09 '24 16:04 kennytm