theme_image

Versions
4.6
theme_image($path, $alt = '', $title = '', $attr = '', $getsize = true)
4.7 – 6
theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE)
7
theme_image($variables)

Return a themed image.

Parameters

$variables An associative array containing:

  • path: Either the path of the image file (relative to base_path()) or a full URL.
  • 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.

Related topics

Code

includes/theme.inc, line 1521

<?php
function theme_image($variables) {
  $path = $variables['path'];
  $alt = $variables['alt'];
  $title = $variables['title'];
  $attributes = $variables['attributes'];
  $getsize = $variables['getsize'];

  if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
    $attributes = drupal_attributes($attributes);
    $url = file_create_url($path);
    return '<img src="' . check_url($url) . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" ' . (isset($image_attributes) ? $image_attributes : '') . $attributes . ' />';
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.