def main(): """main is the entrypoint to the markov meme client. """ parser = get_parser() # Will exit with subcommand help if doesn't parse args, extra = parser.parse_known_args() # Initialize the JuliaSet if args.command == "generate": # If the provided font doesn't end in ttf font = args.font if not args.font.endswith(".ttf"): font = "%s.ttf" % (font) # Determine if we have a corpus or custom corpus corpus = args.corpus if corpus is None: corpus = random.choice(list_corpus()) if args.custom_corpus: if os.path.exists(args.custom_corpus): corpus = args.custom_corpus text = generate_text(corpus=corpus, use_model=not args.no_model, size=10) meme = MemeImage(image=args.custom_image, corpus=corpus) # Add text generated, will go to top and bottom meme.write_text(text, fontsize=args.fontsize, font=font) meme.save_image(args.outfile) else: parser.print_help()
def markov(bot, update): #This script is built in Python and generates memes. It is built on the markovmeme library. #It can be installed using pip install markovmeme #A theme can be chosen from the markov_themes.txt file #Here I am generating a random theme with open('markov_themes.txt', 'r') as file: themes = file.readlines() for i in range(len(s)): themes[i] = themes[i].replace(" " , '').strip('\n') corpus = random.choice(themes) text = generate_text(corpus=corpus, use_model=True, size=14) # Set image to full path, or None to select based on corpus meme = MemeImage(image=None, corpus=corpus) # Add text generated, centered on top meme.write_text(text, fontsize=18, font='Anton-Regular.ttf') # Leave outfile as None to generate random name meme.save_image('image.png') chat_id = update.effective_chat.id bot.send_photo(chat_id=chat_id, photo=open('./image.png', 'rb'))
# imports from markovmeme.main import MemeImage from markovmeme.text import generate_text import random # The module markovmeme, is installed as pip3 install markovmeme - python3 # pip install markovmeme - python # The file themes consists a list of all the topics based on which memes are generated handle = [] with open("themes.txt", "r") as file: handle = file.readlines() for i, j in enumerate(handle): handle[i] = handle[i].replace(" ", "").strip("\n") # A random theme is chosen, from themes.txt corpus = handle[random.randint(0, 29)] text = generate_text(corpus=corpus, use_model=True, size=10) # Set image to full path, or None to select based on corpus meme = MemeImage(image=None, corpus=corpus) # Add text generated, centered on top meme.write_text(text, fontsize=20, font="Anton-Regular.ttf") # The meme is saved as markovmeme.png in the current diectory meme.save_image("markovmeme.png")