import StarTSPImage from PIL import Image, ImageDraw, ImageFont, ImageOps import textwrap # with open("printer/locations.txt") as locations: # pass # with open("printer/actions.txt") as actions: # pass # with open("printer/adverb.txt") as adverb: # pass im=Image.open("printer/image2.jpg") # f = ImageFont.load_default() f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 40) txt=Image.new('L', (1000,230)) 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) if len(lines) > 2: im=Image.open("printer/image.jpg") else: im=Image.open("printer/image2.jpg") 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 + 127, 5), w) im.show() im.save("image_tmp.jpg") raster = StarTSPImage.imageToRaster(im, cut=True) printer = open('/dev/usb/lp0', "wb") #printer.write(raster)