function _smartcrop_gd_histogram in Smart Crop 6
Same name and namespace in other branches
- 7 image.gd.inc \_smartcrop_gd_histogram()
Compute a histogram of an image.
Parameters
resource $img GD image resource.:
Return value
array histogram as an array.
1 call to _smartcrop_gd_histogram()
- _smartcrop_gd_entropy in ./
imageapi_gd.inc - Compute the entropy of an image, defined as -sum(p.*log2(p)).
File
- ./
imageapi_gd.inc, line 148 - libgd implementation of smartcrop action.
Code
function _smartcrop_gd_histogram($img) {
$histogram = array_fill(0, 768, 0);
for ($i = 0; $i < imagesx($img); $i++) {
for ($j = 0; $j < imagesy($img); $j++) {
$rgb = imagecolorat($img, $i, $j);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$histogram[$r]++;
$histogram[$g + 256]++;
$histogram[$b + 512]++;
}
}
return $histogram;
}