码迷,mamicode.com
首页 > Web开发 > 详细

php 有趣的头像拼图

时间:2014-08-20 00:06:25      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   for   ar   2014   

研究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 = 'http://upload.wikimedia.org/wikipedia/commons/b/be/Manga_Icon.png';
$text = 'I-dont-like-manga-...-Why-do-they-have-such-big-eyes? Strange-...-WHAT-WANT-YOU-DO?';

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

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



bubuko.com,布布扣

bubuko.com,布布扣


bubuko.com,布布扣bubuko.com,布布扣

bubuko.com,布布扣


php 有趣的头像拼图,布布扣,bubuko.com

php 有趣的头像拼图

标签:style   blog   http   color   io   for   ar   2014   

原文地址:http://blog.csdn.net/fujiafeihudui/article/details/38690659

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