Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong qrcode size #64

Open
patrickelectric opened this issue Apr 9, 2024 · 1 comment
Open

wrong qrcode size #64

patrickelectric opened this issue Apr 9, 2024 · 1 comment

Comments

@patrickelectric
Copy link

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

@kennytm
Copy link
Owner

kennytm commented Apr 9, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants