From b4fd4126753f22492c194501d99ef9a680b50e68 Mon Sep 17 00:00:00 2001 From: Frederic Date: Tue, 27 Dec 2016 13:28:35 +0100 Subject: [PATCH] added image scrolling support --- scrolltext.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) mode change 100644 => 100755 scrolltext.py diff --git a/scrolltext.py b/scrolltext.py old mode 100644 new mode 100755 index 4ea5040..c43fb6f --- a/scrolltext.py +++ b/scrolltext.py @@ -19,8 +19,7 @@ def create_image(text): return img -def create_scrolltext(text, delay, color): - img = create_image(text) +def scroll_image(img, delay, color): w, h = img.size @@ -39,23 +38,37 @@ def create_scrolltext(text, delay, color): return anim +def create_scrolltext(text, delay, color): + img = create_image(text) + return scroll_image(img, delay, color) + if __name__ == '__main__': parser = argparse.ArgumentParser(description='Generate scrolltext BML files') parser.add_argument('-d', '--delay', type=int, default=100) parser.add_argument('-c', '--color', default='#ffffff') + parser.add_argument('-i', '--image', type=str) + parser.add_argument('-t', '--text', type=str) parser.add_argument('output_file') - parser.add_argument('text') - args = parser.parse_args() + + if args.image is not None and args.text is not None: + print('--image and --text are exclusive', file=sys.stderr) + sys.exit(1) + if args.color.startswith('#'): args.color = args.color[1:] - r = int(args.color[0:2], 16)/255 - g = int(args.color[2:4], 16)/255 - b = int(args.color[4:6], 16)/255 + r = int(args.color[0:2], 16)//255 + g = int(args.color[2:4], 16)//255 + b = int(args.color[4:6], 16)//255 col = (r, g, b) - anim = create_scrolltext(args.text, args.delay, col) - writebml.writeBml(anim, 'scrolltext.bml') + if args.text: + anim = create_scrolltext(args.text, args.delay, col) + elif args.image: + img = Image.open(args.image) + img.convert(mode='RGB') + anim = scroll_image(img, args.delay, col) + writebml.writeBml(anim, args.output_file) ''' num = 10