protected function BackgroundImageManager::colorSampleGdImage in Background Image 8
Same name and namespace in other branches
- 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::colorSampleGdImage()
- 2.0.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::colorSampleGdImage()
Determines the average color of an image using the GD toolkit.
Parameters
\Drupal\system\Plugin\ImageToolkit\GDToolkit $image: A GD image toolkit object.
string $default: A default lowercase simple color (HEX) representation to use if unable to sample the image.
Return value
string An associative array with red, green, blue and alpha keys that contains the appropriate values for the specified color index.
1 call to BackgroundImageManager::colorSampleGdImage()
- BackgroundImageManager::colorSampleImage in src/
BackgroundImageManager.php - Samples the average color of an image file.
File
- src/
BackgroundImageManager.php, line 270
Class
Namespace
Drupal\background_imageCode
protected function colorSampleGdImage(GDToolkit $image, $default = NULL) {
if ($image
->apply('resize', [
'width' => 1,
'height' => 1,
]) && ($resource = $image
->getResource())) {
return @Color::rgbToHex(array_slice(@imagecolorsforindex($resource, @imagecolorat($resource, 0, 0)), 0, 3)) ?: $default;
}
return $default;
}