def _drawimage(options, args): columns = int(options.columns) if columns > 62: message = "Wrong columns value is specified (max: 62)." raise optparse.OptionValueError(message) if select.select([sys.stdin, ], [], [], 0.0)[0]: imagefile = _filenize(sys.stdin) elif len(args) == 0 or args[0] == '-': imagefile = _filenize(sys.stdin) else: imagefile = args[0] from PIL import Image # PIL image = Image.open(imagefile) rows = options.rows if not rows is None: rows = int(rows) output = sys.stdout output.write("\x1b[?8800h") writer = DrcsWriter(f8bit=options.f8bit) writer.draw(image, columns, rows, options.negate, options.use_unicode, output=output, ncolor=options.ncolor, defonly=options.defonly, startoffset=options.startoffset)
def _drawtext(options, args): if select.select([sys.stdin, ], [], [], 0.0): text = sys.stdin.read() elif len(args) == 0 or args[0] == '-': text = sys.stdin.read() import re text = re.sub('[\x00-\x1f\x7f]', '', text) text = unicode(text, "utf-8", "ignore") from PIL import Image from PIL import ImageDraw from PIL import ImageFont if options.font: fontfile = options.font else: import inspect name = "unifont-5.1.20080907.ttf" filename = inspect.getfile(inspect.currentframe()) dirpath = os.path.abspath(os.path.dirname(filename)) fontfile = os.path.join(dirpath, name) font = ImageFont.truetype(filename=fontfile, size=50) w, h = font.getsize(text) image = Image.new('RGB', (w, h + 2), (255, 255, 255)) draw = ImageDraw.Draw(image) draw.text((0, 0), text, font=font, fill=(0, 0, 0)) import wcwidth columns = wcwidth.wcswidth(text) rows = 1 writer = DrcsWriter(f8bit=options.f8bit) writer.draw(image, columns, rows, options.negate, options.use_unicode, ncolor=options.ncolor, defonly=options.defonly, startoffset=options.startoffset)