64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
import StarTSPImage
|
|
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
|
import textwrap
|
|
|
|
|
|
# #image = Image.new('RGB', (2000, 2000), color='White')
|
|
# image = Image.open("printer/image.jpg")
|
|
|
|
|
|
# txt=Image.new('L', (1000,500))
|
|
# font = ImageFont.truetype("printer/font.ttf", 30)
|
|
# draw = ImageDraw.Draw(txt)
|
|
|
|
|
|
# draw.text((0, 0),"Sample Text",font=font)
|
|
# w=txt.rotate(90, expand=1)
|
|
|
|
# image.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), (0,0), w)
|
|
# image.show()
|
|
|
|
|
|
# im=Image.open("image.jpg")
|
|
|
|
# f = ImageFont.load_default()
|
|
# txt=Image.new('L', (500,50))
|
|
# d = ImageDraw.Draw(txt)
|
|
# d.text( (0, 0), "Someplace Near Boulder", font=f, fill=255)
|
|
# w=txt.rotate(17.5, expand=1)
|
|
|
|
# im.paste( ImageOps.colorize(w, (0,0,0), (255,255,84)), (242,60), w)
|
|
|
|
# im.show
|
|
|
|
im=Image.open("printer/image.jpg")
|
|
|
|
# f = ImageFont.load_default()
|
|
f = ImageFont.truetype("printer/Jua-Regular.ttf", 45)
|
|
txt=Image.new('L', (1000,225))
|
|
d = ImageDraw.Draw(txt)
|
|
|
|
text_short = "By the DJ, offer a stranger a drink"
|
|
text_long = "In the outdoor area, ask someone would you rather be known for always being honest or always being kind"
|
|
|
|
lines = textwrap.wrap(text_long, width=23)
|
|
|
|
y = 0
|
|
n = 0
|
|
for line in lines:
|
|
n += 1
|
|
width, height = f.getsize(line)
|
|
d.text(((1000-width)/2, y), line, font=f, fill=255)
|
|
y += height
|
|
w=txt.rotate(-90, expand=1)
|
|
print(n)
|
|
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 130, 5), w)
|
|
|
|
im.show()
|
|
#image.save("image_tmp.jpg")
|
|
|
|
raster = StarTSPImage.imageToRaster(im, cut=True)
|
|
|
|
printer = open('/dev/usb/lp0', "wb")
|
|
printer.write(raster)
|