theme_image_style

Versions
mediamosa-21
theme_image_style($variables)

Return a themed image using a specific image style.

ingroup themeable

Parameters

$variables An associative array containing:

  • style_name: The name of the style to be used to alter the original image.
  • path: 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.
  • 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.
  • getsize: If set to TRUE, the image's dimension are fetched and added as width/height attributes.

Return value

A string containing the image tag.

Code

modules/image/image.module, line 1031

<?php
function theme_image_style($variables) {
  $style_name = $variables['style_name'];
  $path = $variables['path'];

  // theme_image() can only honor the $getsize parameter with local file paths.
  // The derivative image is not created until it has been requested so the file
  // may not yet exist, in this case we just fallback to the URL.
  $style_path = image_style_path($style_name, $path);
  if (!file_exists($style_path)) {
    $style_path = image_style_url($style_name, $path);
  }
  $variables['path'] = file_create_url($style_path);
  $variables['getsize'] = FALSE;
  return theme('image', $variables);
}
?>