lvl0
<?php
if (!isset($_SERVER['argv'][1])) {
die($_SERVER['argv'][0] . '<file>');
}
$file = $_SERVER['argv'][1];
$i = imagecreatefrompng($file);
$width = imagesx($i);
$height = imagesy($i);
$colors = array();
$cc = imagecolorallocate($i, 0xff, 0x00, 0x00);
$cd = imagecolorallocate($i, 0xff, 0xff, 0x00);
for ($k = 0; $k < $width; $k++) {
for ($l = 0; $l < $height; $l++) {
$color = imagecolorat($i, $k, $l);
if ($color == 0x0) {
imagesetpixel($i, $k, $l, $cc);
}
if (($color & 0xff00 == 0xff00)
&& $color != 0x4aff93) {
imagesetpixel($i, $k, $l, $cc);
}
$color = dechex($color);
if (array_key_exists($color, $colors)) {
$colors[$color]++;
} else {
$colors[$color] = 1;
}
}
}
imagepng($i, 'out.png');
asort($colors);
foreach ($colors as $color => $hits) {
echo sprintf('%s %s' . PHP_EOL, $color, $hits);
}