xionfoo Posted May 22, 2008 Share Posted May 22, 2008 So I've been through all the php.net image functions and tried to figure out how to write a script that'll pull common colors out from an image and output a color palette. I tried googling this but all I get is search results showing scripts that are doing this not explaining how to. So if anyone can point me in the right direction on how to create a php script that'll generate an accurate color palette from an image, that would be awesome! Here's something that I've been trying to figure out too. This website pulls the main image colors (palette) and applys that towards the css styles: http://monotonedemo.wordpress.com/ Here's one that generates related colors (Another question would be, how would I go about doing this?) http://www.degraeve.com/reference/color.php Here's another similar one: http://www.gpeters.com/color/color-schemes.php I know these aren't all specifically the same thing, but they all seem somewhat similar so I'm assuming if I learn one, it wouldn't be that much harder to create the others. Thanks Link to comment https://forums.phpfreaks.com/topic/106713-how-to-get-color-palette-from-images-using-php/ Share on other sites More sharing options...
Barand Posted May 22, 2008 Share Posted May 22, 2008 is this what you mean <?php $im = imagecreatefrompng('filename.png'); $colors = array(); for ($x=0, $w = imagesx($im); $x < $w; $x++) { for ($y=0, $h = imagesy($im); $y < $h; $y++) { $c = imagecolorat($im, $x, $y); $a = imagecolorsforindex($im, $c); $colors[vsprintf('%02X%02X%02X', $a)] = $c; } } asort ($colors, SORT_NUMERIC); echo "<table>\n"; foreach ($colors as $col=>$v) { echo "<tr><td style='background-color:#$col; width:50px'> </td><td>$col</td><td>$v</td></tr>\n"; } echo "</table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/106713-how-to-get-color-palette-from-images-using-php/#findComment-547140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.