|
| 1 | +""" |
| 2 | +This module provides a function to create and save an image with custom text, |
| 3 | +and background colors using the Pillow library. |
| 4 | +""" |
1 | 5 | from PIL import Image, ImageDraw, ImageFont
|
2 | 6 |
|
3 |
| -text = """ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 7 | +TEXT = """ABCDEFGHIJKLMNOPQRSTUVWXYZ |
4 | 8 | abcdefghijklmnopqrstuvwxyz
|
5 | 9 | 0123456789
|
6 | 10 | _-~=+*&#$@%^
|
7 | 11 | /<[{(|)}]>\
|
8 | 12 | `'".,:;!?"""
|
9 | 13 |
|
10 |
| -width, height = 3840, 1350 |
11 |
| -font_path = "NeoSpleen.ttf" |
12 |
| -font_size = 294 |
13 |
| -font = ImageFont.truetype(font_path, font_size) |
| 14 | +WIDTH, HEIGHT = 3840, 1350 |
| 15 | +FONT_PATH = "NeoSpleen.ttf" |
| 16 | +FONT_SIZE = 294 |
| 17 | +FONT = ImageFont.truetype(FONT_PATH, FONT_SIZE) |
14 | 18 |
|
15 | 19 |
|
16 |
| -def create_image(background_color, text_color, file_name): |
17 |
| - image = Image.new("RGB", (width, height), background_color) |
| 20 | +def create_image(text_color, background_color, file_path): |
| 21 | + """ |
| 22 | + Create an save an image with specified text color and background color. |
| 23 | +
|
| 24 | + Args: |
| 25 | + text_color (str): The color of the text in the image. |
| 26 | + background_color (str): The background color of the image. |
| 27 | + file_path (str): The filename to save the image under. |
| 28 | + """ |
| 29 | + image = Image.new("RGB", (WIDTH, HEIGHT), background_color) |
18 | 30 | draw = ImageDraw.Draw(image)
|
19 |
| - draw.text((0, 0), text, fill=text_color, font=font) |
20 |
| - image.save("Showcase-" + file_name) |
| 31 | + draw.text((0, 0), TEXT, fill=text_color, font=FONT) |
| 32 | + image.save("Showcase-" + file_path) |
21 | 33 |
|
22 | 34 |
|
23 |
| -create_image("black", "white", "WoB.png") |
24 |
| -create_image("white", "black", "BoW.png") |
| 35 | +create_image("white", "black", "WoB.png") |
| 36 | +create_image("black", "white", "BoW.png") |
0 commit comments