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 = 'https://www.2cto.com/uploadfile/Collfiles/20140820/20140820085933239.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));

下面一個是原圖像,一個是經過處理後的圖像。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *