gdngothehieu / Meme_Generator

#GET_PASSES_THIS_REPO_UDACITY_PLEASE

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Motivational meme generator app

A simple Python application to generate both random and custom motivational memes from images and short quotes, using a commandline interface and a graphical interface. The commandline interface saves the memes locally to a disk while the graphical inteface is served with the Flask web framework.

Getting started

  1. Clone the project using:
git clone https://github.com/gdngothehieu/Meme_Generator.git
  1. Create a virtual environment and install the dependencies by running:
pip install -r requirements.txt

Before you continue ensure that Xpdf is also installed in your computer. It contains the pdftotext utility which is used in the project but not contained in the dependencies list. Visit this link for more information.

  1. To use the CLI:
$ python3 meme.py -h

usage: meme.py [-h] [-path PATH] [-body BODY] [-author AUTHOR]

Generate a motivational meme

optional arguments:
  -h, --help      show this help message and exit
  -path PATH      path to the meme image
  -body BODY      the body of the quote
  -author AUTHOR  the author of the quote

or run the command below:

python3 meme.py

to generate a random meme

  1. To use the web interface, run:
export FLASK_APP=app.py
flask run

Development mode with Flask

For development purposes, make sure to add the following variables:

export FLASK_DEBUG=True
export FLASK_ENV=development

and run:

flask run --reload

for hot reloads whenever you make changes to the code.

Once the server starts, visit this link using your favorite browser.

Modules and dependencies

The project is made up of two modules and several dependencies.

Dependencies

  1. Flask - to build the web interface. Visit this link for more information.
  2. Pillow - for manipulating images. Visit this link for more information.
  3. pandas - for extracting text content from csv documents. Visit this link for more information.
  4. python-docx - for extracting text content from docx documents. Visit this link for more information.

Modules

  1. QuoteEngine module - deals with extracting and parsing quotes from txt, docx, pdf and csv documents.

Contains the ingestor and quote submodules.

  • ingestor Ingestor class: extract text content (quotes) from documents. Documents supported include txt, pdf, docx and csv. Methods: parse(path: str) - parses the contents in the document referenced in the path. Returns a list of QuoteModel objects.

Example:

from QuoteEngine.ingestor import Ingestor

path = '/_data/SimpleLines/SimpleLines.csv'
quotes = Ingestor().parse(path)
print(type(quotes))

>>> <class 'list'>
  • quote QuoteModel class: instantiate quote objects.

Attributes: body (str), author(str) body - The quote's text author - The quote's author

Example:

from QuoteEngine.quote import QuoteModel

body = 'To be or not to be'
author = 'Wiseman'

quote = QuoteModel(body, author)
print(quote)

>>> "To be or not to be" - Wiseman
  1. MemeGenerator module - deals with the creation and storing of the memes.

Contains the meme_engine submodule.

  • meme_engine meme_engine class: create memes from an image and a quote.

Attributes: output_dir (str)

Methods: make_meme(img_path: str, text: str, author: str, width: int) - creates a meme using an image specified in img_path and a quote from text and author. The meme is resized to size width. Returns the path of the created meme in the disk (for CLI) or the relative path to the static files folder (for GUI).

Example:

from MemeGenerator.meme_engine import meme_engine

output_directory = 'memes'

img_path = '/_data/photos/dog/xander_1.jpg'
body = 'To be or not to be'
author = 'Wiseman'

quote = meme_engine(output_directory).make_meme(img_path, body, author, 300)
print(quote)

>>> "/tmp/xander_1_meme.jpg"

Author

  • Silas Jimmy

Credits

About

#GET_PASSES_THIS_REPO_UDACITY_PLEASE

License:MIT License


Languages

Language:Python 83.1%Language:HTML 16.4%Language:Shell 0.5%