Introduce new direct_image
* The direct_image method prints directly from the PIL image object * The image should be converted to 1 bit before * The method was derived from png2escpos (https://github.com/twg/png2escpos)
This commit is contained in:
parent
dd228c9fda
commit
0ef2951c7e
|
@ -14,6 +14,7 @@ except ImportError:
|
|||
import qrcode
|
||||
import time
|
||||
import textwrap
|
||||
import binascii
|
||||
|
||||
from .constants import *
|
||||
from .exceptions import *
|
||||
|
@ -114,6 +115,38 @@ class Escpos:
|
|||
# Convert the RGB image in printable image
|
||||
self._convert_image(im)
|
||||
|
||||
def direct_image(self, image):
|
||||
""" Send image to printer"""
|
||||
mask = 0x80
|
||||
i = 0
|
||||
temp = 0
|
||||
|
||||
(width, height) = image.size
|
||||
self._raw(S_RASTER_N)
|
||||
headerX = int(width / 8)
|
||||
headerY = height
|
||||
buf = "%02X" % (headerX & 0xff)
|
||||
buf += "%02X" % ((headerX >> 8) & 0xff)
|
||||
buf += "%02X" % (headerY & 0xff)
|
||||
buf += "%02X" % ((headerY >> 8) & 0xff)
|
||||
#self._raw(binascii.unhexlify(buf))
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
value = image.getpixel((x,y))
|
||||
value = (value << 8) | value;
|
||||
if value == 0:
|
||||
temp |= mask
|
||||
|
||||
mask = mask >> 1
|
||||
|
||||
i += 1
|
||||
if i == 8:
|
||||
buf += ("%02X" % temp)
|
||||
mask = 0x80
|
||||
i = 0
|
||||
temp = 0
|
||||
self._raw(binascii.unhexlify(buf))
|
||||
|
||||
|
||||
def qr(self,text):
|
||||
""" Print QR Code for the provided string """
|
||||
|
|
Loading…
Reference in New Issue