diff --git a/example_with_files.py b/example_with_files.py index 4eabed0..f1f7f0a 100644 --- a/example_with_files.py +++ b/example_with_files.py @@ -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) \ No newline at end of file diff --git a/pika.webp b/pika.webp new file mode 100644 index 0000000..ba82749 Binary files /dev/null and b/pika.webp differ diff --git a/qraro.py b/qraro.py index 4b3b0d4..611bc8c 100644 --- a/qraro.py +++ b/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: