I'm thinking of modeling a way to replicate QR code images into SVG files. The purpose of this would be to standardize our representation of QR codes on Wikisource, such as we already do with complex math equations, music sheets, etc.

QR codes will usually be in works from the early 2010s or later, since they became mainstream coinciding the early smartphone era, despite having been invented in the 1990s.

Proposed process edit

 
How to read error correction levels in a QR code manually
  • One time: Read the original QR code image (backend).
  • One time: Extract the following data:
  • URL
  • QR version
  • Data capacity
  • Error correction level
  • One time: Enter that information into a Wikisource template {{QR code}}, for example:
{{QR code|url=http://www.justice.gov/ier|version=37|data_capacity=...|error_correction_level=...}}
  • Dynamic: The template would dynamically produce an SVG file of the QR code without uploading it to Wikimedia Commons or anywhere else.

Proposed QR code template capabilities edit

{{QR code|url=http://www.justice.gov/ier|version=37|data_capacity=...|error_correction_level=...}}
  • Dynamically load a QR code based on the information provided above (usually this data is extracted from a QR code present on a scan, as detailed above).
  • Clicking on the image would automatically link you to the site that the QR code normally links to. This makes the QR code even more useful than it was in the original. (Sort of like how we make music sheets more usable than they originally were by allowing MIDI downloads.)
  • (Perhaps) allow users to download a JSON/XML/etc. file with the QR code metadata mentioned above, in case a reader wants to use that data themselves.

Examples of QR codes edit

Python script attempt edit

The following script tries to take the image File:DOJ IER QR Code.jpg (downloaded locally on my system) and do the above process. Update: The below code actually works!!! Thank God!!! This will just read the text returned by a QR code from an image, into UTF-8 format.

from pyzbar.pyzbar import decode
from PIL import Image

def read_qr_code(filename):
    """Read an image and read the QR code.

    Args:
        filename (string): Path to file

    Returns:
        qr (string): Value from QR code
    """
    try:
        img = Image.open(filename)
        qr_codes = decode(img)
        if qr_codes:
            return qr_codes[0].data.decode('utf-8')
        else:
            return "No QR Code detected"
    except Exception as e:
        return f"ERROR: {str(e)}"

# Example usage
value = read_qr_code('qrtest.png')
print(value)

Resources edit


 

I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible:

I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

Public domainPublic domainfalsefalse