erwanvivien / fast_qr

Ultra fast QRCode generation
https://fast-qr.com/
MIT License
197 stars 29 forks source link

QR Codes are Diagonally Inverted When Rendered as SVGs/PNGs #47

Closed Adam-Alj closed 8 months ago

Adam-Alj commented 8 months ago

Hey! Big fan of the library, though I came across a strange issue the other day.

Seems as though the QR codes are rendered with a diagonal inversion for image/svg output.

This can be verified by looking at the format information (as per ISO/IEC 18004 2015), specifically the first two error correction bits and their placement.

This diagram from Wikipedia summarizes the expectations of the format sequence. https://en.wikipedia.org/wiki/File:QR_Format_Information.svg


I used this snippet to create the QRCode for the following tests:

    let qrcode = QRBuilder::new("Test")
        .ecl(ECL::M)
        .version(Version::V01)
        .build()
        .unwrap();

With an ECL::M, we expect to see the ECL sequence of [1,0].

In the following images, the red and blue borders highlight the format sequences, with the green highlighting the ECL sequence.

When printing to our terminal, we see the format sequences aligned correctly:

printed_to_terminal

However, when rendering an SVG or PNG, we notice the diagonal inversion, causing inversion of the format sequences:

rendered_as_image

Note that the rest of the QR code is also diagonally inverted.

erwanvivien commented 8 months ago

Hey, big sorry haven't seen the issue ! Checking the PR