diff --git a/LICENSE b/LICENSE index 4eb750c..a7187a7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016, Stewart Lord +Copyright (c) 2017, Stewart Lord All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/bower.json b/bower.json index 236441c..2922e99 100644 --- a/bower.json +++ b/bower.json @@ -4,12 +4,12 @@ "pnglib.js", "identicon.js" ], - "version": "2.1.1", + "version": "2.2.0", "homepage": "https://github.com/stewartlord/identicon.js", "authors": [ "stewartlord" ], - "description": "GitHub-style identicons in JS with no server-side processing.", + "description": "GitHub-style identicons as PNGs or SVGs in JS.", "moduleType": [ "globals" ], diff --git a/demo.html b/demo.html index 4424e46..9c56a2e 100644 --- a/demo.html +++ b/demo.html @@ -120,23 +120,6 @@

Raw (Smaller)

- -
-
-

Time-based

-

Omit the hash to generate an identicon based on the current time.

-
-  var data = new Identicon().toString();
-  document.write('<img src="data:image/png;base64,' + data + '">');
- -
-
diff --git a/identicon.js b/identicon.js index 77ae0d1..ea306f0 100644 --- a/identicon.js +++ b/identicon.js @@ -1,5 +1,5 @@ /** - * Identicon.js 2.1.1 + * Identicon.js 2.2.0 * http://github.com/stewartlord/identicon.js * * PNGLib required for PNG output @@ -19,9 +19,12 @@ } var Identicon = function(hash, options){ + if (typeof(hash) !== 'string' || hash.length < 15) { + throw 'A hash of at least 15 characters is required.'; + } + this.defaults = { background: [240, 240, 240, 255], - hash: this.createHashFromString((new Date()).toISOString()), margin: 0.08, size: 64, format: 'png' @@ -33,7 +36,7 @@ if (typeof(arguments[1]) === 'number') { this.options.size = arguments[1]; } if (arguments[2]) { this.options.margin = arguments[2]; } - this.hash = hash || this.defaults.hash; + this.hash = hash this.background = this.options.background || this.defaults.background; this.margin = this.options.margin || this.defaults.margin; this.size = this.options.size || this.defaults.size; @@ -128,24 +131,6 @@ } }, - // Creates a consistent-length hash from a string - createHashFromString: function(str){ - var hash = '0', salt = 'identicon', i, chr, len; - - if (!str) { - return hash; - } - - str += salt + str; // Better randomization for short inputs. - - for (i = 0, len = str.length; i < len; i++) { - chr = str.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; - hash |= 0; // Convert to 32bit integer - } - return hash.toString(); - }, - isSvg: function(){ return this.format.match(/svg/i) } diff --git a/package.json b/package.json index 5739394..2b6725f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "identicon.js", - "version": "2.1.1", + "version": "2.2.0", "description": "GitHub-style identicons as PNGs or SVGs in JS.", "main": "identicon.js", "repository": {