identicon-browserify

Identicon Generator for Node.js and the Browser via Browserify


Keywords
identicon, canvas
License
MIT
Install
npm install identicon-browserify@3.0.1

Documentation

identicon-browserify

Npm version Build Status Dependency Status

Identicon generator for Node.js and now the browser!

Difference

This fork allows you to use create identicons in node and the browser with browserify. This also has a breaking change in signature, which no longer returns a buffer but instead a data uri. To keep compatibility between both browser and node versions of canvas, toDataURL is used instead to generate identicons.

There is also an added an extra option to set a different mime type other than PNG (for example: JPEG ('image/jpeg') or the newer WebP ('image/webp')). PNG is used by default and is guaranteed by spec, however extra mime types are generally supported depending on canvas implementation.

Installation

$ npm install identicon-browserify

Installing dependencies

For more information, check the node-canvas Wiki.

## Ubuntu or Debian
apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++

## RHEL or CentOS
yum install cairo-devel libjpeg-turbo-devel libpng-devel giflib-devel gcc-c++

## Mac
curl -sL https://raw.githubusercontent.com/LearnBoost/node-canvas/master/install | sh

Example

var identicon = require('identicon-browserify')

// Asynchronous API
identicon.generate({ id: 'ajido', size: 150, type: 'image/jpeg' }, function(err, uri) {
    if (err) throw err;

    var image = new Image
    image.src = uri // if your canvas implementation supports JPEG creation, then this will likely contain a (data:image/jpeg) header. 
})

// Synchronous API
var uri = identicon.generateSync({ id: 'ajido', size: 40 }) // generates PNG identicon by default

Asynchronous API

.gen

.generate(opts, callback)

{
  opts: Object,
  callback: Function
}

.gen

.generate(id, size, [mimetype], callback)

{
  id: String,
  size: Number,
  mimeType: String,
  callback: Function
}

Synchronous API

.genSync

.generateSync(opts)

{
  opts: Object
}

.genSync

.generateSync(id, size, [mimeType])

{
  id: String,
  size: Number,
  mimeType: String
}

Please note mimeType is always optional. Defaults to PNG format. See the example for more details.

License

(The MIT License)

Copyright (c) 2010-2012 Daiki Kuriyama <dkuriyam@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.