You are here

function theme_emimage_image in Embedded Media Field 6.2

Same name and namespace in other branches
  1. 6.3 contrib/emimage/emimage.theme.inc \theme_emimage_image()
  2. 6 contrib/emimage/emimage.theme.inc \theme_emimage_image()

Helper theme for various emimage themes.

3 theme calls to theme_emimage_image()
theme_emimage_image_full in contrib/emimage/emimage.theme.inc
Format the image using the Full Image preset.
theme_emimage_image_preview in contrib/emimage/emimage.theme.inc
Format the image using the Preview Image preset.
theme_emimage_image_thumbnail in contrib/emimage/emimage.theme.inc
Format the image using the Thumbnail presets.

File

contrib/emimage/emimage.theme.inc, line 11
Theme functions for Embedded Media Image

Code

function theme_emimage_image($field, $item, $formatter, $node, $code, $width = NULL, $height = NULL, $title = '', $link = NULL, $options = array()) {
  $url = emimage_image_url($field, $item, $formatter, $node, $code, $width, $height, $options);
  $attributes = array();
  if ($width) {
    $attributes['width'] = $width;
  }
  if ($height) {
    $attributes['height'] = $height;
  }
  if (!isset($width) || !isset($height)) {

    // Find out the size of the actual image file, and scale accordingly
    if ($item['data']['width'] && $item['data']['height']) {

      // The image's width & height are known
      $scale_width = $item['data']['width'] / ($width ? $width : 1);
      $scale_height = $item['data']['height'] / ($height ? $height : 1);
      if ($scale_width > $scale_height) {
        $attributes['width'] = $width;
      }
      else {
        $attributes['height'] = $height;
      }
    }
    else {

      // We don't know the size of the image, so just make it fill the space available.
      // It will probably be stretched in one direction, making it look odd.
      $attributes['width'] = $width ? $width : NULL;
      $attributes['height'] = $height ? $height : NULL;
    }
  }
  if ($item['class']) {
    $attributes['class'] = $item['class'];
  }
  else {
    if ($item['provider']) {
      $attributes['class'] = $item['provider'];
    }
  }
  $output = theme('image', $url, $title, $title, $attributes, false);
  if ($link) {
    $output = l($output, $link, array(
      'html' => true,
    ));
  }
  return $output;
}