View Full Version : Return RGB from Selected Area

11-12-2007, 10:18 PM
Hi! Using PHP 5, can an a section of an image be selected, and return the RGB values of 3 of most most average colours, contained in the selected area of the image?

11-12-2007, 10:26 PM
It's possible, but it won't be very easy. This would be the general idea:
Load the image into an image pointer,
Copy the section you want to another pointer,
Loop through the pixels using imagecolorat() (http://php.net/imagecolorat) to read each pixel and add it to an array of counters,
Sort the array, etc.

There's a code snippet that might be helpful here (http://php.net/manual/en/function.imagecolorat.php#70783).

11-12-2007, 10:31 PM
Ah ha Cheers!