ESC2

Python

No description

Guest

Download Edit

#!/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 > 384:
width = 384
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(imgstr+"("+str(int(imgstr, 2))+"),")
#Epson._raw("\x11" + row)
print("\x11" + row)
sys.stderr.write("#\n")
img = Image.open('/home/ep/Bilder/Zeichnung.png')
printImage(img)