mirror of
https://github.com/tcsenpai/qrare.git
synced 2025-06-06 03:05:27 +00:00
moar customization, sillier example
This commit is contained in:
parent
0f58e14391
commit
2a588025d7
@ -1,11 +1,11 @@
|
||||
import qraro
|
||||
|
||||
with open("input_test_file.txt", "rb") as f:
|
||||
with open("pika.webp", "rb") as f:
|
||||
data = f.read()
|
||||
|
||||
qraro.bin_to_qr(data, chunk_size=50)
|
||||
qraro.bin_to_qr(data, chunk_size=100, box_size=10, border=4)
|
||||
|
||||
test_file = qraro.qr_to_bin()
|
||||
|
||||
with open("output_test_file.txt", "wb") as f:
|
||||
with open("pika_out.webp", "wb") as f:
|
||||
f.write(test_file)
|
10
qraro.py
10
qraro.py
@ -2,18 +2,19 @@ import qrcode
|
||||
from PIL import Image
|
||||
import zxing
|
||||
|
||||
def bin_to_qr(data, chunk_size=100, filename_prefix="qr_code"):
|
||||
def bin_to_qr(data, chunk_size=100, filename_prefix="qr_code", box_size=10, border=4):
|
||||
hex_data = data.hex()
|
||||
chunks = [hex_data[i:i+chunk_size] for i in range(0, len(hex_data), chunk_size)]
|
||||
total_chunks = len(chunks)
|
||||
|
||||
for i, chunk in enumerate(chunks, 1):
|
||||
qr = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
|
||||
qr = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=box_size, border=border)
|
||||
qr.add_data(f"{i}/{total_chunks}:{chunk}")
|
||||
qr.make(fit=True)
|
||||
|
||||
print(f"Generating QR code {i}", end="")
|
||||
img = qr.make_image(fill_color="black", back_color="white")
|
||||
img.save(f"{filename_prefix}_{i}.png")
|
||||
print(f"[OK]")
|
||||
|
||||
print(f"Generated {total_chunks} QR codes.")
|
||||
|
||||
@ -25,7 +26,9 @@ def qr_to_bin(filename_prefix="qr_code"):
|
||||
while True:
|
||||
try:
|
||||
filename = f"{filename_prefix}_{i}.png"
|
||||
print(f"Decoding QR code {i}...", end="")
|
||||
barcode = reader.decode(filename)
|
||||
print(f"decoded...", end="")
|
||||
if barcode and barcode.parsed:
|
||||
decoded = barcode.parsed
|
||||
chunk_info, chunk_data = decoded.split(':', 1)
|
||||
@ -34,6 +37,7 @@ def qr_to_bin(filename_prefix="qr_code"):
|
||||
if chunk_num == total_chunks:
|
||||
break
|
||||
i += 1
|
||||
print(f"binary data extracted [OK]")
|
||||
except FileNotFoundError:
|
||||
break
|
||||
except Exception as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user