connect-favicon-canvas

0.1.0 • Public • Published

connect-favicon-canvas

connect middleware for generating server-side images and icons with node-canvas.

Install:

npm install connect-favicon-canvas

Example:

    var connect = require('connect'),
        faviconCanvas = require('connect-favicon-canvas'),
        generator,
        rand,
        app;
 
    rand = function( arr ){
        return arr[ ~~(Math.random()*arr.length) ];
    };
    //draw an image using the canvas2d API    
    generator = function( canvas, next ){
        var ctx = canvas.getContext('2d');
        ctx.fillStyle = rand(['aquamarine','teal','red','yellow','lime']);
        var border = 8,
            sqSize = canvas.width - (border*2);
        ctx.fillRect( border, border, sqSize, sqSize );
        next();
    };
    //start a connect server that servers the generative /favicon.ico
    app = connect()
        .use(faviconCanvas( generator ))
        .use(faviconCanvas( generator, {
            route: '/apple-touch-icon-precomposed.png',
            size: 152
        }))
        .use(function( req, res ){
            res.end('Look at the tab! generative favicon!\n');
        })
        .listen(5000);

Released under MIT License, created by Kyle Phillips

Readme

Keywords

none

Package Sidebar

Install

npm i connect-favicon-canvas

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • hapticdata