Many image sites will be based on the user uploaded pictures to retrieve the main color value of the picture, and then search through the color related pictures.
Before the online method to zoom (or mosaic) and then iterate over each pixel, and then the statistics at the highest number of RGB, this approach is too inefficient and the RGB value taken is not accurate. It was later found that using Imagick's Quantizeimage method was a convenient way to get the average RGB value in the picture.
$average = new Imagick ("xiaocai.jpg");
$average->quantizeimage (Imagick::colorspace_rgb, 0, False, false);
$average->uniqueimagecolors ();
function Getimagescolor (Imagick $im) {
$colorarr = array ();
$it = $im->getpixeliterator ();
$it->resetiterator ();
while ($row = $it->getnextiteratorrow ()) {
foreach ($row as $pixel) {
//www.jb51.net
$colorarr [] = $pixe L->getcolor ();
}
return $colorarr;
}
$colorarr = Getimagescolor ($average);
foreach ($colorarr as $val) {
echo ' <div style= ' Background-color:rgb ({$val [' R ']},{$val [' G ']},{$val [' B ']}); Width:50px;height:50px;float:left; ' ></div> ";
}