/ Published in: PHP

This gives you an array whose values are higher for how often that color has been used.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function colorPalette($imageFile, $numColors, $granularity = 5) { if($size === false) { return false; } if(!$img) { return false; } for($x = 0; $x < $size[0]; $x += $granularity) { for($y = 0; $y < $size[1]; $y += $granularity) { { $colors[$thisRGB]++; } else { $colors[$thisRGB] = 1; } } } } // sample usage: $palette = colorPalette('rmnp8.jpg', 10, 4); echo "<table>\n"; foreach($palette as $color) { echo "<tr><td style='background-color:#$color;width:2em;'> </td><td>#$color</td></tr>\n"; } echo "</table>\n"; ?>
Comments
