function theme_image_style

Returns HTML for an image using a specific image style.

Parameters

$variables: An associative array containing:

  • style_name: The name of the style to be used to alter the original image.
  • uri: The path of the image file relative to the Drupal files directory. This function does not work with images outside the files directory nor with remotely hosted images. This should be in a format such as 'images/image.jpg', or using a stream wrapper such as 'public://images/image.jpg'.
  • width: The width of the source image (if known).
  • height: The height of the source image (if known).
  • alt: The alternative text for text-based browsers.
  • title: The title text is displayed when the image is hovered in some popular browsers.
  • attributes: Associative array of attributes to be placed in the img tag.

Related topics

1 call to theme_image_style()
ImageDimensionsTest::testImageDimensions in drupal/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
Test styled image dimensions cumulatively.
7 theme calls to theme_image_style()
ImageFieldDisplayTest::testImageFieldSettings in drupal/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
Tests for image field settings.
ImageFieldDisplayTest::_testImageFieldFormatters in drupal/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
Test image formatters on node display.
ImageThemeFunctionTest::testImageStyleTheme in drupal/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
Tests usage of the image style theme function.
image_field_widget_process in drupal/core/modules/image/image.field.inc
An element #process callback for the image_image field type.
PictureFieldDisplayTest::_testPictureFieldFormatters in drupal/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php
Test picture formatters on node display.

... See full list

File

drupal/core/modules/image/image.module, line 1010
Exposes global functionality for creating image styles.

Code

function theme_image_style($variables) {

  // Determine the dimensions of the styled image.
  $dimensions = array(
    'width' => $variables['width'],
    'height' => $variables['height'],
  );
  image_style_transform_dimensions($variables['style_name'], $dimensions);
  $variables['width'] = $dimensions['width'];
  $variables['height'] = $dimensions['height'];

  // Add in the image style name as an HTML class.
  $variables['attributes']['class'][] = 'image-style-' . drupal_html_class($variables['style_name']);

  // Determine the URL for the styled image.
  $variables['uri'] = image_style_url($variables['style_name'], $variables['uri']);
  return theme('image', $variables);
}