You are here

function image_resize_filter_image_tag in Image Resize Filter 8

Same name and namespace in other branches
  1. 6 image_resize_filter.module \image_resize_filter_image_tag()
  2. 7 image_resize_filter.module \image_resize_filter_image_tag()

Generate a themed image tag based on an image array.

Parameters

$image: An array containing image information and properties.

$settings: Settings for the input filter.

1 call to image_resize_filter_image_tag()
FilterImageResize::getImages in src/Plugin/Filter/FilterImageResize.php
Locate all images in a piece of text that need replacing.

File

./image_resize_filter.module, line 322
Contains image_resize_filter.module.

Code

function image_resize_filter_image_tag($image = NULL, $settings = NULL) {
  $src = file_create_url($image['destination']);

  // Strip the http:// from the path if the original did not include it.
  if (!preg_match('/^http[s]?:\\/\\/' . preg_quote($_SERVER['HTTP_HOST']) . '/', $image['original'])) {
    $src = preg_replace('/^http[s]?:\\/\\/' . preg_quote($_SERVER['HTTP_HOST']) . '/', '', $src);
  }

  // Restore any URL query.
  if (isset($image['original_query'])) {
    $src .= '?' . $image['original_query'];
    $image['original'] .= '?' . $image['original_query'];
  }
  $image['attributes']['src'] = $src;
  return '<img' . new Attribute($image['attributes']) . ' />';
}