filling-factory/fill.php

<?php header('Content-type: image/png');

// Supplement user parameters with defaults
$p = $_GET + array
(
	'r' => 0,
	'g' => 0,
	'b' => 0,
	'a' => 0,
);


// Make sure they are within limits (colors: 0-255, alpha: 0-127)
function fix(&$val, $key)
{
	$val = min(max(0, (int) $val), $key == 'a' ? 127 : 255); 
}
array_walk($p, 'fix');
	

// Create image
$img = @imagecreatetruecolor(15, 15)
	or die('Cannot Initialize new GD image stream');

imagesavealpha($img, true);


// Fill image
$color = imagecolorallocatealpha($img, 
	$p['r'], 
	$p['g'], 
	$p['b'], 
	$p['a']);
imagefill($img, 0, 0, $color);


// Output result
imagepng($img, null, 9);
imagedestroy($img);