How to Extract Letters from user names and convert it to profile image in ionic

I am trying to extract first letter from the user first name and the last name and use it as their default profile image .

I know how to extract the first letters like this

var first = “First Name”;
var last = “Last Name”;
var res = first.charAt(0) + last.charAt(0);

I will like to convert he result into random colourful profile image like we have here on ionic forum in my ionic app

any help will be appreciated