Unity King Logo

Unity King

Automate the Workflow with PowerShell Create Image Collages in Seconds

Automate Sprite Sheet Creation with a Single PowerShell Script

Do you really know you can use PowerShell to manage your graphic design workflow? Most developers and designers think PowerShell is only for system administration...

Game Design Tips and TricksProgramming Tricks
Share this post

⏱️ Estimated reading time: 5 min

Do you really know you can use PowerShell to manage your graphic design workflow? Most developers and designers think PowerShell is only for system administration – but the truth is, this tiny powerhouse can automate image processing, batch-operations, and even sprite-sheet generation faster than most GUI tools.

If you work with game development, UI design, or website graphics, creating sprite sheets manually can be a repetitive nightmare. Dragging images into Photoshop, arranging layers, adjusting spacing, exporting… it wastes hours.

So today, let’s flip the script.

Automate Sprite Sheet Creation with a Single PowerShell Script

This guide introduces a powerful PowerShell script that can take any folder of images and convert them into a neatly arranged sprite sheet (or collage) – complete with:

  • Custom columns & rows
  • Padding control
  • Horizontal & vertical spacing
  • Automatic sheet generation
  • Batch processing (multiple sheets)

No heavy software. No manual dragging. Just select a folder → run the script → get your PNG sprite sheet.

Why This Script is Useful

Whether you’re a:

  • Game developer preparing 2D sprite animations
  • Web designer optimizing assets for CSS sprites
  • UI/UX engineer structuring image sheets
  • Automation enthusiast who loves faster workflows

This script turns a boring, repetitive manual task into a highly optimized one-click process.

How the Script Works

The PowerShell script loops through all images in your selected folder and arranges them into a clean grid. You decide the number of rows, columns, and spacing, and the script automatically calculates the layout and generates multiple sheets if needed.

Here’s what it does step-by-step:

  1. Reads all images in the selected folder.
  2. Loads the first image to detect width/height.
  3. Calculates total required sheet size based on:
    • image dimensions
    • columns × rows
    • horizontal/vertical spacing
    • padding
  4. Creates a transparent PNG canvas.
  5. Draws each image into its calculated spot.
  6. Exports the sprite sheet(s) into a new folder.

How to Use This Script

Follow these simple steps to generate your sprite sheets:

  1. Create a folder and place all your images inside it (PNG/JPG/JPEG supported).
  2. Open PowerShell (Windows + Search → PowerShell).
  3. Copy & paste the script into PowerShell or save it as SpriteSheetGenerator.ps1.
  4. Run it using: .\SpriteSheetGenerator.ps1
  5. Enter the required inputs:
    • Folder path of images
    • Number of columns
    • Number of rows
    • Horizontal spacing
    • Vertical spacing
    • Padding (top/bottom/left/right)
  6. Let the script process the images.

Your sprite sheets will appear in a new folder automatically created inside your image directory named SpriteSheets.

Example Use Cases

1. Game Development (2D Sprite Animations)

Combine dozens of animation frames into a single sprite sheet for Unity, Godot, Unreal Engine or any custom engine. Perfect for character animations, FX frames, or item icons.

2. UI/UX Design

Create a single sheet containing multiple UI elements like icons, badges, or button states to optimize design workflows.

3. Web Development (CSS Sprites)

Generate sprite sheets for icons to improve website performance, reducing HTTP requests for each image.

4. QA Testing & Automation

Combine dozens of screenshots into one sheet for documentation, bug reports, or visual comparison.

5. Photography & Media Collage

Quickly generate aesthetic collages from event photos, thumbnails, or product shots with custom spacing and padding control.

⬇️ Download PowerShell Script

Download Sprite Sheet Generator Script

Full PowerShell Script📜


<#
================================================================================
  Sprite Sheet Generator Script
  Created for UnityKing.com
  License: UnityKing Free Public License (UFPL)

  This script is released as free, open-use software for the community.
  You are allowed to:
      - Use it for personal and commercial projects
      - Modify or extend it
      - Redistribute it with attribution

  Attribution Requirements:
      Include a visible reference to UnityKing.com in the script header
      and wherever redistribution occurs.

  Disclaimer:
      This software is provided "as-is" without any warranty of any kind.
      The author and UnityKing.com are not responsible for any damage
      or data loss resulting from the use of this script.

  Website: https://UnityKing.com
================================================================================
#>

Add-Type -AssemblyName System.Drawing

Write-Host "=== SPRITE SHEET GENERATOR ==="
$folder = Read-Host "Enter images folder path"
$cols = [int](Read-Host "Number of columns (e.g., 5)")
$rows = [int](Read-Host "Number of rows (e.g., 2)")
$hSpace = [int](Read-Host "Horizontal spacing between images (px)"
)
$vSpace = [int](Read-Host "Vertical spacing between images (px)")
$padLeft = [int](Read-Host "Left padding (px)")
$padRight = [int](Read-Host "Right padding (px)")
$padTop = [int](Read-Host "Top padding (px)")
$padBottom = [int](Read-Host "Bottom padding (px)")
$outputFolder = "$folder\SpriteSheets"

if (!(Test-Path $outputFolder)) {
    New-Item -ItemType Directory -Path $outputFolder | Out-Null
}

$images = Get-ChildItem $folder -Include *.png, *.jpg, *.jpeg -Recurse
$imgCount = $images.Count

if ($imgCount -eq 0) {
    Write-Host "No images found. Exiting..."
    exit
}

Write-Host "`nFound $imgCount images."

# Load first image to get universal size
$sample = [System.Drawing.Image]::FromFile($images[0].FullName)
$imgW = $sample.Width
$imgH = $sample.Height

$maxPerSheet = $cols * $rows
$sheetIndex = 1
$start = 0

while ($start -lt $imgCount) {

    $end = [Math]::Min($start + $maxPerSheet - 1, $imgCount - 1)
    $currentImages = $images[$start..$end]

    # Calculate actual rows needed (for last sheet)
    $needed = $currentImages.Count
    $actualRows = [Math]::Ceiling($needed / $cols)

    # Calculate sheet size
    $sheetW = ($imgW * $cols) + ($hSpace * ($cols - 1)) + $padLeft + $padRight
    $sheetH = ($imgH * $actualRows) + ($vSpace * ($actualRows - 1)) + $padTop + $padBottom

    $sheet = New-Object System.Drawing.Bitmap($sheetW, $sheetH)
    $gfx = [System.Drawing.Graphics]::FromImage($sheet)
    $gfx.Clear([System.Drawing.Color]::Transparent)

    $i = 0
    foreach ($imgFile in $currentImages) {
        $bmp = [System.Drawing.Image]::FromFile($imgFile.FullName)

        $col = $i % $cols
        $row = [Math]::Floor($i / $cols)

        $x = $padLeft + ($col * ($imgW + $hSpace))
        $y = $padTop + ($row * ($imgH + $vSpace))

        $gfx.DrawImage($bmp, $x, $y)

        $bmp.Dispose()
        $i++
    }

    $outFile = "$outputFolder\SpriteSheet_$sheetIndex.png"
    $sheet.Save($outFile, [System.Drawing.Imaging.ImageFormat]::Png)

    Write-Host "Generated: SpriteSheet_$sheetIndex.png"

    $gfx.Dispose()
    $sheet.Dispose()

    $sheetIndex++
    $start += $maxPerSheet
}

Write-Host "`nAll sprite sheets generated in: $outputFolder"

Final Thoughts

With a single PowerShell command, you can now transform hundreds of images into perfectly arranged sprite sheets without any manual editing. It’s fast, consistent, and lets you focus on the creative part of your work.

Want more automation tutorials like this? Stay connected with UnityKing – your home for game development tools, productivity scripts, and workflow optimization.

Related Posts

1 Comment

  1. Mono Lover

    Amazing loved it…

Share your thoughts

Your email address will not be published. Required fields are marked *

Subscribe to our newsletter

The latest news, articles, and resources, sent to your inbox weekly. You can unsubscribe any time.

Stay updated with our latest articles, insights, and resources delivered straight to your inbox.
We respect your privacy. Unsubscribe at any time with just one click.