npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imacss

v1.0.0

Published

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

Downloads

236

Readme

imacss Build Status

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.

.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:

<div class="imacss imacss-quitter">...</div>

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.

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:

.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

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

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

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])