GithubHelp home page GithubHelp logo

nvdnkpr / spritemapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yostudios/spritemapper

1.0 0.0 0.0 535 KB

CSS Spritemap Generator

Home Page: http://yostudios.github.com/Spritemapper/

License: MIT License

spritemapper's Introduction

Spritemapper

Homepage:http://yostudios.github.com/Spritemapper/
Authors: Yo Studios <[email protected]>

Spritemapper is an application that merges multiple images into one and generates CSS positioning for the corresponding slices.

The package consists of a simple command-line tool that "does the job" and a Python library including its own PNG and CSS parser. The choice of writing/bundling this was to stay off 3rd-party requirements. Anybody who has ever had the pleasant job of installing PIL on various platforms should have a pretty good idea about what we're trying to avoid.

There are multiple alternatives to Spritemapper, but they all require a bit too much manual labour, whereas Spritemapper reads your current CSS, replacing background images and position with the generated result.

This technique drastically improves your website's loading speed, effectively reducing bandwidth by downloading fewer images.

Spritemapper in action

Here's a simple example illustrating what Spritemapper will do with your CSS:

.emote.smile {
  background: red url(../img/emoticons/smile.png) no-repeat;
}
.emote.grin {
  background: white url(../img/emoticons/grin.png) no-repeat;
}

turns into:

.emote.smile {
  background: red url(../img/emoticons.png) no-repeat 0 0;
}
.emote.grin {
  background: white url(../img/emoticons.png) no-repeat 0 -16px;
}

Check our homepage for real life examples.

Usage

-h, --help
show a help message and exit
-c INI, --conf=INI
read base configuration from INI (see Configuration options)
--padding=N
keep N pixels of padding between sprites

Configuration options

Configuration options can be specified in one of two ways: inline in the CSS, or using passing an INI file with defaults. For CSS it looks something like:

/* spritemapper.output_css = foofile.css

You can do the exact equivalent using an INI file, like this:

[spritemapper]
output_css = foofile.css

It's important to note that all paths are relative to the CSS file being processed.

base_url
a url at which the resulting css and image files can be reached. by default uses file-relative paths (recommended).
sprite_dirs
a list of directories within which to allow spritemaps to be generated. by default all directories are eligible.
recursive
set if sub-spritemaps should be generated when sub-directories are found. set by default.
output_image
the name of output spritemap image. sprite_dirs is incompatible with this because both tell the spritemapper how to sort sprites into spritemaps. by default <dir> + .png.
output_css
the name for the rewritten CSS file. by default sm_{basename}{extension}.
padding
amount of padding space between two images. this is mostly useful to counteract subpixel rendering artifacts on iOS devices. by default 1.
anneal_steps
a larger number here makes the box packer algorithm try more combinations. by default 9200.

Running tests

The test suite requires Nose. You can run them through setup.py, python setup.py test or plain nosetests.

spritemapper's People

Contributors

jbergstroem avatar jnordberg avatar lericson avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.