You are here

function theme_emimage_image in Embedded Media Field 6

Same name and namespace in other branches
  1. 6.3 contrib/emimage/emimage.theme.inc \theme_emimage_image()
  2. 6.2 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()) {

  // Get a thumbnail URL. This can be an override through $options['thumbnail_url'],
  // defined by the provider (the usual case), or a default image.
  if (isset($options['thumbnail_url']) || $item['value'] && $item['provider']) {

    // If we've set $options['thumbnail_url'], then we'll just use that.
    $url = isset($options['thumbnail_url']) ? $options['thumbnail_url'] : '';

    // Otherwise, if we have emthumb installed, then give it a chance to override our thumbnail.
    if (empty($url) && function_exists('emthumb_thumbnail_path')) {
      $url = emthumb_thumbnail_path($item);
    }

    // If we don't have a custom thumbnail, then see if the provider gives us a thumbnail.
    if (empty($url)) {
      $url = module_invoke('emfield', 'include_invoke', 'emimage', $item['provider'], 'image_url', $code, $width, $height, $formatter, $field, $item, $node);
    }
  }
  $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;
}