Skip to content

SquidServers/image-canvas-generator

Repository files navigation

Image Canvas Generator

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!

Preview

Here's what the script generates:

Example Output

Features

  • 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

Installation

  1. Install Python 3.7+ if you haven't already
  2. Install required packages:
    pip install -r requirements.txt

Usage

  1. Place your images in the same directory as the script:

    • kelp.webp
    • minecraft-bubble.png
  2. Run the script:

    python image_canvas_generator.py
  3. The script will generate:

    • generated_canvas.png - Full-size canvas
    • preview_generated_canvas.png - Half-size preview

Configurable Parameters

Basic Settings

  • 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)

Size Settings

  • 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

Position Settings

  • 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 Settings

  • 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 Settings

  • 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)

Visual Effects

  • 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)

Example Configurations

Dense Forest Effect

TOTAL_PARTICLES = 100
KELP_RARITY = 0.8
BUBBLE_RARITY = 0.2
MIN_SCALE = 0.5
MAX_SCALE = 2.0
DISTRIBUTION_TYPE = "clusters"

Sparse Ocean Scene

TOTAL_PARTICLES = 20
KELP_RARITY = 0.3
BUBBLE_RARITY = 0.7
MIN_SCALE = 0.2
MAX_SCALE = 1.0
DISTRIBUTION_TYPE = "random"
OVERLAP_ALLOWED = False

Organized Layout

TOTAL_PARTICLES = 64
DISTRIBUTION_TYPE = "grid"
SIZE_DISTRIBUTION = "normal"
ROTATION_ENABLED = False

Output Files

  • 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

Tips

  1. Adjust Rarity: Make sure KELP_RARITY + BUBBLE_RARITY = 1.0 for balanced distribution
  2. Size Range: Keep MIN_SCALE and MAX_SCALE reasonable to avoid tiny or oversized images
  3. Overlap Control: Use OVERLAP_THRESHOLD to fine-tune how much images can overlap
  4. Distribution: Try different distribution types for different artistic effects
  5. Performance: Higher particle counts will take longer to generate

Troubleshooting

  • "No images could be loaded": Make sure kelp.webp and minecraft-bubble.png are in the same directory
  • Slow generation: Reduce TOTAL_PARTICLES or enable overlap
  • Images too large/small: Adjust MIN_SCALE and MAX_SCALE values
  • Poor distribution: Try different DISTRIBUTION_TYPE values

Customization

The script is designed to be easily customizable. You can:

  • Add more image types by modifying the image_files dictionary
  • Create new distribution patterns in get_random_position()
  • Add more visual effects in apply_image_effects()
  • Modify the canvas dimensions by changing CANVAS_WIDTH and CANVAS_HEIGHT

Support the Project

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

About

A Python script that places images randomly on a 1920x1080 canvas with configurable parameters for creating unique compositions.

Resources

Stars

Watchers

Forks

Languages