mirror of
https://github.com/tcsenpai/qrare.git
synced 2025-06-06 03:05:27 +00:00
added gzip compression by default
This commit is contained in:
parent
2767e14fbe
commit
391dda9840
16
README.md
16
README.md
@ -7,12 +7,13 @@ This Python module provides functionality to encode arbitrary binary data into a
|
|||||||
- Python 3.x
|
- Python 3.x
|
||||||
- qrcode
|
- qrcode
|
||||||
- qrtools
|
- qrtools
|
||||||
|
- compress
|
||||||
- Pillow (PIL)
|
- Pillow (PIL)
|
||||||
- zxing
|
- zxing
|
||||||
|
|
||||||
Install the required libraries using pip:
|
Install the required libraries using pip:
|
||||||
|
|
||||||
`pip install qrcode pillow zxing`
|
`pip install qrcode pillow zxing compress`
|
||||||
|
|
||||||
Or install the dependencies using:
|
Or install the dependencies using:
|
||||||
|
|
||||||
@ -30,10 +31,11 @@ Parameters:
|
|||||||
- `filename_prefix` (str, optional): The prefix for the generated QR code image filenames. Default is "qr_code".
|
- `filename_prefix` (str, optional): The prefix for the generated QR code image filenames. Default is "qr_code".
|
||||||
|
|
||||||
This function performs the following steps:
|
This function performs the following steps:
|
||||||
1. Converts the binary data to a hexadecimal string.
|
1. Compresses the binary data using gzip.
|
||||||
2. Splits the hex string into chunks of the specified size.
|
2. Converts the binary data to a hexadecimal string.
|
||||||
3. Creates a QR code for each chunk, including chunk number and total chunk count.
|
3. Splits the hex string into chunks of the specified size.
|
||||||
4. Saves each QR code as a PNG image.
|
4. Creates a QR code for each chunk, including chunk number and total chunk count.
|
||||||
|
5. Saves each QR code as a PNG image.
|
||||||
|
|
||||||
### qr_to_bin(filename_prefix="qr_code")
|
### qr_to_bin(filename_prefix="qr_code")
|
||||||
|
|
||||||
@ -51,6 +53,8 @@ This function performs the following steps:
|
|||||||
3. Extracts chunk information and data from each decoded QR code.
|
3. Extracts chunk information and data from each decoded QR code.
|
||||||
4. Reconstructs the original hexadecimal string from the chunks.
|
4. Reconstructs the original hexadecimal string from the chunks.
|
||||||
5. Converts the hexadecimal string back to binary data.
|
5. Converts the hexadecimal string back to binary data.
|
||||||
|
6. Decompresses the binary data using gzip.
|
||||||
|
7. Returns the decompressed binary data.
|
||||||
|
|
||||||
## Usage Example
|
## Usage Example
|
||||||
|
|
||||||
@ -74,6 +78,8 @@ print("Original and decoded data match:", original_data == decoded_data)
|
|||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
- The script automatically determines the appropriate QR code version based on the data size.
|
- The script automatically determines the appropriate QR code version based on the data size.
|
||||||
|
- Data is compressed using gzip before being encoded into QR codes to maximize data capacity.
|
||||||
|
- Data is then decompressed using gzip after being decoded from QR codes.
|
||||||
- Error correction level is set to LOW (L) to maximize data capacity.
|
- Error correction level is set to LOW (L) to maximize data capacity.
|
||||||
- The script handles binary data, including non-printable characters.
|
- The script handles binary data, including non-printable characters.
|
||||||
- THe script has a fallback method that (until now) allows for a 100% error free decoding.
|
- THe script has a fallback method that (until now) allows for a 100% error free decoding.
|
||||||
|
20
qraro.py
20
qraro.py
@ -1,9 +1,11 @@
|
|||||||
import qrcode
|
import qrcode
|
||||||
import zxing
|
import zxing
|
||||||
import qrtools
|
import qrtools
|
||||||
|
from compress import Compressor
|
||||||
|
|
||||||
def bin_to_qr(data, chunk_size=100, filename_prefix="qr_code", box_size=10, border=4):
|
def bin_to_qr(data, chunk_size=100, filename_prefix="qr_code", box_size=10, border=4):
|
||||||
hex_data = data.hex()
|
compressed_data = compress_bytes(data)
|
||||||
|
hex_data = compressed_data.hex()
|
||||||
chunks = [hex_data[i:i+chunk_size] for i in range(0, len(hex_data), chunk_size)]
|
chunks = [hex_data[i:i+chunk_size] for i in range(0, len(hex_data), chunk_size)]
|
||||||
total_chunks = len(chunks)
|
total_chunks = len(chunks)
|
||||||
|
|
||||||
@ -63,6 +65,18 @@ def qr_to_bin(filename_prefix="qr_code"):
|
|||||||
print("No QR codes found.")
|
print("No QR codes found.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
hex_data = ''.join(chunks[i] for i in range(1, len(chunks) + 1))
|
hex_data_compressed = ''.join(chunks[i] for i in range(1, len(chunks) + 1))
|
||||||
return bytes.fromhex(hex_data)
|
bytes_compressed = bytes.fromhex(hex_data_compressed)
|
||||||
|
return decompress_bytes(bytes_compressed)
|
||||||
|
|
||||||
|
# Compressing as much as possible
|
||||||
|
|
||||||
|
def compress_bytes(data):
|
||||||
|
compressor = Compressor()
|
||||||
|
compressor.use_gzip()
|
||||||
|
return compressor.compress(data)
|
||||||
|
|
||||||
|
def decompress_bytes(data):
|
||||||
|
compressor = Compressor()
|
||||||
|
compressor.use_gzip()
|
||||||
|
return compressor.decompress(data)
|
@ -1,4 +1,5 @@
|
|||||||
qrcode
|
qrcode
|
||||||
Pillow
|
Pillow
|
||||||
zxing
|
zxing
|
||||||
qrtools
|
qrtools
|
||||||
|
compress
|
Loading…
x
Reference in New Issue
Block a user