本文整理匯總了PHP中Imagine\Image\ImageInterface::histogram方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageInterface::histogram方法的具體用法?PHP ImageInterface::histogram怎麽用?PHP ImageInterface::histogram使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagine\Image\ImageInterface
的用法示例。
在下文中一共展示了ImageInterface::histogram方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: normalize
/**
* @param Imagine\Image\ImageInterface $image
*
* @return array
*/
private function normalize(ImageInterface $image)
{
$step = (int) round(255 / $this->buckets);
$red = $green = $blue = $alpha = array();
for ($i = 1; $i <= $this->buckets; $i++) {
$range = new Range(($i - 1) * $step, $i * $step);
$red[] = new Bucket($range);
$green[] = new Bucket($range);
$blue[] = new Bucket($range);
$alpha[] = new Bucket($range);
}
foreach ($image->histogram() as $color) {
foreach ($red as $bucket) {
$bucket->add($color->getRed());
}
foreach ($green as $bucket) {
$bucket->add($color->getGreen());
}
foreach ($blue as $bucket) {
$bucket->add($color->getBlue());
}
foreach ($alpha as $bucket) {
$bucket->add($color->getAlpha());
}
}
$total = $image->getSize()->square();
$callback = function (Bucket $bucket) use($total) {
return count($bucket) / $total;
};
return array(array_map($callback, $red), array_map($callback, $green), array_map($callback, $blue), array_map($callback, $alpha));
}