New meme generator

A new meme generator! Let's create a simple one using Python and the Pillow library.

Meme Generator Code

import os
from PIL import Image, ImageDraw, ImageFont

class MemeGenerator:
    def __init__(self):
        self.font = ImageFont.truetype("arial.ttf", 24)
        self.image_width = 500
        self.image_height = 500

    def generate_meme(self, top_text, bottom_text, image_path):
        # Open the image
        img = Image.open(image_path)
        img = img.resize((self.image_width, self.image_height))

        # Create a drawing context
        draw = ImageDraw.Draw(img)

        # Add the top text
        draw.text((10, 10), top_text, font=self.font, fill=(255, 255, 255))

        # Add the bottom text
        draw.text((10, self.image_height - 30), bottom_text, font=self.font, fill=(255, 255, 255))

        # Save the meme
        meme_path = f"meme_{os.urandom(6).hex()}.png"
        img.save(meme_path)
        return meme_path

# Example usage
generator = MemeGenerator()
meme_path = generator.generate_meme("This is the top text", "And this is the bottom text", "path/to/image.jpg")
print(meme_path)

How to use

  1. Install the Pillow library by running pip install pillow in your terminal.
  2. Create a new Python file and copy the code above into it.
  3. Replace "path/to/image.jpg" with the path to the image you want to use as the base for your meme.
  4. Run the script by executing the Python file.
  5. The script will generate a new meme image and save it to a file with a random name (e.g., meme_abcdefg.png).
  6. You can then share the meme image with others!

Customization

You can customize the meme generator by modifying the following variables:

I hope you enjoy using this meme generator!