Skip to main content

A simple css sprite generator.

Project description

A simple css sprite generator.

  • Free software: BSD 2-Clause License


pip install css-sprite

You can also install the in-development version with:

pip install


To generate a css sprite from images:

css-sprite [-h] [--grid GRID] --output OUTPUT
    [--mode MODE] [--vertical] [--background BACKGROUND]
    [--template TEMPLATE | --template-path TEMPLATE_PATH]
    [--verbose] [--version] image [image ...]

Output is mainly a new image but you can also generate the accompanying css.

Positional arguments:

image Path to image to include in sprite.

-h, --help

show this help message and exit

--grid GRID, -g GRID

Grid cell size to use. One of: auto, X:Y.

--output OUTPUT, -o OUTPUT

Output file.

--mode MODE, -m MODE

Force a certain image mode in the output, see:

--vertical, -v

Stack the images vertically (they are stacked horizontally by default).


Background color.

--template TEMPLATE, -t TEMPLATE

Jinja template for CSS output on stdout.


Jinja template path for CSS output on stdout.


Make output verbose.


show program’s version number and exit

Template variables:

  • images - list of dicts with fields:

    • index - counter starting from 1

    • index0 - counter starting from 0

    • filename - path to source image

    • offset - dict with fields: x and y (integers)

    • position - dict with fields: x and y (integers)

    • width - integer (same as cell.width for now)

    • height - integer (same as cell.height for now)

  • grid - dict with fields

    • width - integer

    • height - integer

    • vertical - bool (True if you have used --vertical)

  • cell - dict with fields:

    • count - number of input images

    • width - integer

    • height - integer

  • output - pathlib.Path of output file



To run all the tests run:


Note, to combine the coverage data from all the tox environments run:


set PYTEST_ADDOPTS=--cov-append


PYTEST_ADDOPTS=--cov-append tox


0.2.0 (2022-05-06)

  • Allow images to overlap by using alpha composition. Useful when cell is smaller than images, and images are transparent.

  • Restructure template context. BACKWARDS INCOMPATIBLE

0.1.1 (2022-04-18)

  • Remove the universal flag (don’t produce py2.py3 wheels since py2 isn’t supported anyway).

0.1.0 (2022-04-18)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

css-sprite-0.2.0.tar.gz (19.2 kB view hashes)

Uploaded Source

Built Distribution

css_sprite-0.2.0-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page