For some time now, I've started moving away from monolithic and complex GUI tools in favour of more streamlined command line interfaces, generally using text based inputs like JSON or YAML.

While there is still a need for GUI tools for performing complex actions, sometimes you just want something simple without a load of bells and whistles. I especially make use of CLI tools in build processes, and it is so much easier when such tools are simple exe files that can be deployed via the package manager of your choice, rather than requiring dozens of DLL's, registry settings and who knows what.

While my own tools are certainly guilty of some of the above, they do at least include CLI tools, some of which are powerful in their own right (and perhaps some not powerful enough). Sometimes though, even that is too much - such tools generally have dependencies of their own (although much fewer than the GUI versions), and there's no easy way to just get CLI versions without the extra components.

Recently I had need of generating some sprite sheets for use with HTML pages as part of a build process, but installing Spriter was going to be overkill as I didn't need anything it offers bar the absolute core - pack some images together and generate some usable CSS. So I opted to create a small console tool to do just that, and have released the source.

About the tool

A simple example using simple codes
A simple example using simple codes

The tool, sprpack.exe, is a stand alone (well, it needs Microsoft .NET 4, so as stand alone as you can get with that involved) tool that you can point at a given directory and it will suck in the image files and spit out a sprite sheet containing all the images neatly laid out to take the least amount of space possible. It will also create some basic CSS if required.

However, there's obviously a big caveat - it will do that one job and it will do it well enough. But it doesn't include any form of advanced functionality, for example templates to control output CSS, advanced file patterns for including only specify files, layout options, in fact pretty much no options at all. It has one(ish) job.

Options

The following list details the arguments that sprpack.exe accepts. All are optional.

  • path - specifies the path to process. Defaults to the current directory
  • mask - comma separated list of file masks to search. Defaults to *.png
  • out - the file name of the sprite sheet graphic. Defaults to sheet.png
  • css - the file name where the CSS will be written. If not specified, CSS will not be generated
  • class - the base CSS class name. Ignored if /css is not set

As you can see, it is a very simple affair!

Note! The tool will overwrite output files without prompting

Source Code

The source code for the simple packer can be found on the project page.

I haven't done it yet, but I'll probably add a NuGet package so I can more easily drop it into a build process. At this point I don't know if I'll expand the source to include any more options but I suppose I'll build a few extra ones in over time.

Update History

  • 2015-05-24 - First published
  • 2020-11-21 - Updated formatting

Like what you're reading? Perhaps you like to buy us a coffee?

Donate via Buy Me a Coffee

Donate via PayPal


Comments