This Python script generates an image with a unique pattern of words. It utilizes the PIL library for image manipulation and the random
library for randomization. The script arranges a list of predefined words on a transparent background image, placing them at random positions with varying rotation angles and sizes, ensuring no overlap. The final image showcases a visually appealing and random arrangement of words, suitable for various creative applications.
- Python 3.x
- Pillow (PIL Fork): Python Imaging Library
- Access to font files (
.ttf
or.otf
)
- Ensure you have Python installed on your system.
- Install the Pillow library using pip:
pip install pillow
- Modify the
words
list in the script to include the words or phrases you want to appear in the image. - Set the
fonts_dir
variable to the path where your.ttf
or.otf
font files are located. - Run the script:
python random_words_pattern.py
- The script will create an image file named
random_words_pattern.png
in the same directory.
- Font Directory: Change
fonts_dir
to the path containing your font files. - Word List: Modify the
words
list to include your desired words or phrases. - Image Size: Adjust the
width
andheight
variables to change the image dimensions. - Font Size: Tweak
max_font_size
to alter the starting font size. - Rotation Angle: Adjust the values in
rotation_angle = random.uniform(-5, 5)
to change the range of rotation angles.
- Font Loading Issues: Ensure the
fonts_dir
path is correctly set and contains valid font files. - Overlap of Words: The script checks for overlap; however, in cases of high word density or large font sizes, some words may not be placed.