The code in the example reduces the image colors to 10, then discards all but one pixel of every color and then creates the palettes out of those colors. This might not be the most accurate way to do this, but at least it’s fast 🙂
The code creates three different “palettes” from image; average palette, dark palette and bright palette.
Nice tutorial with well documented code shows how extract color palettes from uploaded images using the Imagick php extension.