This tool generates images with either random or specified colors, at a specified size, and saves them to a specified directory. It's a versatile script that allows precise customization of output through flexible command-line arguments.
- Generate images with random colors or a specified hex color code.
- Specify the size (width and height) of the generated images.
- Optionally generate multiple random images at once.
- Save images to a specified output directory, or default to the current directory.
- User-friendly help messages for guidance.
- Python 3.x
Pillow
library for image processing
Install dependencies with:
pip install pillow
Run the script using the following command structure:
python run.py -s <width> <height> [-n <number>] [-c <color>] [-d <output_directory>]
Option | Short | Description | Default |
---|---|---|---|
--size |
-s |
(Required) Specify the size of the image as width and height (e.g., -s 800 600 ). |
N/A |
--number |
-n |
Number of random images to generate (ignored if --color is specified). |
1 |
--color |
-c |
Specify the color in 6-character hex format (e.g., -c ffffff ). |
Randomly generated |
--dir |
-d |
Specify the output directory where images will be saved. | Current directory (. ) |
--help |
-h |
Show detailed help and usage instructions. | N/A |
python run.py -s 800 600
Output:
- A single image of size
800x600
with a random color saved in the current directory.
python run.py -s 800 600 -n 3
Output:
- Three images of size
800x600
with random colors saved in the current directory.
python run.py -s 750 300 -c c6e3d9
Output:
- A single image of size
750x300
with the colorc6e3d9
saved in the current directory.
python run.py -s 1024 768 -n 5 -d ./output
Output:
- Five images of size
1024x768
with random colors saved in the./output
directory.
python run.py -s 600 400 -c ffffff -d ./images
Output:
- A single image of size
600x400
with the colorffffff
saved in the./images
directory.
-
Invalid color format: If the provided color is not a valid 6-character hex code:
Error: Invalid color format. Please provide a valid 6-character hex color (e.g., ffffff).
-
Invalid size or count: If the provided size or count is missing or invalid:
usage: run.py [-h] [-c COLOR] -s WIDTH HEIGHT [-n NUMBER] [-d DIR] Error: Missing required arguments or invalid values.
-
Output directory creation: If the specified output directory does not exist, it will be created automatically.
Generated images follow the naming pattern:
<YYYYMMDD>_<COLOR_HEX>_<WIDTH>x<HEIGHT>.png
For example:
20241119_C6E3D9_800x600.png
By default, images are saved in the current directory. To specify a custom output directory, use the -d/--dir
option.
This tool is open-source and available under the MIT License.
Created by Nayuta. Feel free to contribute or suggest improvements!