theme_image

5 theme.inc theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE)
6 theme.inc theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE)
7 theme.inc theme_image($variables)
8 theme.inc theme_image($variables)

Return a themed image.

Parameters

$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

10 theme calls to theme_image()

File

includes/theme.inc, line 616
The theme system, which controls the output of Drupal.

Code

function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
    $attributes = drupal_attributes($attributes);
    $url = (url($path) == $path) ? $path : (base_path() . $path);
    return '<img src="' . check_url($url) . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" ' . $image_attributes . $attributes . ' />';
  }
}

Comments

If you're using theme_image()

If you're using theme_image() on a URL instead of a path set $getsize = FALSE or this function won't have a return value.

Not entirely true. PHP can

Not entirely true. PHP can fetch the image over the net to evaluate the size. Some PHP configurations have disable this. Many have it enabled; wich causes a) a lot of bandwith and b) speed problems, since theme_image will return a value only after the entire image was transferred and processed.

So: when using this with a path that contains http:// you may get nothing. Or you may have speed problems. Don't do that!

Login or register to post comments