Categories We Write About

Build a motivational quote poster generator

Here’s a straightforward motivational quote poster generator concept in Python. It creates an image with a random motivational quote styled attractively.

python
from PIL import Image, ImageDraw, ImageFont import random import textwrap # Sample motivational quotes list quotes = [ "Believe you can and you're halfway there.", "Success is not final, failure is not fatal: It is the courage to continue that counts.", "Don't watch the clock; do what it does. Keep going.", "The harder you work for something, the greater you'll feel when you achieve it.", "Dream it. Wish it. Do it.", "Great things never come from comfort zones.", "Push yourself, because no one else is going to do it for you." ] def generate_poster(output_path='motivational_poster.png', width=800, height=600): # Choose a random quote quote = random.choice(quotes) # Create a blank white image img = Image.new('RGB', (width, height), color=(255, 255, 255)) draw = ImageDraw.Draw(img) # Load font (you may need to adjust path or use a system font) try: font = ImageFont.truetype("arial.ttf", 40) font_bold = ImageFont.truetype("arialbd.ttf", 50) except IOError: # fallback to default font if arial not found font = ImageFont.load_default() font_bold = font # Text wrapping for quotes longer than width margin = 40 max_width = width - 2 * margin wrapped_text = textwrap.fill(quote, width=30) # Calculate text size and position to center vertically and horizontally text_size = draw.multiline_textsize(wrapped_text, font=font) x = (width - text_size[0]) / 2 y = (height - text_size[1]) / 2 # Draw a subtle background rectangle for the text rect_padding = 20 rect_x0 = x - rect_padding rect_y0 = y - rect_padding rect_x1 = x + text_size[0] + rect_padding rect_y1 = y + text_size[1] + rect_padding draw.rectangle([rect_x0, rect_y0, rect_x1, rect_y1], fill=(230, 230, 250)) # Draw the wrapped text draw.multiline_text((x, y), wrapped_text, fill=(25, 25, 112), font=font, align='center') # Save the poster image img.save(output_path) print(f"Poster saved as {output_path}") if __name__ == "__main__": generate_poster()

How it works:

  • Randomly picks a motivational quote.

  • Wraps the text to fit nicely.

  • Centers the text on a white background.

  • Adds a subtle background rectangle behind the text for better visibility.

  • Saves as a PNG image file.

You can customize fonts, colors, sizes, and quotes easily. Would you like me to expand it with GUI or web version?

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About