<?php
$colors = array(array(  0,   0,   0),   
                array(255,   0,   0),   
                array(  0, 255,   0),   
                array(  0,   0, 255),   
                array(255,   0, 255),   
                array(  0, 255, 255),   
                array(255, 255,   0),   
                array(255, 255, 255));  

define('BARWIDTH', 640 / count($colors));
define('HEIGHT',   480);

$image = imagecreate(BARWIDTH * count($colors), HEIGHT);

foreach ($colors as $position => $color) {
    $color = imagecolorallocate($image, $color[0], $color[1], $color[2]);
    imagefilledrectangle($image, $position * BARWIDTH, 0,
                         $position * BARWIDTH + BARWIDTH - 1,
                         HEIGHT - 1, $color);
}

header('Content-type:image/png');
imagepng($image);
imagedestroy($image);