本文整理汇总了Python中Adafruit_Thermal.printImage方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_Thermal.printImage方法的具体用法?Python Adafruit_Thermal.printImage怎么用?Python Adafruit_Thermal.printImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_Thermal
的用法示例。
在下文中一共展示了Adafruit_Thermal.printImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_password
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def print_password(headerText, ttp):
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 4), "white"), (0, 0))
# create the divider
bottomDividerLineImg = Image.open("/home/pi/Printer/dividerline.bmp")
font = ImageFont.truetype("/usr/share/fonts/ttf/swansea.ttf", 20)
draw = ImageDraw.Draw(bottomDividerLineImg)
rightMarkText = "Piperwallet.com"
rightMarkSize = draw.textsize(rightMarkText, font=font)
leftMarkOrigin = (10, 15)
rightMarkOrigin = (384 - rightMarkSize[0] - 10, 15)
draw.text(leftMarkOrigin, headerText, font=font, fill=(0, 0, 0))
draw.text(rightMarkOrigin, rightMarkText, font=font, fill=(0, 0, 0))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(dividerLine, True)
printer.println("Password: ")
printer.println(ttp)
printer.printImage(bottomDividerLineImg, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例2: upload_file
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def upload_file():
if request.method == 'POST':
uploadedFile = request.files['file']
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(Image.open(uploadedFile), True)
printer.feed(10)
redirect("/printer")
示例3: print_image
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def print_image(filename):
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.feed(5)
image = Image.open(filename)
image = image.rotate(90, expand=1)
image = ImageEnhance.Contrast(image).enhance(1.3) # add contrast
printer.printImage(image, True)
printer.feed(5)
示例4: encodeQRAndPrint
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def encodeQRAndPrint(ttp):
qrSize = (340, 340)
finalImg = Image.new("RGB", (384, 440), "white")
finalImg.paste(getQR(ttp, qrSize), (30, 55))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(finalImg, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例5: __init__
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
class thermal_printer:
def __init__(self):
self.printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
def printImg(self, img, priv_key):
self.printer.feed(3)
self.printer.printImage(img)
# I have some reservation about how to deal with encrypted private key, but need to wait for thermal_printer to look into it.
if len(priv_key) <= 51:
self.printer.printChar(priv_key[:17]+"\n")
self.printer.justify("R")
self.printer.printChar(priv_key[17:34]+"\n")
self.printer.justify("L")
self.printer.printChar(priv_key[34:]+"\m")
else:
self.printer.println(priv_key)
示例6: printHDMWalletSeed
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def printHDMWalletSeed(headerText, seed, xpub):
qrSize = (170,170)
qrPad = 10
finalImg = Image.new("RGB", (384, qrSize[1]), "white")
finalImg.paste(getQR(seed, qrSize), (qrPad, 0))
finalImg.paste(getQR(xpub, qrSize), (qrSize[0]+qrPad*2+14, 0))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 4), "white"), (0, 0))
printer.printImage(dividerLine, True)
printer.println(headerText)
printer.println("Seed Mnemonic: "+seed+'\n')
printer.println("xpub: "+xpub+'\n')
printer.printImage(finalImg, True)
printer.feed(1)
printer.printImage(dividerLine, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例7: encodeQRAndPrintText
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def encodeQRAndPrintText(headerText, ttp):
qrSize = (340, 340)
finalImg = Image.new("RGB", (384, 440), "white")
finalImg.paste(getQR(ttp, qrSize), (30, 55))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 3), "white"), (0, 0))
printer.printImage(dividerLine, True)
printer.println(headerText)
printer.println(ttp)
printer.printImage(finalImg, True)
printer.println(ttp)
printer.printImage(dividerLine, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例8: splitAndPrint
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
def splitAndPrint(ttp, k, n):
print "Thing to split: "+ttp
#first, split it up
secret = Secret.from_printable_ascii(ttp)
shares = secret.split(int(k), int(n))
#now convert to QR codes and print the shares
print shares
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
qrSize = (340, 340)
ctr = 0
qrImg = {}
for shr in shares:
print "Share: "+shr
finalImg = Image.new("RGB", (384, 440), "white")
finalImg.paste(getQR(shr, qrSize), (30, 55))
qrImg[shr] = finalImg
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 3), "white"), (0, 0))
for shr in shares:
printer.printImage(dividerLine, True)
printer.println("This is a share in a "+k+" of "+n+"\nthreshold scheme")
printer.println(shr)
printer.printImage(qrImg[shr], True)
printer.println(shr)
printer.println("Shamir's Secret Sharing")
printer.printImage(dividerLine, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例9: numWidth
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
if windDir < DirAngle[winDirNum]: break
w = Humidity.size[0] + 5 + numWidth(s, HumiDigit)
w2 = Wind.size[0] + 5 + numWidth(s2, HumiDigit)
if windSpeed > 0:
w2 += 3 + Dir[winDirNum].size[0]
if windUnits == 'kph': w2 += 3 + Kph.size[0]
else: w2 += 3 + Mph.size[0]
if w2 > w: w = w2
# Draw humidity and wind
x = img.size[0] - w # Left-align the two lines
y = 67
img.paste(Humidity, (x, y))
x += Humidity.size[0] + 5
drawNums(s, x, y, HumiDigit)
x = img.size[0] - w # Left-align again
y += 23 # And advance to next line
img.paste(Wind, (x, y))
x += Wind.size[0] + 5
if windSpeed > 0:
img.paste(Dir[winDirNum], (x, y))
x += Dir[winDirNum].size[0] + 3
x = drawNums(s2, x, y, HumiDigit) + 3
if windUnits == 'kph': img.paste(Kph, (x, y))
else: img.paste(Mph, (x, y))
# Open connection to printer and print image
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(img, True)
printer.feed(3)
示例10: print_keypair
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
#.........这里部分代码省略.........
#---begin the private key qr code generation and drawing section---
#we begin the QR code creation process
#feel free to change the error correct level as you see fit
qr = qrcode.QRCode(
version=None,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=10,
border=0,
)
qr.add_data(privkey)
qr.make(fit=True)
privkeyImg = qr.make_image()
#resize the qr code to match our design
privkeyImg = privkeyImg.resize((220,220), Image.NEAREST)
startPos=(110,807)
charDist=15
lineHeight=23
lastCharPos=0
keyLength = len(privkey)
#draw 2 lines of 17 characters each. keyLength always == 34 so keylength/17 == 2
for x in range(0,keyLength/17):
lastCharPos=0
#print a line
for y in range(0, 17):
theChar = privkey[(x*17)+y]
charSize = draw.textsize(theChar, font=font)
#print charSize
if y == 0:
draw.text((startPos[0],startPos[1]+(lineHeight*x)),theChar, font=font, fill=(0,0,0))
lastCharPos = startPos[0]+charSize[0]+(charDist-charSize[0])
else:
draw.text((lastCharPos,startPos[1]+(lineHeight*x)),theChar, font=font, fill=(0,0,0))
lastCharPos = lastCharPos + charSize[0] + (charDist-charSize[0])
#draw the QR code on the final image
finalImg.paste(privkeyImg, (125, 560))
#---end the private key qr code generation and drawing section---
#create the divider
rightMarkText = "Piperwallet.com"
font = ImageFont.truetype("/usr/share/fonts/ttf/swansea.ttf", 20)
rightMarkSize = draw.textsize(rightMarkText, font=font)
rightMarkOrigin = (384-rightMarkSize[0]-10, 10)
dividerLineImg = Image.open("/home/pi/Printer/dividerline.bmp")
#font = ImageFont.truetype("/home/pi/Helvetica.ttf", 20)
draw = ImageDraw.Draw(dividerLineImg)
draw.text(rightMarkOrigin,rightMarkText, font=font, fill=(255,255,255))
#do the actual printing
printer.printImage(finalImg)
printer.printChar(privkey[:17]+"\n")
printer.justify('R')
printer.printChar(privkey[17:34]+"\n")
printer.justify('L')
printer.printChar(privkey[34:]+"\n")
#print the divider line
time.sleep(0.4)
printer.printImage(dividerLineImg)
#print some blank space so we can get a clean tear of the paper
time.sleep(0.4)
printer.feed(1)
time.sleep(0.4)
printer.feed(1)
time.sleep(0.4)
printer.feed(1)
printer.sleep() # Tell printer to sleep
printer.wake() # Call wake() before printing again, even if reset
printer.setDefault() # Restore printer to defaults
示例11: exit
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
printer.print('IP address: ' + s.getsockname()[0])
ip = s.getsockname()[0]
printer.feed(1)
except:
printer.boldOn()
printer.println('Network is unreachable.')
printer.boldOff()
printer.print('Connect display and keyboard\n'
'for network troubleshooting.')
printer.print('Shutting down...')
printer.feed(3)
exit(0)
# Print greeting image
printer.feed(3)
printer.printImage(Image.open('40in20out_logo.bmp'), True)
printer.feed(1)
printer.print("40in20out")
printer.feed(1)
printer.print("Presented by...")
printer.feed(1)
printer.printImage(Image.open('totemasset_logo.bmp'), True)
printer.feed(2)
GPIO.output(ledPin, GPIO.LOW)
# Poll initial button state and time
prevButtonState = GPIO.input(buttonPin)
prevTime = time.time()
tapEnable = False
示例12: print_keypair
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
#.........这里部分代码省略.........
#we begin the QR code creation process
#feel free to change the error correct level as you see fit
qr = qrcode.QRCode(
version=None,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=10,
border=0,
)
qr.add_data(privkey)
qr.make(fit=True)
privkeyImg = qr.make_image()
#resize the qr code to match our design
privkeyImg = privkeyImg.resize((220,220), Image.NEAREST)
#draw the QR code on the final image
finalImg.paste(privkeyImg, (125, 560))
startPos=(110,807)
charDist=15
lineHeight=23
lastCharPos=0
keyLength = len(privkey)
while(keyLength % 17 != 0):
privkey += " "
keyLength = len(privkey)
#draw 2 lines of 17 characters each. keyLength always == 34 so keylength/17 == 2
for x in range(0,keyLength/17):
lastCharPos=0
#print a line
for y in range(0, 17):
theChar = privkey[(x*17)+y]
charSize = draw.textsize(theChar, font=font)
#print charSize
if y == 0:
draw.text((startPos[0],startPos[1]+(lineHeight*x)),theChar, font=font, fill=0)
lastCharPos = startPos[0]+charSize[0]+(charDist-charSize[0])
else:
draw.text((lastCharPos,startPos[1]+(lineHeight*x)),theChar, font=font, fill=0)
lastCharPos = lastCharPos + charSize[0] + (charDist-charSize[0])
#---end the private key qr code generation and drawing section---
#create the divider
rightMarkText = "ArchReactor.org"
font = ImageFont.truetype("/usr/share/fonts/ttf/swansea.ttf", 20)
rightMarkSize = draw.textsize(rightMarkText, font=font)
leftMarkOrigin = (10, 15)
rightMarkOrigin = (384-rightMarkSize[0]-10, 15)
dividerLineImg = Image.open("/home/pi/build/Piper/dividerline.bmp")
draw = ImageDraw.Draw(dividerLineImg)
draw.text(leftMarkOrigin, leftBorderText, font=font, fill=0)
draw.text(rightMarkOrigin,rightMarkText, font=font, fill=0)
#finalImg.save('file.png')
#dividerLineImg.save('file2.png')
#do the actual printing
usd = 1.0/float(curbtc)
returnamt = usd*float(inputamt)
printer.println("1BTC=$"+str(curbtc))
printer.println("1USD=B"+str(usd))
printer.println("Input=$"+str(inputamt))
printer.println("Return=B"+str(returnamt))
printer.println("Transaction Hash: "+str(tx_hash))
printer.printImage(finalImg)
#if(len(privkey) <= 51):
# printer.println(privkey[:17]+"\n")
# printer.justify('R')
# printer.println(privkey[17:34]+"\n")
# printer.justify('L')
# printer.println(privkey[34:]+"\n")
#else:
# printer.println(privkey)
#print the divider line
printer.printImage(dividerLineImg)
#print some blank space so we can get a clean tear of the paper
printer.feed(3)
printer.sleep() # Tell printer to sleep
printer.wake() # Call wake() before printing again, even if reset
printer.setDefault() # Restore printer to defaults
示例13: print
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
# print all of the images!
for i in sys.argv[1:]:
if i[0] == '-':
if i[1] == 'n':
no_print = 1
elif i[1] == 'u':
upscale = 1
continue
im = Image.open(i)
#im = im.transpose(Image.ROTATE_90)#.transpose(Image.FLIP_TOP_BOTTOM)
print("OLDSIZE", im.size)
if im.size[0] > max_width or (upscale and im.size[0] < max_width):
newsize = (max_width, int(float(im.size[1]) / (float(im.size[0]) / max_width)))
print("NEWSIZE", newsize)
im = im.resize(newsize, Image.ANTIALIAS)
# PIL algorithm: convert to greyscale then convert to mono with dithering
im = im.convert('1')
im.save("p.jpg", "jpeg")
if not no_print:
printer = Adafruit_Thermal(timeout=5)
printer.printImage(im, False)
printer.feedRows(50)
示例14: button
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
GPIO.setmode(GPIO.BCM)
# Enable LED and button (w/pull-up on latter)
GPIO.setup(ledPin, GPIO.OUT)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# LED on while working
GPIO.output(ledPin, GPIO.HIGH)
# Processor load is heavy at startup; wait a moment to avoid
# stalling during greeting.
# time.sleep(30)
# Print greeting image
printer.feed(1)
printer.printImage(Image.open('40in20out_logo.bmp'), True)
printer.feed(1)
printer.print("40in20out")
printer.feed(1)
printer.print("Presented by...")
printer.feed(1)
printer.printImage(Image.open('totemasset_logo.bmp'), True)
printer.feed(2)
GPIO.output(ledPin, GPIO.LOW)
# Show IP address (if network is available)
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 0))
printer.print('My IP address is ' + s.getsockname()[0])
ip = s.getsockname()[0]
示例15: exit
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import printImage [as 别名]
printer.print('Welcome to the Tatadada Table! \n My IP address is ' + s.getsockname()[0])
printer.feed(3)
except:
printer.boldOn()
printer.println('Network is unreachable.')
printer.boldOff()
printer.print('Connect display and keyboard\n'
'for network troubleshooting.')
printer.feed(3)
exit(0)
# Print greeting image
# printer.printImage(Image.open('gfx/welcome.png'), True)
# printer.feed(3)
printer.printImage(Image.open('gfx/logo-tatadada.png'), True)
printer.feed(3)
#printer.printImage(Image.open('gfx/ladybug.png'), True)
#printer.feed(3)
GPIO.output(ledPin, GPIO.LOW)
# Poll initial button state and time
prevButtonState = GPIO.input(buttonPin)
prevTime = time.time()
tapEnable = False
holdEnable = False
# Main loop
while (True):