You are here

public function TwigExtension::imageStyle in Twig Tweak 8

Same name and namespace in other branches
  1. 8.2 src/TwigExtension.php \Drupal\twig_tweak\TwigExtension::imageStyle()

Returns the URL of this image derivative for an original image path or URI.

Parameters

string $path: The path or URI to the original image.

string $style: The image style.

Return value

string The absolute URL where a style image can be downloaded, suitable for use in an <img> tag. Requesting the URL will cause the image to be created.

File

src/TwigExtension.php, line 440

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function imageStyle($path, $style) {

  /** @var \Drupal\Image\ImageStyleInterface $image_style */
  if ($image_style = ImageStyle::load($style)) {
    return file_url_transform_relative($image_style
      ->buildUrl($path));
  }
}