示例#1
0
文件: test.py 项目: nu-book/zxing-cpp
	def test_write_read_multi_cycle(self):
		format = BF.QRCode
		text = "I have the best words."
		img = zxingcpp.write_barcode(format, text)

		res = zxingcpp.read_barcodes(img)[0]
		self.check_res(res, format, text)
示例#2
0
文件: test.py 项目: nu-book/zxing-cpp
	def test_write_read_cycle_pil(self):
		from PIL import Image
		format = BF.QRCode
		text = "I have the best words."
		img = zxingcpp.write_barcode(format, text)
		img = Image.fromarray(img, "L")

		self.check_res(zxingcpp.read_barcode(img), format, text)
		self.check_res(zxingcpp.read_barcode(img.convert("RGB")), format, text)
		self.check_res(zxingcpp.read_barcode(img.convert("RGBA")), format, text)
		self.check_res(zxingcpp.read_barcode(img.convert("1")), format, text)
		self.check_res(zxingcpp.read_barcode(img.convert("CMYK")), format, text)
示例#3
0
文件: test.py 项目: nu-book/zxing-cpp
	def test_write_read_cycle(self):
		format = BF.QRCode
		text = "I have the best words."
		img = zxingcpp.write_barcode(format, text)

		res = zxingcpp.read_barcode(img)
		self.check_res(res, format, text)
		self.assertEqual(res.symbology_identifier, "]Q1")
		self.assertEqual(res.position.top_left.x, 4)

		res = zxingcpp.read_barcode(img, formats=format)
		self.check_res(res, format, text)
示例#4
0
文件: test.py 项目: nu-book/zxing-cpp
	def test_write_read_oned_cycle(self):
		format = BF.Code128
		text = "I have the best words."
		height = 80
		width = 400
		img = zxingcpp.write_barcode(format, text, width=width, height=height)
		self.assertEqual(img.shape[0], height)
		self.assertEqual(img.shape[1], width)

		res = zxingcpp.read_barcode(img)
		self.check_res(res, format, text)
		self.assertEqual(res.position.top_left.x, 61)
示例#5
0
import sys
import zxingcpp
from PIL import Image

if len(sys.argv) < 3:
    img = zxingcpp.write_barcode(zxingcpp.BarcodeFormat.QRCode,
                                 "I have the best words.",
                                 width=200,
                                 height=200)
else:
    img = zxingcpp.write_barcode(zxingcpp.barcode_format_from_str(sys.argv[1]),
                                 sys.argv[2],
                                 width=200,
                                 height=200)
Image.fromarray(img).save("test.png")