<?php
$colors = [];
$img = function(Callable $rand) use ($colors) {
$height = 200;
$width = 200;
$r = imagecreatetruecolor($width, $height);
foreach (range(0, $height) as $y) {
foreach (range(0, $width) as $x) {
$c = $rand();
if (!array_key_exists($c, $colors)) {
$colors[$c] = imagecolorallocate($r, $c, $c, $c);
}
imagesetpixel($r, $x, $y, $colors[$c]);
}
}
ob_start();
imagepng($r);
$img = base64_encode(ob_get_contents());
ob_clean();
return '<img src="data:image/png;base64,' . $img . '">';
};
$rand = function() {
// time as seed
srand((float) microtime() * 100);
return rand(0, 255);
};
// no so random
echo $img($rand);