码迷,mamicode.com
首页 > 其他好文 > 详细

生成用户名默认头像

时间:2019-04-26 14:44:25      阅读:672      评论:0      收藏:0      [点我收藏+]

标签:www.   pre   用户   unp   pac   span   svg   cti   bsp   

 /**
     * 字母头像
     * @param $text
     * @return string
     */
    function letter_avatar($text)
    {
        $total = unpack(‘L‘, hash(‘adler32‘, $text, true))[1];
        $hue = $total % 360;
//        list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);
        list($r, $g, $b) = [43,140,249];

        $bg = "rgb({$r},{$g},{$b})";
        $color = "#ffffff";
        $first = mb_strtoupper(mb_substr($text, -2));
        $src = base64_encode(‘<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="‘ . $bg . ‘" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="40" text-copy="kl" fill="‘ . $color . ‘" text-anchor="middle" text-rights="admin" alignment-baseline="central">‘ . $first . ‘</text></svg>‘);
        $value = ‘data:image/svg+xml;base64,‘ . $src;
        return $value;
    }

 

生成用户名默认头像

标签:www.   pre   用户   unp   pac   span   svg   cti   bsp   

原文地址:https://www.cnblogs.com/zwtqf/p/10774055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!