Compare commits
2 Commits
15e79e67df
...
c996650414
| Author | SHA1 | Date | |
|---|---|---|---|
| c996650414 | |||
| 653257b787 |
28
printer/press.py
Normal file
28
printer/press.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import StarTSPImage
|
||||||
|
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||||
|
import textwrap
|
||||||
|
import random
|
||||||
|
|
||||||
|
im = Image.new('RGB', (500, 1600), color = 'white')
|
||||||
|
# f = ImageFont.load_default()
|
||||||
|
f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 100)
|
||||||
|
txt=Image.new('L', (1600,500))
|
||||||
|
d = ImageDraw.Draw(txt)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
d.text((50, 50), "(When flashing)", font=f, fill=255)
|
||||||
|
w=txt.rotate(-90, expand=1)
|
||||||
|
|
||||||
|
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), (-100, 60), w)
|
||||||
|
|
||||||
|
im.show()
|
||||||
|
# im.save("image_tmp.jpg")
|
||||||
|
|
||||||
|
raster = StarTSPImage.imageToRaster(im, cut=True)
|
||||||
|
printer = open('/dev/usb/lp0', "wb")
|
||||||
|
printer.write(raster)
|
||||||
@@ -46,7 +46,7 @@ def on_message(client, userdata, msg):
|
|||||||
|
|
||||||
lines = textwrap.wrap(text, width=23)
|
lines = textwrap.wrap(text, width=23)
|
||||||
|
|
||||||
if len(lines) > 2:
|
if random.randint(0,1) == 0:
|
||||||
im=Image.open("printer/image.jpg")
|
im=Image.open("printer/image.jpg")
|
||||||
else:
|
else:
|
||||||
im=Image.open("printer/image2.jpg")
|
im=Image.open("printer/image2.jpg")
|
||||||
@@ -62,20 +62,20 @@ def on_message(client, userdata, msg):
|
|||||||
print(n)
|
print(n)
|
||||||
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 127, 5), w)
|
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 127, 5), w)
|
||||||
|
|
||||||
im.show()
|
# im.show()
|
||||||
im.save("image_tmp.jpg")
|
# im.save("image_tmp.jpg")
|
||||||
|
|
||||||
raster = StarTSPImage.imageToRaster(im, cut=True)
|
raster = StarTSPImage.imageToRaster(im, cut=True)
|
||||||
|
|
||||||
printer = open('/dev/usb/lp0', "wb")
|
printer = open('/dev/usb/lp0', "wb")
|
||||||
#printer.write(raster)
|
printer.write(raster)
|
||||||
|
|
||||||
|
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
|
|
||||||
client.connect("", 1883, 60)
|
client.connect("192.168.240.231", 1883, 60)
|
||||||
|
|
||||||
# Blocking call that processes network traffic, dispatches callbacks and
|
# Blocking call that processes network traffic, dispatches callbacks and
|
||||||
# handles reconnecting.
|
# handles reconnecting.
|
||||||
|
|||||||
Reference in New Issue
Block a user