def capture(image): serialport = ThermalPrinter.SERIALPORT if not os.path.exists(serialport): sys.exit("ERROR: Serial port not found at: %s" % serialport) p = ThermalPrinter(serialport=serialport) i = image i = resizeimage(i) data = list(i.getdata()) w, h = i.size p.print_bitmap(data, w, h, True) p.linefeed(2) pyCam.camstream()
from printer import ThermalPrinter import Image, ImageDraw p = ThermalPrinter() # bitmap i = Image.open("today.png") data = list(i.getdata()) w, h = i.size p.print_bitmap(data, w, h) # text # p.print_text(self, "oh hello there! Meow.")
''' parse an animated gif for thermal printing ''' from printer import ThermalPrinter from PIL import Image import sys printer = ThermalPrinter(serialport='/dev/ttyAMA0') gif = Image.open(sys.argv[1]) # separate out panels and process each one frame = 0 while frame < 10: try: # get the current frame gif.seek(frame) converted = gif # rotate image converted = converted.rotate(90, expand=True) # resize image to printer width base_width = 384 size = converted.size print(size) height = int(size[1] * (base_width / float(size[0]))) converted = converted.resize((base_width, height), Image.ANTIALIAS) # convert the image to black and white converted = converted.convert('1', dither=3) data = list(converted.getdata()) w, h = converted.size
import os, time, sys, json sys.path.append('~/projets/printer') from printer import ThermalPrinter p = ThermalPrinter(serialport=ThermalPrinter.SERIALPORT) # coding: utf8 def print_text(text): p.print_text(text) def initTicket(): p.justify("C") p.print_text("---------//----------") p.linefeed() p.inverse() p.print_text("WEB SESSION\n") p.inverse(False) p.print_text("----------//---------- \n\n") p.justify() def footerTicket(): p.print_text("----------------------") p.font_b() p.print_text( " \n Send this to google \n@1600 Amphitheatre Parkway Mountain View,\n CA 94043, USA" )
def parse_content_list(section): return "\n".join(parse_content_item(item) for item in section['content']) def parse_title(section): # CENTRE ME return "\n" + textwrap.fill(section['title'], LINE_WIDTH) def parse_section(section): return "\n".join([parse_title(section), parse_content_list(section)]) def parse_story(data): sections = [parse_section(section) for section in data['sections']] return "\n".join(sections) conn = sqlite3.connect('creepypasta.db') c = conn.cursor() ids = get_id_list() stripped = strip_printed_stories(c, ids, "creepypasta.wikia.com") shuffled = sample(ids, len(ids)) newest = get_newest_story(c, shuffled) lines = parse_story(newest).encode('ascii', 'replace') printer = ThermalPrinter() for line in lines.split("\n"): printer.print_text("\n" + line) conn.commit() conn.close()