Code Monkey home page Code Monkey logo

images-to-variables's Introduction

images-to-variables

NPM version Build status Coverage Status Dependency Status

A simple utility for generating Sass/Less variables for images.

Installation

Install from NPM:

npm install images-to-variables

Using from Node

To generate encoded image values from Node, call the create function. A promise is returned and an array containing the encoded variables is passed to handlers:

var imagesToVariables = require('images-to-variables');

imagesToVariables.create( '*.png' ).then( function( variables ) {
	console.log( variables[0].name );
	console.log( variables[0].length );
	console.log( variables[0].value );
} );

A Note About Encoding: currently, the .png contents are base-64 encoded so it can be safely included. For .svg, the contents are simply escaped as per RFC 2397.

Options

Output File

Specify the dest option to write the variables directly to a file :

imagesToVariables.create( '*.png', { dest: variables.less } );

Prefix Variables

Specify the prefix option to prefix the generated variables:

imagesToVariables.create( '*.png', { prefix: 'vui-' } );

Sass

Specify the scssFormatter if you want scss variables:

imagesToVariables.create(
	'*.png', {
		formatter: imagesToVariables.scssFormatter
	}
);

Less

The default variable format is Less, however you can explicitly specify the lessFormatter if desired:

imagesToVariables.create(
	'*.png', {
		formatter: imagesToVariables.lessFormatter
	}
);

Compression

By default, images are minified using imagemin before encoding the variables. This can optionally be disabled by providing the optimize option:

imagesToVariables.create( '*.png', { optimize: false } );

Using from CLI

Creating variables from the CLI is a piece of cake. For example, the following commands will generate Less and Scss files containing variables formatted for Less or Scss respectively. A variable is generated for each file represented by the *.png pattern, and the variables will be prefixed with vui-.

imgtoless -p vui- -o variables.less *.png

imgtoscss -p vui- -o variables.scss *.png

Note: Currently, the images must be uniquely named. The module currently does not handle duplicate file names spread across directories, but this could be added.

images-to-variables's People

Contributors

dbatiste avatar brian-pearson avatar omsmith avatar pdehaan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.