Radiance is a PHP library by Tomás López that generates unique, deterministic mesh gradient avatars from any input string. Given the same seed, the library produces identical avatars every time, making it a practical choice for user profiles, identicons, and placeholder images.
The library requires PHP 8.2 or higher and can be installed via Composer:
composer require tomloprod/radiance
At its core, Radiance uses a fluent API for configuration. Here's a basic example that generates an SVG avatar:
radiance() ->seed('ericlbarnes') ->text('EB') ->baseColor('#f9332b') ->toSvg();
You can chain additional methods to customize the avatar's appearance:
radiance() ->seed('predmond@example.com') ->text('PR') ->size(128) ->baseColor('#f9332b') ->squircle() ->saturation(1.6) ->textShadow(2) ->toBase64();
The package offers multiple shape options, including circles, squircles (rounded squares), and squares. You can customize the output with text overlays that include automatic font resizing and shadow effects.
Radiance includes several configuration options for fine-tuning your avatars:
- Shape and Size: Control dimensions and choose between
circle(),square(), orsquircle() - Colors: Set a
baseColor()or usesolidColor()for non-gradient outputs - Filters: Adjust
saturation(),contrast(), andfadeDistance() - Text: Customize with
fontFamily(),fontSizeRatio(), andtextShadow() - Pixel Patterns: Add identicon-style overlays with
pixelGridSize(),pixelOpacity(),pixelDensity(), and shape options
For output, the library supports both SVG generation via toSvg() and Base64 encoding with toBase64().
Radiance is built on top of Colority, another library by the same author for color manipulation.
You can explore the library with an interactive playground at radiance.tomloprod.dev and view the source code on GitHub.