Create Daily Inspirational Wallpapers with Python and Pillow

Last night while scrolling through my phone, I saw someone in my friend circle post a super cool inspirational wallpaper. I immediately felt the urge to have one too, thinking how great it would be to see such a positive wallpaper every day! Unfortunately, those ready-made wallpapers always seem to lack a bit of “me”. So, I had a brilliant idea: why not create one myself using Python?

From Scratch: Build Your Own Wallpaper Generator

We need a reliable assistant. The Python imaging library Pillow is the perfect choice. It acts like our personal designer; as long as we give the instructions, it can help turn our ideas into reality.

from PIL import Image, ImageDraw, ImageFont
import random

# Create an image with a white background
img = Image.new('RGB', (1920, 1080), color='white')
draw = ImageDraw.Draw(img)

This few lines of code are like opening a 1920×1080 canvas on our computer. Now, this blank canvas is waiting for us to doodle on it!

Words Are the Soul: Let the Inspirational Quotes Shine

With the canvas ready, we need to write something interesting on it. For example, how about a little motivational boost every day?

quotes = [
    "Today's sweat is tomorrow's success",
    "Be the best version of yourself",
    "Persistence is victory",
    # Continue adding your favorite inspirational quotes
]

font = ImageFont.truetype("path/to/your/font.ttf", 60)
quote = random.choice(quotes)
text_width, text_height = draw.textsize(quote, font=font)
position = ((1920 - text_width) / 2, (1080 - text_height) / 2)
draw.text(position, quote, fill="black", font=font)

This piece of code is like picking today’s lucky draw. It randomly selects one quote from a bunch of inspirational sayings and writes it in a beautiful font right in the center of the canvas. Every morning when you open your computer and see a different inspirational quote, doesn’t it make you feel invigorated?

Friendly reminder: Don’t forget to replace “path/to/your/font.ttf” with the actual path to a font file on your computer! If you can’t find a nice font, the built-in “Microsoft YaHei” on Windows is also a good choice.

Add Some Flair to Make Your Wallpaper Unique

Just having text isn’t enough; let’s add some fancy elements to make the wallpaper more interesting.

# Draw some random colorful dots
for _ in range(50):
    x = random.randint(0, 1920)
    y = random.randint(0, 1080)
    r = random.randint(5, 20)
    color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
    draw.ellipse([x-r, y-r, x+r, y+r], fill=color)

# Add the date in the bottom right corner
from datetime import date
today = date.today().strftime("%Y-%m-%d")
date_font = ImageFont.truetype("path/to/your/font.ttf", 30)
draw.text((1750, 1030), today, fill="gray", font=date_font)

Look, now our wallpaper not only has inspirational quotes but also colorful dots embellishing it. We also sneakily added the date in the bottom right corner, making each day’s wallpaper unique!

Save Your Work: Keep Inspiration Close

img.save(f"Inspirational_Wallpaper_{today}.png")
print(f"Today's inspirational wallpaper has been generated: Inspirational_Wallpaper_{today}.png")

Done! Now you have your own daily inspirational wallpaper generator. Just run this script, and you will get a brand new wallpaper filled with positive energy.

See, using Python can not only solve problems at work but also add a splash of color to our lives. The uses of this little tool are numerous—perhaps one day when you are feeling down, you will be grateful for this little companion that encourages you at all times.

If you think this is still not cool enough, keep unleashing your creativity! For instance, you could add more background elements or make the text have special effects. Python is like a treasure chest; as long as you are willing to explore, you can always create something surprising.

Leave a Comment