Created
June 11, 2026 11:00
-
-
Save aspose-com-gists/16320a7da40aa770561c93ac18e2a42f to your computer and use it in GitHub Desktop.
Generate and Read Royal Mail QR Code in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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