Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
I

imacss

> 编程语言
Open source

An application and library that transforms image files to data URIs and embeds them into a single CSS file.

396 stars0 likes0 views
WebsiteGitHub

About

An application and library that transforms image files to data URIs and embeds them into a single CSS file.

[!NOTE] This project is preserved as a historical open-source project. It is not actively maintained, and its dependencies or recommended practices may be outdated.

I’m keeping it public because it may still be useful as reference material. If you rely on it in production, please review the code carefully and consider maintaining your own fork.

imacss

pronunciation: imax

An application and library that transforms image files to data URIs (rfc2397) and embeds them into a single CSS file as background images.

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.

What?

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 will generate this CSS code for you.

css
.imacss.imacss-github {
    background:url(data:image/svg+xml;base64,iVBORw0KGgoAAAANSUhEBg...);
}

.imacss.imacss-quitter {
    background:url(data:image/svg+xml;base64,iVBORw0KGgoAAAANSUhADA...);
}

You can refer to this images by using the respective CSS classes:

xml

CLI

imacss comes with a command-line interface which pipes the output to stdout by default (yeah, plain old text streams FTW!).

Installation

Install with npm globally.

bash
npm install -g imacss

Usage examples

Embed all SVGs in a particular directory and all its subdirectories (will pipe the output to stdout).

$ imacss "~/projects/webapp/images/**/*.svg"

Embed all SVGs in a particular directory and transfer them to a CSS file which will be saved in the CWD.

$ imacss "~/projects/webapp/images/*.svg" > images.svg.css

Embed all SVGs and PNGs in a particular directory and transfer them to a CSS file which will be saved in the CWD.

$ imacss "~/projects/webapp/images/*.{svg,png}" > images.css

If you don't like the imacss selector namespace you are able to modify it as well.

$ imacss "~/projects/webapp/images/*.{svg,png}" foobar > images.css

will produce this selector structure in the CSS file:

css
.foobar.foobar-github {...}

Important: Please note that imacss does not embed image/svg+xml as base64 strings. Instead it will use the raw utf-8 representation.

API

If you would like to use the imacss functionality within your application, there is an API for that.

Install

Install with npm

bash
npm install --save imacss

Methods

transform(glob[, namespace]);

Transforms the image files from the specified glob and returns a stream with the CSS selectors that can be piped to somewhere else.

Arguments

glob

String || Vinyl file object

The path to the images which should be transformed. You can use any glob pattern you want or you're also able pass single Vinyl file objects.

namespace (optional; default=imacss)

String || Function

A string containing the css class namespace prefix, or a function to generate the entire CSS ruleset.

The CSS selector namespace.

Usage example

javascript
var imacss = require('imacss');

imacss
    .transform('/path/to/your/images/*.png')
    .on('error', function onError (err) {
        console.error('Transforming images failed: ' + err);
    })
    .pipe(process.stdout);

Passing a function to customize the resulting CSS rule set

javascript
var imacss = require('imacss');

function generateCss(image) {
    return '.image-' + image.slug + ' { ' + 'background-image:' + 'url(\'' + image.datauri + '\'); }';
}

imacss
    .transform('/path/to/your/images/*.png', generateCss)
    .on('error', function (err) {
        console.error('Transforming images failed: ' + err);
    })
    .pipe(process.stdout);

Author

Copyright 2014 - 2015, André König ([email protected])

Issues· 2 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言