Skip to content

Instantly share code, notes, and snippets.

@tkjaergaard
Last active December 31, 2015 17:49
Show Gist options
  • Select an option

  • Save tkjaergaard/8023126 to your computer and use it in GitHub Desktop.

Select an option

Save tkjaergaard/8023126 to your computer and use it in GitHub Desktop.
stupid

Stupid Sprite Generator CLI

Installation

  • create a file in /usr/local/bin called "stupid" and add the content for "stupid" in this gist to the file. Alternatively you could do a wget.

  • Set the file to executable by chmod +x stupid

Now, the stupid command shoud be available anywhere.

Dependencies

  • Imagemagick
  • Optipng

Instructions

Navigate to a directory where you have your image-files located.

Now, you could run stupid and your files would be generated to 2x9 sprites.

Options

Options default description
-t 2x9 Sprite grid to be generated
-o 5 Optimization lavel [0-9]
-d . Image location
-n sprite Sprite name, numbers will be appended
-out . Output directory

No options are required.

stupid -t 2x7 -o 5 -d images/ -n sprite -out sprites/

Stupid Sprite Generator
Stupid jQuery Sprite Anim

#!/bin/bash
## Defaults
tiles=2x9
optimize=5
dir=.
output=.
name="sprite"
while getopts t:o:d:n:out: opt; do
case $opt in
t)
tiles=$OPTARG
;;
o)
optimize=$OPTARG
;;
d)
dir=${OPTARG%/}
;;
n)
name=$OPTARG
;;
out)
output=${OPTARG%/}
;;
esac
done
# take all images and convert it to sprites
echo "Converting images to sprites in $tiles grid"
echo "Saving to $output/$name{xxxxxx}.png"
montage -tile $tiles -mode concatenate -background transparent "$dir/*.*" $output/$name%05d.png > /dev/null 2>&1
echo "-- Sprites converted --"
# Optimize images
echo "Compressing sprites with optimization $optimize"
optipng -o$optimize $output/*.png > /dev/null 2>&1
echo "-- Sprites optimized --"
echo "Done, happy coding!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment