Пример #1
0
    def test_write_read_cycle(self):
        format = BF.QR_CODE
        text = "I have the best words."
        img = zxing.write_barcode(format, text)
        res = zxing.read_barcode(img)

        self.assertTrue(res.valid)
        self.assertEqual(res.format, format)
        self.assertEqual(res.text, text)
Пример #2
0
    def test_write_read_cycle(self):
        format = BF.QRCode
        text = "I have the best words."
        img = zxing.write_barcode(format, text)
        res = zxing.read_barcode(img)

        self.assertTrue(res.valid)
        self.assertEqual(res.format, format)
        self.assertEqual(res.text, text)
        self.assertEqual(res.orientation, 0)
        self.assertEqual(res.position.topLeft.x, 4)
Пример #3
0
    def test_write_read_oned_cycle(self):
        format = BF.Code128
        text = "I have the best words."
        height = 80
        width = 400
        img = zxing.write_barcode(format, text, width=width, height=height)
        self.assertEqual(img.shape[0], height)
        self.assertEqual(img.shape[1], width)

        res = zxing.read_barcode(img)
        self.assertTrue(res.valid)
        self.assertEqual(res.format, format)
        self.assertEqual(res.text, text)
        self.assertEqual(res.orientation, 0)
        self.assertEqual(res.position.topLeft.x, 61)
Пример #4
0
	def test_write_read_cycle_pil(self):
		from PIL import Image
		format = BF.QRCode
		text = "I have the best words."
		img = zxing.write_barcode(format, text)
		img = Image.fromarray(img, "L")

		res = zxing.read_barcode(img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		rgb_img = img.convert("RGB")
		res = zxing.read_barcode(rgb_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		rgba_img = img.convert("RGBA")
		res = zxing.read_barcode(rgba_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		bin_img = img.convert("1")
		res = zxing.read_barcode(bin_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)

		cmyk_img = img.convert("CMYK")
		res = zxing.read_barcode(cmyk_img)
		self.assertTrue(res.valid)
		self.assertEqual(res.format, format)
		self.assertEqual(res.text, text)
		self.assertEqual(res.orientation, 0)
		self.assertEqual(res.position.top_left.x, 4)
Пример #5
0
import sys
import zxing
from PIL import Image

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