memeengine package

Submodules

memeengine.meme_generator module

Meme generators overlay text(body, author from quoteengine image files.

class memeengine.meme_generator.MemeGenerator(output_path: str = './output', input_image_path: Optional[str] = None, quote_body: str = '', quote_author: str = '', output_width: Optional[int] = None, text_width_percent: float = 0.7, font_path: str = 'memeengine/fonts/Montserrat-SemiBold.ttf', font_size: Optional[int] = None)[source]

Bases: object

MemeGenerator generates a meme from an image and text.

Geenrates a meme from either (1) initialized arguments or (2) by setting output_dir only during construction then calling make_make to get back a path of the processed meme image.

However all methods are checked and will raise a value error if not set/supplied required attributes are missing. All have defaults except quote_body and quote_author.

crop_image(output_width: Optional[int] = None) None[source]

Return an image crop cropped to single_dim keeping aspect ratio.

load_image(image_path: str) None[source]

Return None after loading an image from path into class attribute.

make_meme(img_path: str, quote_body: str, quote_author: str, width: int = 500) str[source]

Override previously supplied params and saves image.

Created for a specific use case:

meme = MemeGenerator(‘./tmp’) path = meme.make_meme(img, quote.body, quote.author)

Parameters
  • img_path – Loads image from path, overriding and previously stored image

  • quote_body – Loads quote_body from supplied text, overriding quote_body a previously set quote_body

  • quote_author – Same as quote_body but for quote_author

  • width – Scaled image keeping

Returns

location of saved file as a str

overlay_text(position: Optional[Tuple[int, int]] = None, output_width: Optional[int] = None, scale_text: bool = True, random_text_position=True)[source]

Overlays text on loaded image.

Applies optional args then applies previously loaded quote_body and quote_author to an previously loaded image. To access the processed image use the image class attribute.

property quote_author

Return quote author in the format of choice for rendering.

random_image_position() Tuple[int, int][source]

Return random position for text placement.

save_image()[source]

Return path of saved image file.

set_font_size(size: int, author_decrease_pct=0.2) None[source]

Return a font for author based on class attributes.

set_fonts_image_scale(text_width_pct: Optional[float] = None) None[source]

Return two fonts for body and author text scaled to percentage of width.

Module contents

memeengine module manipulates and displays text on images.