Home

Awesome

Travis CI Coverage Status Requirements Status PyPI version Downloads number

Spriter

Spriter is a simple and flexible dynamic sprite generator for CSS, using Python. It can process CSS both synchronous and asynchronous as it provides classes to be used in your python code and also a watcher that listens to your filesystem and changes CSS and sprite as soon as a static is changed.

Installation

Automatic installation::

pip install spriter

Spriter is listed in PyPI and can be installed with pip or easy_install.

Manual installation: Download the latest source from PyPI.

tar xvzf spriter-$VERSION.tar.gz
cd spriter-$VERSION
sudo python setup.py install

Spriter source code is hosted on GitHub.

Usage

It's really simple to use pitomba sprites generator. Imagine you have 3 images files at your home's directory: ~/1.png, ~/2.png, ~/3.png. Then open the python interpreter

from spriter import Spriter
sprt = Spriter(["~/1.png", "~/2.png", "~/3.png"])
css_path, image_path = sprt.gen_sprite()
print css_path
print image_path

This sprite was generated using the Spriter

Alt mosaico

A more detailed explanation. The source distribution includes demo applications that are not present when Spriter is installed via pip or easy_install, so you may wish to download the source tarball.

Flags used by demo app are provided by FAMFAMFAM

Documentation

Spriter attributes:

Sprites works with paths and urls_paths at same time. So if you have a local image and an Internet image the Spriter will merge the files onto a sprite file.

class_name_function:

"""The general rule of css's class name is:
case insensitive; not preceded by number and, in general, ascii letters.
The filename will be transformed in lowercas;
all non-ascii letters will be change to empty string;
all non letter or non number will be change to '-';
started by letter s to avoid numbers-only filenames"""

So, The css class name of an image named "123.png" will be: "s123"

Spriter functions:

WebP Support

First, be sure complete google's webp install instructions before proceed.

Then, (re-)install Pillow's library.

To save an sprite as webp be sure the image_extension property equals to WEBP, and the sprite's name with webp extension (sprite.webp).

from spriter import Spriter
sprt = Spriter(["~/1.png", "~/2.png", "~/3.png"], image_extension="WEBP", sprite_name="sprite.webp")
sprt.do_write_image()

Since webp's format is not fully supported by all major web browser use it when you have absolute certain that your clients have support to this extension.

Visit Can I Use's website to follow up the evolution of support

Base64 Support

Since version 1.2 is possibile to generate base64 sprite, i.e without generate the sprite files and put directly in css's string (file).

To get the base64 strings:

from spriter import Spriter
sprt = Spriter(["~/1.png", "~/2.png", "~/3.png"])
image_str = sprt.get_base64_str()

To get the css's string with base64 sprite string:

from spriter import Spriter
sprt = Spriter(["~/1.png", "~/2.png", "~/3.png"])
css_str = sprt.get_css_base64()

If you want generate the css file:

from spriter import Spriter
sprt = Spriter(["~/1.png", "~/2.png", "~/3.png"])
css_path = sprt.do_write_css(is_base64=True)

Or

from spriter import Spriter
sprt = Spriter(["~/1.png", "~/2.png", "~/3.png"])
css_path, image_path = sprt.gen_sprite(is_base64=True)

the last script don't write the image file (i.e, image path is None).

Contribute

Get touch via github. Don't be shy, open an issue or mail us. We speak PT_BR too. ;)

Or following up How to contribute

License

Bitdeli Badge