demo_writer.py 647 B

12345678910111213141516171819202122
  1. import sys
  2. import zxingcpp
  3. from PIL import Image
  4. if len(sys.argv) < 3:
  5. format, content = zxingcpp.BarcodeFormat.QRCode, "I have the best words."
  6. else:
  7. format, content = zxingcpp.barcode_format_from_str(sys.argv[1]), sys.argv[2]
  8. # old writer API
  9. img = zxingcpp.write_barcode(format, content, width=200, height=200)
  10. Image.fromarray(img).save("test.png")
  11. # new/experimental writer API
  12. # barcode = zxingcpp.create_barcode(content, format, ec_level = "50%")
  13. # img = barcode.to_image(size_hint = 500)
  14. # Image.fromarray(img).save("test.png")
  15. # svg = barcode.to_svg(with_hrt = True)
  16. # with open("test.svg", "w") as svg_file:
  17. # svg_file.write(svg)