RosettaCodeData/Task/Colour-bars-Display/PHP/colour-bars-display-1.php

26 lines
884 B
PHP
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
<?php
2015-11-18 06:14:39 +00:00
$colors = array(array( 0, 0, 0), // black
2013-04-10 16:57:12 -07:00
array(255, 0, 0), // red
array( 0, 255, 0), // green
array( 0, 0, 255), // blue
array(255, 0, 255), // magenta
array( 0, 255, 255), // cyan
2015-11-18 06:14:39 +00:00
array(255, 255, 0), // yellow
array(255, 255, 255)); // white
2013-04-10 16:57:12 -07:00
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);