File: demo_writer.py

package info (click to toggle)
zxing-cpp 2.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,832 kB
  • sloc: cpp: 32,803; ansic: 18,360; php: 1,156; python: 215; makefile: 25; sh: 3
file content (22 lines) | stat: -rw-r--r-- 647 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)