Codice PHP:
<?php
header("Content-Type: image/png");
$points = [];
$size = 5000;
$npoints = 500000;
// Generates points (or read them from database)
for ($i = 0; $i < $npoints; $i++) {
$points[$i] = ['x' => round(rand(0, $size)), 'y' => round(rand(0, $size)), 'c' => round(rand(0, 9))];
}
// Creates image and allocates colors
$img = imagecreate($size, $size);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
$colors = [
imagecolorallocate($img, 255, 0, 0),
imagecolorallocate($img, 0, 255, 0),
imagecolorallocate($img, 0, 0, 255),
imagecolorallocate($img, 255, 255, 0),
imagecolorallocate($img, 0, 255, 255),
imagecolorallocate($img, 255, 0, 255),
imagecolorallocate($img, 255, 255, 255),
imagecolorallocate($img, 0, 0, 0),
imagecolorallocate($img, 128, 128, 128),
imagecolorallocate($img, 64, 64, 64)
];
// Draw points
foreach ($points as $point) {
imagesetpixel($img, $point['x'], $point['y'], $colors[$point['c']]);
}
// Outputs image
imagepng($img);
imagedestroy($img);
?>
Sicuro che il collo di bottiglia sia nella creazione dell'immagine piuttosto che nella lettura dal database?