Skip to content

Instantly share code, notes, and snippets.

@jscheel
Created August 4, 2011 05:28
Show Gist options
  • Save jscheel/1124556 to your computer and use it in GitHub Desktop.
Save jscheel/1124556 to your computer and use it in GitHub Desktop.
List all colors in css file
<?php
//needs to be expanded to include #fff and also needs to be more robust, but it's a start
$colorsString = shell_exec("grep -o -h '#......;' ./style.css | tr [A-Z] [a-z] | sort | uniq");
$colors = array_filter(explode("\n", str_replace(array('#', ';'), '', $colorsString)));
header("Content-Type: image/png");
$im = @imagecreate(210, 20 * count($colors))
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
$allocatedColors = array();
foreach ($colors as $idx => $color) {
$allocatedColors[$color] = imagecolorallocate($im, hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
imagefilledrectangle($im, 0, $idx * 20, 110, ($idx * 20) + 20, $allocatedColors[$color]);
imagestring($im, 2, 115, ($idx * 20) + 2, "#$color;", $text_color);
}
//$text_color = imagecolorallocate($im, 233, 14, 91);
//imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment