|
| 1 | +# imacss |
| 2 | + |
| 3 | +An application and library that transforms image files to [data URIs (rfc2397)](https://www.ietf.org/rfc/rfc2397.txt) and embeds them into a single CSS file as background images. |
| 4 | + |
| 5 | +Let's say you have a web-based frontend which embeds a lot of images (e.g. icons). This referencing produces HTTP requests for every single image. What if you would like to minimize it to just one request? That is something `imacss` can do for you. |
| 6 | + |
| 7 | +## What? |
| 8 | + |
| 9 | +Okay, enough words. Let's dive straight into a transformation example. If we assume that you have two SVGs, like `github.svg` and `quitter.svg`, `imacss` would generate this CSS code for you. |
| 10 | + |
| 11 | + .imacss.imacss-github { |
| 12 | + background:url(data:image/svg+xml;base64,iVBORw0KGgoAAAANSUhEBg...); |
| 13 | + } |
| 14 | + |
| 15 | + .imacss.imacss-quitter { |
| 16 | + background:url(data:image/svg+xml;base64,iVBORw0KGgoAAAANSUhADA...); |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | +## CLI |
| 21 | + |
| 22 | +`imacss` comes with a command-line interface which pipes the output to stdout by default (yeah, plain old text streams FTW!). |
| 23 | + |
| 24 | +### Installation |
| 25 | + |
| 26 | +Install with [npm](https://npmjs.org/package/imacss) globally. |
| 27 | + |
| 28 | + npm install -g imacss |
| 29 | + |
| 30 | +### Usage examples |
| 31 | + |
| 32 | +Embed all SVGs in a particular directory and all its subdirectories (will pipe the output to stdout). |
| 33 | + |
| 34 | + imacss "~/projects/webapp/images/**/*.svg" |
| 35 | + |
| 36 | +Embed all SVGs in a particular directory and transfer them to a CSS file which will be saved in the CWD. |
| 37 | + |
| 38 | + imacss "~/projects/webapp/images/*.svg" images.svg.css |
| 39 | + |
| 40 | +Embed all SVGs _and_ PNGs in a particular directory and transfer them to a CSS file which will be saved in the CWD. |
| 41 | + |
| 42 | + imacss "~/projects/webapp/images/*.{svg,png}" images.css |
| 43 | + |
| 44 | +If you don't like the `imacss` selector namespace you are able to modify it as well. |
| 45 | + |
| 46 | + imacss "~/projects/webapp/images/*.{svg,png}" images.css foobar |
| 47 | + |
| 48 | +will produce this selector structure in the CSS file: |
| 49 | + |
| 50 | + .foobar.foobar-github {...} |
| 51 | + |
| 52 | +## API |
| 53 | + |
| 54 | +If you would like to use the `imacss` functionality within your application, there is an API for that. |
| 55 | + |
| 56 | +### Install |
| 57 | + |
| 58 | +Install with [npm](https://npmjs.org/package/imacss) |
| 59 | + |
| 60 | + npm install --save imacss |
| 61 | + |
| 62 | +### Methods |
| 63 | + |
| 64 | +#### convert(glob[, namespace]); |
| 65 | + |
| 66 | +Converts the image files from the specified glob and returns a stream with the CSS selectors that can be piped to somewhere else. |
| 67 | + |
| 68 | +**Arguments** |
| 69 | + |
| 70 | +`glob` |
| 71 | + |
| 72 | +The instruction to search for images. |
| 73 | + |
| 74 | +`namespace` (optional; default=imacss) |
| 75 | + |
| 76 | +The CSS selector namespace. |
| 77 | + |
| 78 | +### Usage example |
| 79 | + |
| 80 | + var imacss = require('imacss'); |
| 81 | + |
| 82 | + imacss |
| 83 | + .transform('/path/to/your/images/*.png') |
| 84 | + .on('error', function (err) { |
| 85 | + error('Transforming images failed: ' + err); |
| 86 | + }) |
| 87 | + .pipe(process.stdout); |
| 88 | + |
| 89 | + |
| 90 | +## Changelog |
| 91 | + |
| 92 | +### Version 0.1.0 (20140211) |
| 93 | + |
| 94 | +- Initial Release. Implemented the core functionality (CLI and API). |
| 95 | + |
| 96 | +## Author |
| 97 | + |
| 98 | +Copyright 2014, [André König](http://iam.andrekoenig.info) (andre.koenig@posteo.de) |
0 commit comments