#!/usr/bin/env python from PIL import Image import math import sys def printImage( image ): Epson = printer.Serial("/dev/ttyUSB0") if image.mode != '1': image = image.convert('1') width = image.size[0] height = image.size[1] if width != 576: sys.stderr.write("Error! wrong width") exit() rowBytes = (width + 7) / 8 bitmap = bytearray(rowBytes * height) pixels = image.load() for y in range(height): row = "" for x in range(int(math.ceil(width/8))*8): if x%8 == 0: imgstr = "" if pixels[x, y] > 150: color = 0 else: color = 1 imgstr = imgstr + str(color) if x%8 == 7: row = row + str(chr(int(imgstr, 2))) sys.stderr.write(("0"+(hex(int(imgstr, 2))[2:]))[-2:]) Epson._raw("\x11" + row) sys.stderr.write("#\n") img = Image.open('/home/ep/Bilder/chaostal-mono.png') printImage(img)