A Python script that places images randomly on a 1920x1080 canvas with configurable parameters for creating unique compositions.
Fun Fact:
This script was used to create the background image for SquidServers.com!
Here's what the script generates:
- Transparent Background: Creates PNG files with transparent backgrounds
- Configurable Parameters: Easy-to-modify variables for customization
- Multiple Distribution Patterns: Random, grid, spiral, and cluster distributions
- Size Variance: Configurable scaling with multiple distribution types
- Rotation: Optional random rotation of images
- Overlap Control: Configurable overlap prevention
- Visual Effects: Random brightness variations
- Statistics: Detailed output about the generation process
- Install Python 3.7+ if you haven't already
- Install required packages:
pip install -r requirements.txt
-
Place your images in the same directory as the script:
kelp.webpminecraft-bubble.png
-
Run the script:
python image_canvas_generator.py
-
The script will generate:
generated_canvas.png- Full-size canvaspreview_generated_canvas.png- Half-size preview
TOTAL_PARTICLES: Total number of images to place (default: 50)KELP_RARITY: Probability of placing kelp images (0.0 to 1.0, default: 0.6)BUBBLE_RARITY: Probability of placing bubble images (0.0 to 1.0, default: 0.4)
MIN_SCALE: Minimum scale factor (default: 0.3 = 30% of original)MAX_SCALE: Maximum scale factor (default: 1.5 = 150% of original)SIZE_DISTRIBUTION: Size distribution type:"uniform": Even distribution across the range"normal": Bell curve distribution"exponential": More smaller images, fewer larger ones
MARGIN: Minimum distance from canvas edges (default: 50 pixels)OVERLAP_ALLOWED: Whether images can overlap (default: True)OVERLAP_THRESHOLD: Maximum allowed overlap (0.0 = no overlap, 1.0 = full overlap)
DISTRIBUTION_TYPE: How images are positioned:"random": Completely random placement"grid": Organized in a grid pattern"spiral": Spiral outward from center"clusters": Grouped in random clusters
ROTATION_ENABLED: Enable/disable rotation (default: True)MIN_ROTATION: Minimum rotation angle in degrees (default: -45)MAX_ROTATION: Maximum rotation angle in degrees (default: 45)
BRIGHTNESS_VARIANCE: Random brightness variation (-0.2 to +0.2, default: 0.2)CONTRAST_VARIANCE: Random contrast variation (default: 0.1)SATURATION_VARIANCE: Random saturation variation (default: 0.15)
TOTAL_PARTICLES = 100
KELP_RARITY = 0.8
BUBBLE_RARITY = 0.2
MIN_SCALE = 0.5
MAX_SCALE = 2.0
DISTRIBUTION_TYPE = "clusters"TOTAL_PARTICLES = 20
KELP_RARITY = 0.3
BUBBLE_RARITY = 0.7
MIN_SCALE = 0.2
MAX_SCALE = 1.0
DISTRIBUTION_TYPE = "random"
OVERLAP_ALLOWED = FalseTOTAL_PARTICLES = 64
DISTRIBUTION_TYPE = "grid"
SIZE_DISTRIBUTION = "normal"
ROTATION_ENABLED = False- Main Canvas:
generated_canvas.png(1920x1080) - Preview:
preview_generated_canvas.png(960x540) - Example Output:
example.png- Cool preview of what the script can create! 🎨 - Console Output: Statistics and generation progress
- Adjust Rarity: Make sure
KELP_RARITY + BUBBLE_RARITY = 1.0for balanced distribution - Size Range: Keep
MIN_SCALEandMAX_SCALEreasonable to avoid tiny or oversized images - Overlap Control: Use
OVERLAP_THRESHOLDto fine-tune how much images can overlap - Distribution: Try different distribution types for different artistic effects
- Performance: Higher particle counts will take longer to generate
- "No images could be loaded": Make sure
kelp.webpandminecraft-bubble.pngare in the same directory - Slow generation: Reduce
TOTAL_PARTICLESor enable overlap - Images too large/small: Adjust
MIN_SCALEandMAX_SCALEvalues - Poor distribution: Try different
DISTRIBUTION_TYPEvalues
The script is designed to be easily customizable. You can:
- Add more image types by modifying the
image_filesdictionary - Create new distribution patterns in
get_random_position() - Add more visual effects in
apply_image_effects() - Modify the canvas dimensions by changing
CANVAS_WIDTHandCANVAS_HEIGHT
If you find this script useful, please consider:
- Starring this repository
- Forking it to create your own variations
- Sharing it with others who might find it helpful
