Skip to main content

Generate sprites from SVG icons

Project description

© 2014 Thomas Khyn

Python package to generate sprites from SVG icons

This package takes its inspiration from from Iconizr and grunt-iconizr by 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.

Installation

As straighforward as it can be, using pip:

pip install pyconizr

Usage

From the command line:

pyconizr [options]

From python:

from pyconizr import iconize
iconize(option1=val1, option2=val2, ...)

Default behavior

By default, pyconizr will:
  • optimize every SVG file in the current working directory using scour (without overwriting them)

  • concatenate them to create an optimized SVG sprite in current_working_dir/sprites/sourcedir_name.svg

  • create a PNG sprite from the SVG sprite as current_working_dir/sprites/sourcedir_name.png

  • create a CSS/SCSS/whatever file at current_working_dir/sourcedir_name

This can be configured using the following options.

Options

All options should be prefixed by -- in the command line (if not using the shortcut), or should be provided as keyword arguments to the iconize function.

in, -i

The 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, -o

The 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, -s

The 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-icons

The 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, -r
How the output should be rendered. Can be:
  • css: for CSS output [default]

  • scss: for SASS output

  • no or Falsy from python: no output (to simply generate the sprite)

  • a path to a custom Jinja2 template file for a 100% custom output (see existing templates for available variables)

static-url

The absolute URL to the static directory. Used for links towards sprites and icons files from within the generated outputs. Defaults to /static

sprites-url

The absolute or relative (to static-url) URL to the sprites directory. Used for links towards sprite files. Defaults to sprites

icons-url

The 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 to icons

padding

Padding around the icons, in pixels. Defaults to 0.

layout

The sprite layout. Can be vertical, horizontal or diagonal. Defaults to vertical.

png

Should png fallbacks be generated? If True, PNG sprites will be generated and used by any icon bearing a ‘nosvg’ class. Defaults to True

data

Should 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 to False

class

A common CSS class for all the icons in the sprite. Default to None.

selectors

Comma-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 to hover,target,active

scour-*

All the options from scour, using the ‘scour-’ prefix. ‘strip-xml-prolog’ becomes ‘scour-strip-xml-prolog’ Defaults to best possible optimisation parameters for sprite generation.

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

pyconizr-0.1a4.zip (20.7 kB view details)

Uploaded Source

Built Distributions

pyconizr-0.1a4.win32.exe (219.3 kB view details)

Uploaded Source

pyconizr-0.1a4-py2.7.egg (27.7 kB view details)

Uploaded Source

File details

Details for the file pyconizr-0.1a4.zip.

File metadata

  • Download URL: pyconizr-0.1a4.zip
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyconizr-0.1a4.zip
Algorithm Hash digest
SHA256 e99958f42ed3dccceb9929458c9b12135e90bcb39636475147564ac4399ee5c0
MD5 6cf706949dd4a523e6dd97012387a839
BLAKE2b-256 c108277a0f86d35f8a9a94ecec75d960609bab8ee510e2d959d6357cd06ee6cb

See more details on using hashes here.

File details

Details for the file pyconizr-0.1a4.win32.exe.

File metadata

  • Download URL: pyconizr-0.1a4.win32.exe
  • Upload date:
  • Size: 219.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyconizr-0.1a4.win32.exe
Algorithm Hash digest
SHA256 508e65ccd27e067e66b7935bb0c7f8a2681eaad67d8862bbbebcd34867ee2ca2
MD5 886a87306576898b5671a85a985610e7
BLAKE2b-256 f05c8e2a063df7821ed58175f2b4452dabe0510d8f8d661c6ff9678e91097506

See more details on using hashes here.

File details

Details for the file pyconizr-0.1a4-py2.7.egg.

File metadata

  • Download URL: pyconizr-0.1a4-py2.7.egg
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyconizr-0.1a4-py2.7.egg
Algorithm Hash digest
SHA256 b4329d1ca0fb79a8bd3f0a2cc301c642d7d11dfb7b8ae6e2203225e81bc08804
MD5 42afe7de500ac963df97df9ec086a54c
BLAKE2b-256 d0259a82148bdebd49332f2aa20276eee6bfdcd75ad83f97571d3fb6a7ace815

See more details on using hashes here.

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