function SmartcropTestCase::mean in Smart Crop 6
Same name and namespace in other branches
- 7 tests/smartcrop.test \SmartcropTestCase::mean()
Calculate the mean pixel intensity.
Parameters
$image GD image resource.:
Return value
The mean.
2 calls to SmartcropTestCase::mean()
- SmartcropTestCase::assertImageEqual in tests/
smartcrop.test - Assert that two images are the same, with some difference allowed to account for e.g. compression artifacts.
- SmartcropTestCase::assertImageNotEqual in tests/
smartcrop.test - Assert that two images are not the same, with some difference allowed to account for e.g. compression artifacts.
File
- tests/
smartcrop.test, line 211 - Tests for the smartcrop module.
Class
- SmartcropTestCase
- @file Tests for the smartcrop module.
Code
function mean($image) {
$mean = 0;
$size = imagesx($image) * imagesy($image) * 3;
for ($i = 0; $i < imagesx($image); $i++) {
for ($j = 0; $j < imagesy($image); $j++) {
$rgb = imagecolorat($image, $i, $j);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$mean += $r / $size;
$mean += $g / $size;
$mean += $b / $size;
}
}
return $mean;
}