Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/16320a7da40aa770561c93ac18e2a42f to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/16320a7da40aa770561c93ac18e2a42f to your computer and use it in GitHub Desktop.
Generate and Read Royal Mail QR Code in Python
# Generate and Read Royal Mail QR Code in Python
# Read the full guide here: https://blog.aspose.com/barcode/generate-and-read-royal-mail-qr-code-in-python/
import asposebarcode as barcode
# 1. Initialize the generator for QR code
generator = barcode.BarcodeGenerator(
symbology=barcode.Symbology.QR,
code_text="1234567890" # Sample data required by Royal Mail
)
# 2. Configure Royal Mail specific parameters
generator.parameters.qr.error_correction = barcode.QRErrorCorrectionLevel.Q
generator.parameters.qr.version = 5 # Recommended version for Royal Mail
generator.parameters.qr.module_size = 5 # Size of each module (pixel)
generator.parameters.qr.quiet_zone = 4 # Quiet zone width
# 3. Save the QR code as PNG (lossless for best readability)
output_path = "output/royal_mail_qr.png"
generator.save(output_path, barcode.BarcodeImageFormat.PNG)
# 4. Initialize the reader and decode the saved image
reader = barcode.BarcodeReader()
reader.read(output_path)
# 5. Extract and display the decoded text
if reader.found:
decoded_text = reader.get_code_text()
print(f"Decoded text: {decoded_text}")
else:
print("No QR code detected.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment