You are here

function fft_field_styled_image_url in Field Formatter Template 8

Same name and namespace in other branches
  1. 8.2 fft.module \fft_field_styled_image_url()
  2. 7 fft.module \fft_field_styled_image_url()

Get image url with style name.

Parameters

object $image: Image uri.

string $style: Image style name.

Return value

array Return image url.

1 call to fft_field_styled_image_url()
fft_field_formatter_render in ./fft.module
Render field formatter.

File

./fft.module, line 226
Field formatter template.

Code

function fft_field_styled_image_url($image, $style) {
  $image_info = [];
  $style = ImageStyle::load($style);
  $image_uri = $image->entity
    ->getFileUri();
  $image_filepath = $style
    ->buildUri($image_uri);
  $style
    ->createDerivative($image_uri, $image_filepath);
  $image_info['path'] = file_create_url($image_filepath);

  // Determine the dimensions of the styled image.
  $dimensions = [
    'width' => $image->width,
    'height' => $image->height,
  ];
  $style
    ->transformDimensions($dimensions, $image_uri);
  $image_info['width'] = $dimensions['width'];
  $image_info['height'] = $dimensions['height'];
  return $image_info;
}