Trevor Reimer
Trevor Reimer

Reputation: 304

Material Letter Icons for PHP

I know that this is a generally broad question but I have been looking all afternoon and have yet to find a php library that works for my needs. What I want is a simple class that I can pass in a Name or Character and it'll generate one of those Material Like design Letter Icons with a random colour in the background. I would prefer the icon in png or jpeg format.

Something like this just for php would be perfect https://github.com/eladnava/material-letter-icons

Material Icon from js Library

Upvotes: 1

Views: 649

Answers (1)

Ali
Ali

Reputation: 107

You can simply use html, css for a span. Use an array of colors in PHP and then choose one color from it randomly. CSS can make a span look like a circle. Add extra css as per your like.

<?php
function letterIcon($char) {
   $colors = ['red', 'green', 'blue', 'orange'];

   $color = $colors[rand(0, count($colors) - 1)];

   return "<span style=\"background-color:{$color}; border-radius: 50%; height:200px; width:200px; padding:20px;\">{$char}</span>";
}
echo letterIcon('A');
?>

Upvotes: 1

Related Questions