How to generate gmail avatars by PHP?

--

Have you ever challenged the task to generate default avatars similar as gmail does? If yes, then I could guess that you used some HTML/CSS/JS solution.

In this article I would like to tell how to generate gmail avatars (or other avatars) with PHP. So, just a back-end solution!

At first! You don’t need to create your own bicycle!
The one is created already, please check this composer package:

gmail-logo/generator”.

This package allows you to generate images like this:

To install the package run this:

composer require gmail-logo/generator

To generate gmail avatars you may do things like this:

$avatar = new Generator('Abby', [75, 175], Font::ROBOTO_REGULAR);

return $avatar
->setSizes(300,300)
->setBackgroundColor(150, 150, 100)
->setTextColor(0,0,0)
->setTextSize(250)
->png()
->html();

The documentation is here:
https://logo-generator.online/

Relevant links:
https://github.com/OleksiiFedorchak/GmailLogo
https://packagist.org/packages/gmail-logo/generator

--

--

Alexey Fedorchak
Alexey Fedorchak

Written by Alexey Fedorchak

Hi! I’m expert certified Laravel/PHP developer.

No responses yet