Maison  >  Article  >  développement back-end  >  php 有趣的头像拼图_PHP教程

php 有趣的头像拼图_PHP教程

WBOY
WBOYoriginal
2016-07-13 10:19:491045parcourir

php 有趣的头像拼图

研究php的GD库的时候,发现了一段他人写的代码,这里给出来希望增加大家对php的热情。这段代码对人物头像进行了代码的马赛克,看起来很有趣。


function pixelfuck($url, $chars='ewk34543§G§$§$Tg34g4g', $shrpns=1, $size=4,$weight=2)
{
    list($w, $h, $type) = getimagesize($url);
    $resource = imagecreatefromstring(file_get_contents($url));
    $img = imagecreatetruecolor($w*$size,$h*$size);

    $cc = strlen($chars);
    for($y=0;$y <$h;$y+=$shrpns) 
        for($x=0;$x <$w;$x+=$shrpns)
            imagestring($img,$weight,$x*$size,$y*$size, $chars{@++$p%$cc}, imagecolorat($resource, $x, $y));
    return $img;
}

$url = &#39;http://www.bkjia.com/uploads/allimg/140830/0421361239-0.png&#39;;
$text = &#39;I-dont-like-manga-...-Why-do-they-have-such-big-eyes? Strange-...-WHAT-WANT-YOU-DO?&#39;;

Header(&#39;Content-Type: image/png&#39;);
imagepng(pixelfuck($url, $text, 1, 6));

下面一个是原图像,一个是经过处理后的图像。



\

\


\\



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/871192.htmlTechArticlephp 有趣的头像拼图 研究php的GD库的时候,发现了一段他人写的代码,这里给出来希望增加大家对php的热情。这段代码对人物头像进行了代码...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn