function ResponsiveImageBuilder::getImageStyleUrl
Returns the given image style URL.
Explicitly supports the special empty image as aa data: URL.
Parameters
string $style_name: Name of the image style.
string $path: The path or URI to the original image.
Return value
string The image style URL.
File
-
core/
modules/ responsive_image/ src/ ResponsiveImageBuilder.php, line 330
Class
- ResponsiveImageBuilder
- Provides methods related to building responsive image source attributes.
Namespace
Drupal\responsive_imageCode
public function getImageStyleUrl(string $style_name, string $path) : string {
if ($style_name == ResponsiveImageStyleInterface::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 $this->fileUrlGenerator
->transformRelative($entity->buildUrl($path));
}
return $this->fileUrlGenerator
->generateString($path);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.