Image Sprites and CSS Classes creator
Example:
Source Images
Generated Sprite
Generated CSS Classes
Image Sprites are a very good way to feed your application some images.
Basically it consists of combining a set of images in a larger one and then just cache it.
When you need one of the small images all you have to know are the coodenates of it on the large one.
With this technique, you just need to load one image for the entire application and reuse it, instead loading each image at a time.
Here I'll be covering the implementation with CSS used on WebSites but you can use this technique wherever you want.
Why this?
Sure you can Google it and find a lot of matches telling you how to use sprites and CSS but where’s the “no pain” way of building them and their CSS?
All of them will tell you to use Photoshop of any other photo editing tool but this will always take a lot of time.
That’s when this cute little application comes in.
It will generate the sprite image and its css in no time, and you can add images later and regenerate it without having to worry about breaking your code!
Using the code
On the package you’ll find a compiled version and its source code.
Just drop the SpriteCreator.exe file on the folder that have the images to be inclided on the sprite and run it. DONE!
Assumptions and Limitations
- All images on the folder have the same size, ex: 16x16, 32x32, ...
- The size of the images will be the size of the first image loaded into the sprite.
- The big srite image will be always square, having the minimum size needed to fit all images inside.
- All the images on the folder will be included on the sprite.
- Only jpg, jpeg, png & bmp extensions are supported.
- The name of the images is used on the CSS class name.
- The spaces on images file name will be replaced with -
- The result 2 files, one *.png and *.css where * is a generated GUID
Options
This is a console application so you can pass some customization arguments.
- /h :: Help.
- /source :: Specify the images source directory path.
- /destination :: Destination dir path.
- /classprefix :: CSS class name prefix.
Ex: SpriteCreator.exe /source shadow /classprefix app-ui-