本文整理汇总了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));
}