產生頭像(沒事寫著玩的)

來源:互聯網
上載者:User
<?php/** * Author:  Seven Yu * E-Mail:  dofyyu (at) gmail.com * Version: 0.0.3 * Update:  2012/11/14  */$rand = true;$cache = true;$time = $rand ? time() : 0;$name = isset($_GET['name']) ? trim($_GET['name']) : $time;$name = empty($name) ? $time : $name;$code = isset($_GET['code']) ? $_GET['code'] : md5($name);if(preg_match('/^[0-9a-f]{32}$/i', $code) == 0){    $code = md5($time);}$assets = array(    array('name' => 'bg',    'count' => 30),    array('name' => 'face',  'count' => 10),    array('name' => 'eye',   'count' => 11),    array('name' => 'nose',  'count' => 10),    array('name' => 'mouth', 'count' => 10),    array('name' => 'hair',  'count' => 5),);$folder1 = substr($code, 0, 2);$folder2 = substr($code, 2, 2);$folder = "cache/$folder1/$folder2";$file = "$folder/$code.png";if(!$cache || !file_exists($file)){    // make image    $i = 0;    $parts = str_split($code, 5);    $im = imagecreatetruecolor(64, 64);    foreach($assets as $item)    {        $name = $item['name'];        $index = getWordOrd($parts[$i++]) % $item['count'];        $img = "assets/$name/$index.png";        if(file_exists($img))        {            $add = imagecreatefrompng($img);            imagecopy($im, $add, 0, 0, 0, 0, 64, 64);        }    }    if($cache)    {        if(!file_exists($folder))        {            mkdir($folder, 0777, true);        }        imagepng($im, $file);    }    else    {        header('Content-Type: image/png');        imagepng($im);    }    imagedestroy($im);}$cache && header("location:$file");/** * 單詞 ascii 碼和 * @param $word 字串 * @return 求和 * */function getWordOrd($word){    $result = 0;    foreach(str_split($word) as $char)    {        $result += ord($char);    }    return $result;}?>

可以在這裡預覽,素材隨便畫的 ╮( ̄▽ ̄")╭ 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.