def init_printer(vendorId, machineId, printId): printer = EpsonPrinter(vendorId, machineId, printId) printer.center() printer.bold_on() printer.set_print_speed(2) return printer
def print_image(file): printer = EpsonPrinter(0x04b8, 0x0202) printer.set_print_speed(1) start = time.time() im = Image.open(file) im = im.transpose(Image.ROTATE_270) basewidth = 512 wpercent = (basewidth / float(im.size[0])) hsize = int((float(im.size[1]) * float(wpercent))) im = im.resize((basewidth, hsize), Image.BICUBIC) printer.print_image(im) printer.linefeed(5) printer.cut() end = time.time() print end - start
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the cartridge sensor.""" host = config.get(CONF_HOST) from epsonprinter import EpsonPrinter """Set up the printer API.""" api = EpsonPrinter(host) sensors = [ EpsonPrinterCartridge(hass, api, condition) for condition in config[CONF_MONITORED_CONDITIONS] ] add_devices(sensors, True)
def print_images(num_images): printer = EpsonPrinter(0x04b8, 0x0202) printer.set_print_speed(1) for i in range(num_images): start = time.time() print "PRINT" im = Image.open(str(i)+ ".jpg") #brighter = ImageEnhance.Brightness(im) #im = brighter.enhance(1.2) #contrast = ImageEnhance.Contrast(im) #im = contrast.enhance(1.0) #verkleinern #im = im.resize((682, 512)) #drehen im = im.transpose(Image.ROTATE_90) #printer.print_file(str(i)+ ".png") printer.print_image(im) if text['show']: printer.print_text("\n") printer.center() if text['row1'] != "": printer.print_text(text['row1']) printer.print_text("\n") if text['row2'] != "": printer.print_text(text['row2']) printer.print_text("\n") if text['row3'] != "": printer.print_text(text['row3']) if text['date']: printer.print_text("\n") printer.print_text(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")) printer.linefeed(7) printer.cut() end = time.time() print end - start
import sys if __name__ == '__main__': parser = OptionParser() parser.add_option("-v", "--idvendor", action="store", type="int", dest="id_vendor", help="The printer vendor id") parser.add_option("-p", "--idProduct", action="store", type="int", dest="id_product", help="The printer product id") options, args = parser.parse_args() if not options.id_vendor or not options.id_product: parser.print_help() else: printer = EpsonPrinter(options.id_vendor, options.id_product) printer.print_text("Following is a bitmap") printer.linefeed() printer.print_image_from_file("horse-drawing.jpg") printer.linefeed() printer.print_text("Feeding paper 10 lines before cutting") printer.linefeed(5) printer.cut() sys.exit(1)