/**
  * Shows a monster id avatar.
  *
  * @param array eventdata the data given by the event
  *
  * @return boolean true, if Avatar was found and added to the comment buffer
  */
 function fetchMonster(&$eventData)
 {
     require_once dirname(__FILE__) . '/monsterid/monsterid.php';
     $seed = md5($eventData['author']) . $eventData['email_md5'] . md5($eventData['url']);
     $default = $this->getDefaultImageConfiguration();
     $size = $default['size'];
     // Save monster image
     @mkdir($this->getCacheDirectory());
     $cache_file = $this->getCacheFilePath($eventData);
     $this->log("Caching monster avatar: " . $cache_file);
     if (build_monster($cache_file, $seed, $size)) {
         $this->log("Success caching monster.");
         $this->avatarConfiguration['mime-type'] = "image/png";
         $this->show($cache_file);
     } else {
         if ($this->supportDefaultAvatar()) {
             $this->fetchDefault();
         }
     }
     return true;
 }
<?php

/**
 * @license   GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author    Andreas Gohr <*****@*****.**>
 */
build_monster($_REQUEST['seed'], $_REQUEST['size']);
/**
 * Generates a monster for the given seed
 * GDlib is required!
 */
function build_monster($seed = '', $size = '')
{
    // create 16 byte hash from seed
    $hash = md5($seed);
    // calculate part values from seed
    $parts = array('legs' => _get_monster_part(substr($hash, 0, 2), 1, 5), 'hair' => _get_monster_part(substr($hash, 2, 2), 1, 5), 'arms' => _get_monster_part(substr($hash, 4, 2), 1, 5), 'body' => _get_monster_part(substr($hash, 6, 2), 1, 15), 'eyes' => _get_monster_part(substr($hash, 8, 2), 1, 15), 'mouth' => _get_monster_part(substr($hash, 10, 2), 1, 10));
    // create background
    $monster = @imagecreatetruecolor(120, 120) or die("GD image create failed");
    $white = imagecolorallocate($monster, 255, 255, 255);
    imagefill($monster, 0, 0, $white);
    // add parts
    foreach ($parts as $part => $num) {
        $file = dirname(__FILE__) . '/parts/' . $part . '_' . $num . '.png';
        $im = @imagecreatefrompng($file);
        if (!$im) {
            die('Failed to load ' . $file);
        }
        imageSaveAlpha($im, true);
        imagecopy($monster, $im, 0, 0, 0, 0, 120, 120);
        imagedestroy($im);