Here is the code snippet for generating an image using JavaScript
var colors = ["#1abc9c", "#2ecc71", "#3498db", "#9b59b6", "#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50", "#f1c40f", "#e67e22", "#e74c3c", "#95a5a6", "#f39c12", "#d35400", "#c0392b", "#bdc3c7", "#7f8c8d"];
var name = "John Doe",
nameSplit = name.split(" "),
initials = nameSplit[0].charAt(0).toUpperCase() + nameSplit[1].charAt(0).toUpperCase();
var charIndex = initials.charCodeAt(0) - 65,
colorIndex = charIndex % 19;
var canvas = document.createElement('canvas');
canvas.width = '32';
canvas.height = '32';
var context = canvas.getContext("2d");
context.fillStyle = colors[colorIndex];
context.fillRect (0, 0, canvas.width, canvas.height);
context.font = "16px Arial";
context.textAlign = "center";
context.fillStyle = "#FFF";
context.fillText(initials,16,22);
var dataUrl = canvas.toDataURL();
return dataUrl;