import os as _os fontpath = _os.path.realpath(_os.path.join(__file__,"..","..","wavesharelib","pic", 'Font.ttc')) def eink_qr(args): from waveshare_epd import epd2in13_V2 from PIL import Image,ImageDraw import qrcode epd = epd2in13_V2.EPD() epd.init(epd.FULL_UPDATE) image = Image.new('1', (epd.height, epd.width), 0) qr = qrcode.QRCode(version=1, box_size=3, border=1) qr.add_data(args.text) qr.make() pic = qr.make_image().get_image() image.paste(pic, (int(epd.height-pic.width),0), pic) epd.display(epd.getbuffer(image)) epd.sleep() epd.Dev_exit() def eink_quote_qr(args): pass def eink_quote(args): import simpilib quote = simpilib.getQuote() if not quote: return args.text = quote["content"] + ' - ' + quote["author"] eink_text(args) def eink_text(args): from waveshare_epd import epd2in13_V2 from PIL import Image,ImageDraw import simpilib epd = epd2in13_V2.EPD() print("init and Clear") epd.init(epd.FULL_UPDATE) # epd.Clear(0xFF) image = Image.new('1', (epd.height, epd.width), 0) draw = ImageDraw.Draw(image) text, longline = simpilib.wrapText(args.text, line_width_factor=5) font = simpilib.loadFontSize(text, draw, image, fontpath) w, h = draw.textsize(text, font=font) # epd parameters are rotated 90° center = [ int((epd.height - w)/2), int((epd.width-h)/2) - 3, ] # -3 px to leave some space for low characters print("Drawing:", (w, h), (epd.height, epd.width), center) draw.text(center, text, align="center", font = font, fill = 255) # epd.display(epd.getbuffer(image.rotate(180))) epd.display(epd.getbuffer(image)) epd.sleep() epd.Dev_exit()