import os, sys, sh, glob try: os.mkdir("tmp"); except: pass files = sh.ls("-tr1", glob.glob("*.png")).split("\n"); files = [str(f) for f in files if len(f) > 0] cmd = "convert -delay 30 -loop 0 " anno_setup = "-fill white -undercolor '#00000080' -gravity South -font DejaVu-Sans-Mono -pointsize 30 " for f in files: t = f.replace(".png", ".txt") if os.path.isfile(t): print f anno = open(t).read().strip().replace("'", r"\'").replace("& ", r"&\n") os.system("convert %s %s -annotate +0+90 '%s' tmp/%s" % (f, anno_setup, anno, f)) f = "tmp/%s" % f cmd += "'" + f + "' " cmd += " -layers Optimize xenialbig.gif" print cmd os.system(cmd); os.system("gifsicle xenialbig.gif --resize 180x120 -O3 --colors 256 > xenialmini.gif") os.system("gifsicle xenialbig.gif --resize 720x480 -O3 --colors 256 > xenial.gif")