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

gulp-imagine-64

v2.0.1

Published

Gulp plugin converts globs of image files to array of plain objects with base64 strings.

Downloads

10

Readme

gulp-imagine-64

Gulp plugin converts globs of image files to array of plain objects with base64 strings.

Usage

var gulp = require('gulp');
var concat = require('gulp-concat');
var header = require('gulp-header');
var footer = require('gulp-footer');
var img64 = require('gulp-imagine-64');

var img = require('./config').img64;

gulp.task('images', function() {
    return gulp.src(img.src.files, img.src.options)
        .pipe(img64(img.dest.options))
        .pipe(header(img.src.header))
        .pipe(footer(img.src.footer))
        .pipe(concat(img.dest.file))
        .pipe(header(img.dest.header))
        .pipe(footer(img.dest.footer))
        .pipe(gulp.dest(img.dest.dir));
});

The above sample gulpfile.js can be found in the module folder (node_modules/gulp-imagine-64.js).

Output

See build/images.js for some sample output.

Configuration

The img object in the above usage example may be configured as follows:

module.exports = {
    img64: {
        src: {
            globs: 'images/*.{gif,png,jpg,jpeg,svg,ico}',
            options: {}
        },
        transform: {
            options: {},
            header: '',
            footer: ''
        },
        dest: {
            path: 'build',
            filename: 'images.js',
            header: 'module.exports = { // This file generated by gulp-imagine-64 at '
                 + (new Date).toLocaleTimeString() + ' on '
                 + (new Date).toLocaleDateString() + '\n',
            footer: '\n};\n',
            options: {}
        }
    }
};

The above sample config.js can be found in the module folder (node_modules/config.js).

Required configuration data

The only required fields are glob (input files) and path/filename (output file).

Configuration options

The header, footer, and options fields are all optional. You can give '' and {} as I have done here for illustrative purposes; or you can omit them entirely. If you do omit header or footer you should remove or comment off the .pipe() call(s) that reference them as well.

img64.src.globs

Required. Passed to gulp.src() as its globs parameter.

img64.src.options

Optional. Passed to gulp.src() as its options parameter. Although there's only one output file, note that options.base will affect the resulting image keys in that file just as it would normally affect the output files' pathnames. That is, the resulting keys will include the path relative to base (using slash as delimiter).

img64.transform.options.template

Optional. You can provide an arbitrary template in img64.transform.options.template with variables. For each file in the img64.src.files glob, the template will substitute data for the following variables:

variable|substitution data :---:|-------- {name} | the filename part of the current file (sans extension) {key} | the relative path of the current file, relative to base (sans extension) {ext} | the extension part of the current file (sans leading period) {mimetype} | the extension mapped through the mime type table (see below) {data} | the image file's data as a base64 string

Note that {name} and {key} are the same unless the files are in subfolders and img64.src.options.base is given.

If not given, the default template is:

    "{key}": {
        type: "{mimetype}",
        data: "{data}"
    },`

As of v2, the default template uses the new {mimetype} variable, which maps the extension (case-insensitive) to the correct MIME type through the img64.mimetypeDictionary hash. If not found, the value images/{ext} (but forced to lower case) is used. The hash can however be augmented or replaced before invoking the function.

This is a potentially breaking change from v1 which used image/{ext}. If your application monkey-patched the MIME type, you will need to either retire that patch or pass the v1 template in the img64.transform.options.template option.

img64.transform.header

Optional. String to prepend to the result of each transform.

img64.transform.footer

Optional. String to append to the result of each transform.

img64.dest.path

Required. Output folder path. Passed to gulp.dest() as its path parameter.

img64.dest.filename

Required. Output filename. Passed to concat() as its filename "option" (required so not really an option).

img64.dest.header

Optional. String to prepend to the entire output file.

img64.dest.footer

Optional. String to append to the entire output file.

img64.dest.options

Optional. Passed to gulp.dest() as its options parameter.

img64.mimetypes

A hash of exceptional MIME types. MIME types that are a faithful reflection of the lower cased extension do not need to be included.

key(lower cased {ext}) | Value{mimetype} :---: | :---: jpg | image/jpeg svg | image/svg+xml ico | image/x-icon

The hash is deferenced by the file lower cased extension. The default hash has the following keys and values. It can be augmented or replaced before invoking the function.

Converting image data to DOM objects

See build/imagine.js for an example module that consumes the data on the client side, producing a hash of usable Image DOM objects. (This mutates the original hash which isn't needed anymore. You could of course change this to preserve the original hash.)

Version History

See releases.