Packagist GitLab GitHub Bitbucket Gitea

MonsterID is a method to generate a unique monster image based upon a certain identifier (IP address, email address, whatever). It can be used to automatically provide personal avatar images in blog comments or other community services.

Monster Example

MonsterID was inspired by a post by Don Park and the Combinatoric Critters.


Install it with Composer

composer require sandfoxme/monsterid



Get PNG as a string:


use function SandFox\MonsterID\build_monster;

// output to browser
header('Content-type: image/png');
echo build_monster('', 150);

Put PNG to a stream:


use function SandFox\MonsterID\stream_monster;

// save to file
$stream = fopen('avatar.png', 'w');
stream_monster($stream, '', 150);

Export GD object:


use function SandFox\MonsterID\build_monster_gd;

// convert it to a different format for example
$gd = build_monster_gd('', 150); // a copy of the internal gd object
header('Content-type: image/avif');
imagedestroy($gd); // it's your responsibility to destroy the resource (PHP <= 8.0)



use SandFox\MonsterID\Monster;

$monster = new Monster('', 150);

// output it to browser
header('Content-type: image/png');
echo $monster->getImage();

// save it to file
$monster->writeToStream(fopen('avatar.png', 'w'));

// gd
header('Content-type: image/avif');

Upgrade from 1.x

  • Expect different images to be generated

  • Namespace SandFoxMe\MonsterID is removed, use SandFox\MonsterID

  • Object style changes

    use SandFox\MonsterID\Monster;
    // 1.x
    (new Monster(''))->build(150);
    // 2.x
    (new Monster('', 150))->getImage();
    • Size parameter moved to the constructor

    • build() is now getImage()


All graphics were created by Andreas Gohr. The source code and the graphics are provided under the MIT License.

Adaptation as a composer library for modern PHP was performed by Anton “Sand Fox” Smirnov