Package: pyconizr
© 2014 Thomas KhynPython package to generate sprites from SVG iconsThis package takes its inspiration fromIconizrandgrunt-iconizrby
Joschi Kuphal.From Joschi’s words, Iconizr …:... takes a folder of SVG images and creates a CSS icon kit out of them.
Depending on the client's capabilities, icons are served as SVG / PNG
sprite or embedded data URIs. iconizr creates suitable CSS / Sass / LESS
etc. resources and a JavaScript loader for easy integration into your
HTML documents.Not all the functionnalities from the original Iconizr are implemented yet,
but most of them are here.Works on Python 2.6 and 2.7.InstallationAs straighforward as it can be, usingpip:pip install pyconizrRequirementsPyconizr will install all the required dependencies, except Cairo and librsvg
and their python bindings, which are needed to generate PNG images. Please make
sure they are installed in your environment if you want to use the pyconizr’s
PNG functionalities.If you are on Windows, the quickest way to install them is to use eitherPyGTK(for python 2.6 and 2.7) orPyGI(for python 2.7).UsageFrom the command line:pyconizr [options]From python:from pyconizr import iconize
iconize(option1=val1, option2=val2, ...)Default behaviorBy default, pyconizr will:optimize every SVG file in the current working directory usingscour(without overwriting them)concatenate them to create an optimized SVG sprite in
current_working_dir/sprites/sourcedir_name.svgcreate a PNG sprite from the SVG sprite as
current_working_dir/sprites/sourcedir_name.pngcreate a CSS/SCSS/whatever file at current_working_dir/sourcedir_nameThis can be configured using the following options.OptionsAll options should be prefixed by--in the command line (if not using the
shortcut), or should be provided as keyword arguments to theiconizefunction.in, -iThe input directory or files (as a wildcard) that should be used to generate
the sprite.
Only valid SVG files will be taken into account, so there is no need to add
a *.svg wildcard (“dir/*” will only include the *.svg files in dir).
Defaults to the current working directory.out, -oThe output path for the generated output file (CSS, SASS…). The directory
will be created if it does not already exist.
Defaults to the ‘out’ directory in the current working directory.out-sprite, -sThe output path for the SVG and PNG sprites. The directory will be created
if it does not already exist.
Defaults to the ‘sprites’ directory in the output directory.out-iconsThe output path for the optimized SVG and rasterized PNG individual icons.
If left blank, no icons will be generated. If defined, a supplementary
output file will be generated with a ‘-icons’ suffix.
Defaults to blank (no icons generated).render, -rHow the output should be rendered. Can be:css: for CSS output [default]scss: for SASS outputno orFalsyfrom python: no output (to simply generate the sprite)a path to a customJinja2template file for a 100% custom output (see
existing templates for available variables)static-urlThe absolute URL to the static directory. Used for links towards sprites and
icons files from within the generated outputs.
Defaults to/staticsprites-urlThe absolute or relative (to static-url) URL to the sprites directory. Used
for links towards sprite files.
Defaults tospritesicons-urlThe absolute or relative (to static-url) URL to the icons directory. Used
for links towards individual icons. Not used if out-icons is not defined.
Defaults toiconspaddingPadding around the icons, in pixels.
Defaults to0.layoutThe sprite layout. Can be vertical, horizontal or diagonal.
Defaults tovertical.png/nopngBy default, png fallbacks will be generated. When using theiconize,
function, usepng=Falseto disable the behavior. With the command line,
use--nopng.
Defaults toTruedataShould SVG and PNG images be linked as dataURIs? Remember that a page loads
faster (thanks to caching vs dataURI decoding) if the CSS does not use
dataURIs.
Defaults toFalseclassA common CSS class for all the icons in the sprite.
Default toNone.selectorsComma-separated list of selectors that can be embedded in icons filenames,
using the_separator. For example, there a file name_hover.svg will be
taken as the hovered version of the icon name.
Defaults tohover,target,activeunitThe unit to be used for thebackground-positionproperty. Only supposed
to work withpxand%.
Defaults topxscour-*All the options fromscour, using the ‘scour-’ prefix. For example,
‘strip-xml-prolog’ becomes ‘scour-strip-xml-prolog’.
Defaults to best possible optimisation parameters for sprite generation.There are 2 command-line options added for scour parameters:scour-disable-comment-strippingPyconizr enables comment stripping by default. When using theiconizefunction, useenable_comment_stripping=Falseto
disable this feature. From the command line you need to use--scour-disable-comment-strippingscour-verbosePyconizr runs scour in quiet mode by default. If you need to see
scour’s non-error output, usequiet=Falsewith theiconizefunction, or--scour-verbosefrom the command line.