public static function GdImageAnalysis::mean in Image Effects 8.3
Same name and namespace in other branches
- 8 src/Component/GdImageAnalysis.php \Drupal\image_effects\Component\GdImageAnalysis::mean()
- 8.2 src/Component/GdImageAnalysis.php \Drupal\image_effects\Component\GdImageAnalysis::mean()
Calculates the mean pixel intensity.
Parameters
resource $image: A GD image resource.
Return value
float The mean pixel intensity value.
4 calls to GdImageAnalysis::mean()
- GdImageAnalysisTest::testDifference in tests/
src/ Unit/ GdImageAnalysisTest.php - Verify the difference calculation.
- GdImageAnalysisTest::testMean in tests/
src/ Unit/ GdImageAnalysisTest.php - Verify the mean calculation with a known image.
- ImageEffectsTestBase::assertImagesAreEqual in tests/
src/ Functional/ ImageEffectsTestBase.php - Asserts that two GD images are equal.
- ImageEffectsTestBase::assertImagesAreNotEqual in tests/
src/ Functional/ ImageEffectsTestBase.php - Asserts that two GD images are not equal.
File
- src/
Component/ GdImageAnalysis.php, line 19
Class
- GdImageAnalysis
- Image analysis helper methods for GD.
Namespace
Drupal\image_effects\ComponentCode
public static 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;
}