[![build status](https://secure.travis-ci.org/Filirom1/css-base64-images.png)](http://travis-ci.org/Filirom1/css-base64-images)
css-base64-images
=================

Base64 images in your css file.

![Base64](https://github.com/Filirom1/css-base64-images/raw/master/draft.png)

Transform this:

    .single-quote {
      background: url('../img/background-pattern.gif');
    }

into

    .single-quote {
      background: url('data:image/gif;base64, ');
    }

Only works with CSS files.

Works with:

* single quotes: url('../img/background-pattern.gif');
* double quotes: url("../img/background-pattern.gif");
* absolute URL: url("/img/background-pattern.gif"); but you must specify a `root` path

Do not work with (a warning is shown, but the process continue)

* File bigger than 4Ko (configurable)
* external urls: url("http://my-company.ext/img/background-pattern.gif");
* not found images

## Install

    npm install -g css-b64-images

## Usage

    cd /your/www/root/dir
    css-b64-images css/styles.css > css/style.optimized.css

## As a library

### From File

fromFile(cssFile, root, [options,] cb)

You must specify the `root` path for absolute URLs to work.

    var b64img = require('css-b64-images');

    b64img.fromFile('/your/www/root/dir/css/your-stylesheet.css', '/your/www/root/dir/', function(err, css){
      if(err) console.error('Error:', err);
      console.log(css);
    });

### From String

fromString(css, relativePath, rootPath, [options,] cb)

    var b64img = require('css-b64-images');
    var css = fs.readFileSync('/your/www/root/dir/css/your-stylesheet.css');

    b64img.fromString(css, '/your/www/root/dir/css/', '/your/www/root/dir/', function(err, css){
      if(err) console.error('Error:', err);
      console.log(css);
    });

### Options

* maxSize: (default 4096) bigger images are not base64 in the CSS


## LICENSE

MIT
