Untitled
public
May 24, 2024
Never
68
1 from PIL import Image, ImageDraw, ImageFont 2 3 # Create a new image with a specific size (2560x1440 is the recommended size for YouTube banners) 4 width, height = 2560, 1440 5 banner = Image.new('RGB', (width, height), color=(173, 216, 230)) # light blue background 6 7 # Load a font 8 font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf" 9 title_font = ImageFont.truetype(font_path, 200) 10 tagline_font = ImageFont.truetype(font_path, 100) 11 text_font = ImageFont.truetype(font_path, 70) 12 13 # Initialize ImageDraw 14 draw = ImageDraw.Draw(banner) 15 16 # Define text 17 title_text = "Life Whispers" 18 tagline_text = "Discover the Beauty in Everyday Moments" 19 details_text = "Inspiration | Mindfulness | Personal Growth" 20 21 # Get text sizes 22 title_size = draw.textsize(title_text, font=title_font) 23 tagline_size = draw.textsize(tagline_text, font=tagline_font) 24 details_size = draw.textsize(details_text, font=text_font) 25 26 # Calculate positions 27 title_position = ((width - title_size[0]) // 2, height // 3 - title_size[1] // 2) 28 tagline_position = ((width - tagline_size[0]) // 2, height // 2 - tagline_size[1] // 2) 29 details_position = ((width - details_size[0]) // 2, 2 * height // 3 - details_size[1] // 2) 30 31 # Draw text on image 32 draw.text(title_position, title_text, font=title_font, fill="white") 33 draw.text(tagline_position, tagline_text, font=tagline_font, fill="white") 34 draw.text(details_position, details_text, font=text_font, fill="white") 35 36 # Save image 37 banner_path = "/mnt/data/life_whispers_banner.jpg" 38 banner.save(banner_path) 39 40 banner.show() 41 banner_path