研究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.aspphp.online/bianchen/UploadFiles_4619/201701/2017011710210121.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));
下面一個是原圖像,一個是經過處理後的圖像。

