/ Published in: PHP
This gives you an array whose values are higher for how often that color has been used.
Expand |
Embed | Plain Text
<?php function colorPalette($imageFile, $numColors, $granularity = 5) { if($size === false) { return false; } $img = @imagecreatefromjpeg($imageFile); if(!$img) { return false; } for($x = 0; $x < $size[0]; $x += $granularity) { for($y = 0; $y < $size[1]; $y += $granularity) { $thisColor = imagecolorat($img, $x, $y); $rgb = imagecolorsforindex($img, $thisColor); { $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"; ?>
You need to login to post a comment.
