Ensure QR codes have a border large enough (#235)
* Ensure QR codes have a border large enough (The QR code spec requires a border at least 4*box_size thick but we can't just set border=16 because that results in a QR code more than 255px tall and I'm not yet ready to use fullimage() as a backend for it) This fix was originally commited by Stephan Sokolow on 2014-05-22 * Let the user print stuff using qr example * fix tests
This commit is contained in:
parent
89dfb6cf86
commit
5bd6dcf471
|
@ -0,0 +1,19 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from escpos.printer import Usb
|
||||||
|
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
print("usage: qr_code.py <content>")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
usage()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
content = sys.argv[1]
|
||||||
|
|
||||||
|
# Adapt to your needs
|
||||||
|
p = Usb(0x0416, 0x5011, profile="POS-5890")
|
||||||
|
p.qr(content)
|
|
@ -211,7 +211,10 @@ class Escpos(object):
|
||||||
qr_img = qr_code.make_image()
|
qr_img = qr_code.make_image()
|
||||||
im = qr_img._img.convert("RGB")
|
im = qr_img._img.convert("RGB")
|
||||||
# Convert the RGB image in printable image
|
# Convert the RGB image in printable image
|
||||||
|
self.text('\n')
|
||||||
self.image(im)
|
self.image(im)
|
||||||
|
self.text('\n')
|
||||||
|
self.text('\n')
|
||||||
return
|
return
|
||||||
# Native 2D code printing
|
# Native 2D code printing
|
||||||
cn = b'1' # Code type for QR code
|
cn = b'1' # Code type for QR code
|
||||||
|
|
|
@ -86,9 +86,11 @@ def test_image():
|
||||||
instance = printer.Dummy()
|
instance = printer.Dummy()
|
||||||
instance.qr("1", native=False, size=1)
|
instance.qr("1", native=False, size=1)
|
||||||
print(instance.output)
|
print(instance.output)
|
||||||
expected = b'\x1dv0\x00\x03\x00\x17\x00\x00\x00\x00\x7f]\xfcA\x19\x04]it]et' \
|
expected = b'\x1bt\x00\n' \
|
||||||
|
b'\x1dv0\x00\x03\x00\x17\x00\x00\x00\x00\x7f]\xfcA\x19\x04]it]et' \
|
||||||
b']ItA=\x04\x7fU\xfc\x00\x0c\x00y~t4\x7f =\xa84j\xd9\xf0\x05\xd4\x90\x00' \
|
b']ItA=\x04\x7fU\xfc\x00\x0c\x00y~t4\x7f =\xa84j\xd9\xf0\x05\xd4\x90\x00' \
|
||||||
b'i(\x7f<\xa8A \xd8]\'\xc4]y\xf8]E\x80Ar\x94\x7fR@\x00\x00\x00'
|
b'i(\x7f<\xa8A \xd8]\'\xc4]y\xf8]E\x80Ar\x94\x7fR@\x00\x00\x00' \
|
||||||
|
b'\n\n'
|
||||||
assert(instance.output == expected)
|
assert(instance.output == expected)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue