4o Poster
A rather unfortunate attempt by OpenAI GPT 4o to create a poster document with an image and overlaid text.unknown
python
a month ago
3.4 kB
7
Indexable
from PIL import Image, ImageDraw, ImageFont # Load the generated image image_path = "/mnt/data/A_modern_office_environment_with_diverse_employees.png" image = Image.open(image_path) # Define text to overlay text = """ Business Casual Dress Code Guidelines Purpose: To maintain a professional yet comfortable atmosphere in the workplace, the business casual dress code balances formality with flexibility. General Guidelines - Clean and Polished Appearance: All clothing should be clean, wrinkle-free, and in good condition. - Neutral Colors: Stick to neutral, muted tones and minimal patterns. - Accessories: Keep accessories simple and understated. For Men: - Tops: Collared shirts (e.g., button-ups or polos) in solid colors or subtle patterns. - Bottoms: Chinos, khakis, or tailored trousers. Avoid jeans or shorts. - Footwear: Leather or suede loafers, Oxfords, or dress boots. - Outerwear: Blazers or sweaters. For Women: - Tops: Blouses, tailored shirts, or modest sweaters. - Bottoms: Tailored trousers, skirts (knee-length or longer), or dresses. - Footwear: Flats, loafers, or heels no higher than 3 inches. - Outerwear: Blazers or neat cardigans. What to Avoid: - Graphic T-shirts, hoodies, or overly casual wear. - Ripped or distressed clothing. - Sportswear, including leggings, athletic shoes, or flip-flops. - Excessively flashy patterns, logos, or accessories. By following these guidelines, employees can ensure their attire reflects the company's professional standards while allowing for personal comfort and style. """ # Initialize drawing poster = image.copy() draw = ImageDraw.Draw(poster) image_width, image_height = poster.size # Set font sizes and load fonts header_font_size = 50 text_font_size = 24 try: header_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", header_font_size) text_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", text_font_size) except IOError: # Use default fonts if specific ones are unavailable header_font = ImageFont.load_default() text_font = ImageFont.load_default() # Define text box dimensions and position margin = 50 text_box_width = image_width - 2 * margin text_start_y = image_height + margin # Split text into lines that fit within the text box width lines = [] for line in text.split("\n"): if not line.strip(): lines.append("") continue words = line.split() current_line = "" for word in words: test_line = f"{current_line} {word}".strip() if draw.textsize(test_line, font=text_font)[0] <= text_box_width: current_line = test_line else: lines.append(current_line) current_line = word if current_line: lines.append(current_line) # Resize poster to include space for the text extra_height = len(lines) * (text_font_size + 10) + margin * 2 new_height = image_height + extra_height poster = poster.resize((image_width, new_height)) draw = ImageDraw.Draw(poster) # Add text to the poster y = image_height + margin for line in lines: draw.text((margin, y), line, font=text_font, fill="black") y += text_font_size + 10 # Save the final poster poster_path = "/mnt/data/Business_Casual_Dress_Code_Poster.png" poster.save(poster_path) poster.show()
Editor is loading...