view mupdf-source/thirdparty/zxing-cpp/wrappers/python/demo_writer.py @ 22:d77477b4e151

Let _int_rc() also handle (i.e. ignore) a local version suffix
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 19 Sep 2025 12:05:57 +0200
parents b50eed0cc0ef
children
line wrap: on
line source

import sys
import zxingcpp
from PIL import Image

if len(sys.argv) < 3:
	format, content = zxingcpp.BarcodeFormat.QRCode, "I have the best words."
else:
	format, content = zxingcpp.barcode_format_from_str(sys.argv[1]), sys.argv[2]

# old writer API
img = zxingcpp.write_barcode(format, content, width=200, height=200)
Image.fromarray(img).save("test.png")

# new/experimental writer API
# barcode = zxingcpp.create_barcode(content, format, ec_level = "50%")

# img = barcode.to_image(size_hint = 500)
# Image.fromarray(img).save("test.png")

# svg = barcode.to_svg(with_hrt = True)
# with open("test.svg", "w") as svg_file:
# 	svg_file.write(svg)