You are here

public static function BackgroundImageCssController::imageStyleUrl in Background Image 8

Same name and namespace in other branches
  1. 2.x src/Controller/BackgroundImageCssController.php \Drupal\background_image\Controller\BackgroundImageCssController::imageStyleUrl()
  2. 2.0.x src/Controller/BackgroundImageCssController.php \Drupal\background_image\Controller\BackgroundImageCssController::imageStyleUrl()

Duplication of _responsive_image_image_style_url().

This is needed so this module does not have to provide a hard dependency on the responsive_image module.

Parameters

string $style_name: The style name to use.

string $path: The path of the image file.

Return value

string The image style URL.

Deprecated

in 8.x-1.4, will be removed in 8.x-2.0. Use \Drupal\background_image\BackgroundImageInterface::getImageUrl() instead.

File

src/Controller/BackgroundImageCssController.php, line 271

Class

BackgroundImageCssController
Defines a controller to serve image styles.

Namespace

Drupal\background_image\Controller

Code

public static function imageStyleUrl($style_name, $path) {
  if ($style_name == '_empty image_') {

    // The smallest data URI for a 1px square transparent GIF image.
    // http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
    return 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
  }
  $entity = ImageStyle::load($style_name);
  if ($entity instanceof ImageStyle) {
    return file_url_transform_relative($entity
      ->buildUrl($path));
  }
  return file_url_transform_relative(file_create_url($path));
}