CSS Sprites Generator API Help

http://css.spritegen.com/api.php?help

The CSS Sprites Generator uses a very simple HTTP API. Simply send GET or POST requests (file uploads have to be POST of course) to this URL.

All requests except getToken require a token to be present - this is what identifies you to the system - like a session ID.

All responses are sent as UTF-8 JSON. They contain at least "message" property and an "error" property. Different requests may add other properties. If "error" is true then "message" will be the error message.

All requests may be made as many times as you like (but be reasonable!).

Step 1: Get your token

Request

api.php?getToken

Response

message
Some information about the result
error
Boolean - true if an error occurred
token
Your token for this session

Step 2: Upload your files

You can upload files using a normal HTTP POST.

The file data should be encoded the same as if it were sent from an <input type="file" name="img">.

Files accepted are .png, .jpg, .jpeg, .gif and .zip (containing the aforementioned file types).

Request

api.php?upload&token=...

Response

message
Some information about the result
error
Boolean - true if an error occurred

Step 3: Create your Sprite

Request

api.php?create&token=...

There are also several optional arguments you can pass in - more options may be coming soon:

padding (default = "3")
Padding to apply between images (pixels)
output_type (default = "png")
The output type you want (png, jpeg or gif)
jpeg_reduce_artefacts (default "0")
Pass in 1 to reduce jpeg artefacts (only used when output_type is jpeg)
jpeg_quality (default = "75")
The JPEG quality, from 0 to 100 (higher is better quality, bigger file) (only used when output_type is jpeg)

Response

message
Some information about the result
error
Boolean - true if an error occurred
url
The URL you can download your sprite from
css
The CSS you need to display your sprite correctly
html
Example HTML you can use to test your sprite
info
A list containing information about each file in the sprite (see below)
oldSize
The sum of the filesizes of the uploaded files (bytes)
newSize
The filesize of the new file (bytes)
width
The width of the sprite (pixels)
height
The height of the sprite (pixels)

Step 4: Save your Sprite

Download your sprite from the URL given in the previous step.

For example, in PHP you can simply use file_put_contents('my_file.png', file_get_contents($response['url']))