PHP Classes

How to Use a PHP Avatar Generator to Generate User Profile Avatar Images Using the Package Radiance: Generate avatar images from parameters

Recommend this page to a friend!
     
  Info   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-01-11 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
radiance 1.0.0MIT/X Consortium ...8.2Graphics, PHP 8
Description 

Author

This package can generate avatar images from parameters.

It provides classes that have functions to define several types of parameters that define how the generated avatar image will look like.

Currently, it can:

- Define the avatar text and font, image size, shape, base color, saturation, contrast, pixelated overlay,

- Output image in SVG format

Innovation Award
PHP Programming Innovation award winner
January 2026
Winner
Many sites use picture provided by their users to put in their profiles.

For users that do not provide their pictures, some sites generate avatar images.

This package can generate avatar images from parameters. The generated avatar images may have a gradient shade of colors in the background.

Manuel Lemos
Picture of tomloprod
  Performance   Level  
Name: tomloprod <contact>
Classes: 5 packages by
Country: Spain Spain
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Instructions

Please read this document, to learn how to generate avatar images from parameters.

You can see this package working in the demonstration page.

Details

<div align="center"> <img title="Radiance - Deterministic Avatar Generator" alt="Radiance - Deterministic Avatar Generator" src="./docs/radiance.png" width="600"> <p><b>Beautifully deterministic avatars for PHP</b></p> </div>

<div align="center">

<a href="https://www.php.net/"><img alt="PHP >= 8.2" src="https://img.shields.io/badge/PHP-%E2%89%A5 8.2-777BB4?style=flat-square&logoColor=white&labelColor=111827&color=4f5b93&label=PHP"></a>
<a href="https://packagist.org/packages/tomloprod/radiance"><img alt="Version" src="https://img.shields.io/packagist/v/tomloprod/radiance?style=flat-square&label=version&labelColor=111827&color=white"></a>
<a href="https://github.com/tomloprod/radiance/actions"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/tomloprod/radiance/tests.yml?branch=main&style=flat-square&label=tests&labelColor=111827&color=1a534d"></a>
<a href="https://packagist.org/packages/tomloprod/radiance"><img alt="Downloads" src="https://img.shields.io/packagist/dt/tomloprod/radiance?style=flat-square&label=downloads&labelColor=111827&color=b15356"></a>
<a href="https://packagist.org/packages/tomloprod/radiance"><img alt="License" src="https://img.shields.io/packagist/l/tomloprod/radiance?style=flat-square&label=license&labelColor=111827&color=38543d"></a>

</div>

? About Radiance

Radiance is a modern PHP library designed to generate beautiful, deterministic mesh gradient avatars from any string. Same input always produces the same unique avatar, making it perfect for user profiles, identicons and more.

<div align="center"> <video src="https://github.com/user-attachments/assets/447b9ffd-8ec6-4b37-9e0f-d48c12a86215" width="80%" controls></video> <p>? <a href="https://radiance.tomloprod.dev/" target="_blank">Try the interactive playground</a></p> </div>

? Features

  • ? Deterministic Generation: Same seed, same avatar. Always.
  • ? Mesh Gradients: Smooth, vibrant, and perceptually balanced color transitions.
  • ? Multiple Shapes: Circles, Squircles, and Rectangles.
  • ?? Text Overlay: Add initials or names with automatic font resizing and shadow effects.
  • ? Pixel Patterns: Optional identicon-style pixel overlays with customizable shapes and colors.
  • ? Fluent API: An intuitive and expressive interface.

? Installation

Requires PHP 8.2+.

Install Radiance via Composer:

composer require tomloprod/radiance

? Usage

Basic Usage

Generate a simple avatar from a seed:

$svg = radiance()
    ->seed('tomloprod')
    ->text('TL')
    ->toSvg();

Advanced Customization

Radiance provides a fluent API to fully customize your avatars:

$svg = radiance()
    ->seed('tomloprod')
    ->text('TL')
    ->size(256)
    ->squircle()
    ->baseColor('#3498db')
    ->saturation(1.5)
    ->contrast(1.2)
    ->toSvg();

Pixel Patterns

Add a identicon-like pixelated overlay:

$svg = radiance()
    ->seed('tomloprod')
    ->enablePixelPattern()
    ->pixelGridSize(8)
    ->pixelOpacity(0.4)
    ->pixelDensity(0.5)
    ->pixelShapeCircles()
    ->pixelColorAccent()
    ->toSvg();

Text Controls

Fine-tune how text is displayed:

$svg = radiance()
    ->seed('tomloprod')
    ->text('TL')
    ->fontFamily('Inter')
    ->fontSizeRatio(0.45)
    ->fontSizeRatioAuto(false)
    ->textShadow(0.8)
    ->toSvg();

? API Reference

Base

| Method | Description | Default | | :--- | :--- | :--- | | seed(string $seed) | Set the deterministic seed. | null (random) |

Shape & Size

| Method | Description | Default | | :--- | :--- | :--- | | size(int $size) | Set the dimension in pixels (width/height). | 512 | | circle() | Set the shape to Circle. | - | | square() | Set the shape to Square. | (Square) | | squircle() | Set the shape to Squircle (rounded). | - |

Colors

| Method | Description | Default | | :--- | :--- | :--- | | baseColor(string $color) | Influence the generated palette hue. Accepts hex, rgb, or hsl. | null | | solidColor(string $color) | Use a fixed background instead of gradient. | null |

Gradient Filters

| Method | Description | Default | | :--- | :--- | :--- | | saturation(float $val) | Adjust gradient saturation. 1.0 = original, >1 = vivid, <1 = muted. | 1.0 | | contrast(float $val) | Adjust gradient contrast. 1.0 = original, >1 = higher contrast. | 1.0 | | fadeDistance(int $val) | Control gradient circle size (40-200). Lower = colors more separated. | 50 |

Text Overlay

| Method | Description | Default | | :--- | :--- | :--- | | text(string $text) | Add a centered text overlay. | null | | fontFamily(string $font) | Set the font-family for the text. | monospace | | fontSizeRatio(float $ratio) | Set font size as ratio of avatar size (0.01-1.0). Disables auto-sizing. | 0.5 | | fontSizeRatioAuto(bool $enabled) | Enable/disable automatic font sizing based on text length. | true | | textShadow(float $val) | Set text shadow intensity. 0 = no shadow. | 1.0 |

Pixel Pattern

| Method | Description | Default | | :--- | :--- | :--- | | enablePixelPattern(bool $enable) | Enable/disable the identicon-style overlay. | true | | pixelGridSize(int $size) | Set the pixel grid size (3, 5, 7...). Must be odd for symmetry. | 13 | | pixelOpacity(float $opacity) | Set pixel pattern opacity (0.0-1.0). | 0.3 | | pixelDensity(float $density) | Control how many pixels are drawn (0.0-1.0). | 0.25 | | pixelColorGradient() | Use gradient-derived colors for pixels. | (Gradient) | | pixelColorMonochrome() | Use white color for all pixels. | - | | pixelColorAccent() | Use complementary accent color for pixels. | - | | pixelShapeSquares() | Use square shapes for pixels. | (Squares) | | pixelShapeCircles() | Use circle shapes for pixels. | - | | pixelShapeMix() | Use mixed shapes (deterministic per seed). | - |

Output

| Method | Description | | :--- | :--- | | toSvg() | Get the avatar as an SVG string. | | toBase64() | Get the avatar as a Base64 encoded data URI. |

????? Contributing

Contributions are welcome! Please review the Contributing Guidelines before submitting a pull request.

  1. Fork the project.
  2. Create a new branch (`git checkout -b feature/amazing-feature`).
  3. Commit your changes (`git commit -m 'Add some feature'`).
  4. Push to the branch (`git push origin feature/amazing-feature`).
  5. Open a Pull Request.

? License

Radiance is open-sourced software licensed under the MIT license.

<div align="center">

Created by <b><a href="https://github.com/tomloprod">Tomás López</a></b> ? Powered by <b><a href="https://github.com/tomloprod/colority">Colority</a></b>

</div>


  Radiance playgroundExternal page  

Open in a separate window

  Files folder image Files (31)  
File Role Description
Files folder image.github (1 file, 1 directory)
Files folder imagedocs (1 file)
Files folder imagesrc (4 directories)
Files folder imagetests (1 file, 2 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpstan.neon.dist Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file pint.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file rector.php Example Example script

  Files folder image Files (31)  /  .github  
File Role Description
Files folder imageworkflows (2 files)
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data

  Files folder image Files (31)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file formats.yml Data Auxiliary data
  Accessible without login Plain text file tests.yml Data Auxiliary data

  Files folder image Files (31)  /  docs  
File Role Description
  Accessible without login Image file radiance.png Icon Icon image

  Files folder image Files (31)  /  src  
File Role Description
Files folder imageConcerns (6 files)
Files folder imageEnums (5 files)
Files folder imageServices (1 file)
Files folder imageSupport (1 file, 1 directory)

  Files folder image Files (31)  /  src  /  Concerns  
File Role Description
  Plain text file ConfiguresColors.php Class Class source
  Plain text file ConfiguresFilters.php Class Class source
  Plain text file ConfiguresPixelPattern.php Class Class source
  Plain text file ConfiguresShape.php Class Class source
  Plain text file ConfiguresText.php Class Class source
  Plain text file GeneratesPixelPattern.php Class Class source

  Files folder image Files (31)  /  src  /  Enums  
File Role Description
  Accessible without login Plain text file AvatarShape.php Aux. Configuration script
  Accessible without login Plain text file EasterEgg.php Example Example script
  Accessible without login Plain text file GradientZone.php Aux. Configuration script
  Accessible without login Plain text file PixelColorMode.php Aux. Configuration script
  Accessible without login Plain text file PixelShape.php Aux. Configuration script

  Files folder image Files (31)  /  src  /  Services  
File Role Description
  Plain text file RadianceManager.php Class Class source

  Files folder image Files (31)  /  src  /  Support  
File Role Description
Files folder imageFacades (1 file)
  Accessible without login Plain text file RadianceAlias.php Aux. Configuration script

  Files folder image Files (31)  /  src  /  Support  /  Facades  
File Role Description
  Plain text file Radiance.php Class Class source

  Files folder image Files (31)  /  tests  
File Role Description
Files folder imageServices (1 file)
Files folder imageSupport (1 file, 1 directory)
  Accessible without login Plain text file ArchTest.php Example Example script

  Files folder image Files (31)  /  tests  /  Services  
File Role Description
  Plain text file RadianceManagerTest.php Class Class source

  Files folder image Files (31)  /  tests  /  Support  
File Role Description
Files folder imageFacades (1 file)
  Plain text file RadianceAliasTest.php Class Class source

  Files folder image Files (31)  /  tests  /  Support  /  Facades  
File Role Description
  Accessible without login Plain text file RadianceTest.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0