Merges multiple .PNG files to aid in the creation of spritesheets.
This script was used heavily in the creation of the art assets for Search For The Red Herring, and I found it to be a huge timesaver. As such, I’ve cleaned it up a bit and released it under the GPL for everyone to use.

Description

The script will take in any number of .PNG files as commandline arguments and will then generate an out.png file, while retaining all alpha data!

New in version 0.3 is the ability to merge images vertically as well as horizontally. Simply pass in the --vert commandline parameter. Also, there is a full example batch file included that will show you some ways to use this script to save even more time.

An example of how it works

Suppose you have 3 individual frames, and you want to combine them into one spritesheet. Here are the frames:

one.png
Merge Example Part 1
two.png
Merge Example Part 2
three.png
Merge Example Part 3

Then by using merge.py in the following way, you’ll end up with this result:

merge.py one.png two.png three.png

out.png
 Merge Example Part 4 - Result!

Requirements

Download

Version 0.3 (Oct 22, 2008) – merge-v0.3.zip

  • Cleaned up code, fixed some bugs
  • Added vertical merge support

Version 0.2 (Oct 23, 2006) – merge-v0.2.zip

  • Doesn’t work, only here for historical purposes

6 responses to “Sprite Merge (merge.py)”

  1. […] Sprite Merge (merge.py) […]

  2. fydo says:

    Hi there brian,

    Thanks for the question. There is an included batch file which demos all of the Sprite Merge functionality. Basically just ensure that all your sprites are of the same vertical height, then pass them all in as command-line parameters. ie.
    “merge.py sprite1.png sprite2.png sprite3.png”

    Hope this helps!

  3. […] A friend of mine has a simple script tool for joining images up into sprite sheets. It is nice, but I didn’t want to deal with a command line thing every time and I wanted the process to be more accessible to users, so I created a GUI spritesheet tool in wxPython. […]

  4. Ram K. says:

    the following is what I did to get this working on python 3.2:
    1.get:
    PIL-1.1.7.win32-py3.2.‌exe
    from:
    http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil
    2. install it…
    3. replace “print “Processing: ” + arg” with print (“Processing: “, arg) in merge.py.
    4. go through the rest of the print statements and add parentheses so “print ‘Unknown option.'” becomes print (‘Unknown option.’) and so on…

    profit 🙂

  5. WH says:

    Hi,
    Thanks for posting this. Unfortunately, the script does not work with Python 3 and cannot merge large numbers of images. I needed to do exactly that for a project, so I wrote my own image merging script.

    You can download the script here:
    https://github.com/255/merge-images

    You will need a version of PIL compatible with Python 3. I recommend Pillow (https://python-pillow.github.io/), which you can install from PyPI.

    I know this post is super old… but hopefully the script will be useful to someone who happens to Google into this like I did.

Leave a Reply

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