You are here

public function BackgroundImageManager::colorSampleImage in Background Image 2.0.x

Same name and namespace in other branches
  1. 8 src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::colorSampleImage()
  2. 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::colorSampleImage()

Samples the average color of an image file.

Parameters

\Drupal\Core\Image\ImageInterface $image: An Image object.

string $default: The default lowercase simple color (HEX) representation to use if unable to sample the image.

Return value

string The lowercase simple color (HEX) representation of the sampled image.

Overrides BackgroundImageManagerInterface::colorSampleImage

1 call to BackgroundImageManager::colorSampleImage()
BackgroundImageManager::colorSampleFile in src/BackgroundImageManager.php
Samples the average color of an image file.

File

src/BackgroundImageManager.php, line 247

Class

BackgroundImageManager

Namespace

Drupal\background_image

Code

public function colorSampleImage(ImageInterface $image, $default = NULL) {

  // Immediately return if the image is not valid.
  if (!$image
    ->isValid()) {
    return $default;
  }

  // Retrieve the toolkit and use it, if valid.
  $toolkit = $image
    ->getToolkit();
  if ($toolkit instanceof GDToolkit) {
    return $this
      ->colorSampleGdImage($toolkit, $default);
  }
  else {
    if ($toolkit instanceof ImagemagickToolkit) {
      return $this
        ->colorSampleImagemagickImage($toolkit, $default);
    }
  }
  return $default;
}