You are here

function theme_imagecache_proportions_formatter_vertical_horizontal in Imagecache Proportions 6

Depending on the dimensions of the image, we switch the preset chosen.

File

./imagecache_proportions.module, line 146
CCK formatter for imagefields that allows the user to select between 3 different imagecache presets depending on the proportions of the original image uploaded. One preset would be squared for more or less squared images, another for wider images and…

Code

function theme_imagecache_proportions_formatter_vertical_horizontal($element) {

  // Inside a view $element may contain NULL data. In that case, just return.
  if (empty($element['#item']['fid'])) {
    return '';
  }
  $item = $element['#item'];
  $widget = imagecache_proportions_get_field_settings($element['#field_name'], $element['#type_name']);
  $size = getimagesize($item['filepath']);
  $width = $size[0];
  $height = $size[1];
  $proportions = imagecache_proportions_calculate_proportions($size[0], $size[1], $widget['looseness']);
  $presetname = $widget[$proportions];
  $item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : '';
  $item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL;
  switch ($widget['enable_link']) {
    case 'node':

      // Link to its node, get the nid and show a link instead.
      $style = 'linked';
      $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']);
      $path = empty($item['nid']) ? '' : 'node/' . $item['nid'];
      $class = "imagecache imagecache-{$presetname} imagecache-{$style} imagecache-{$element['#formatter']}";
      return l($imagetag, $path, array(
        'attributes' => array(
          'class' => $class,
        ),
        'html' => TRUE,
      ));
      break;
    case 'image':

      // Image link, also get the image modal window, if any.
      $style = 'imagelink';

      // No fancy image plugin, we just show the raw image.
      $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']);
      $path = file_create_url($item['filepath']);
      $link_attributes['class'] = "imagecache imagecache-{$presetname} imagecache-{$style} imagecache-{$element['#formatter']}";
      return l($imagetag, $path, array(
        'attributes' => $link_attributes,
        'html' => TRUE,
      ));
      break;
    case 'colorbox':
      $style = 'imagelink';
      switch (variable_get('colorbox_imagefield_gallery', 1)) {
        case 0:
          $gallery_id = 'all';
          break;
        case 1:
          $gallery_id = $element['#node']->nid;
          break;
        case 2:
          $gallery_id = $element['#node']->nid . '-' . $element['#field_name'];
          break;
        case 3:
          $gallery_id = $element['#node']->nid . '-' . $item['fid'];
          break;
      }
      return theme('colorbox_imagefield', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title'], $gallery_id, $element['#field_name']);
      break;
    case 'thickbox':
      $style = 'imagelink';
      return theme('imagefield_image_imagecache_thickbox', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']);
      break;
    case 'shadowbox':
      $style = 'imagelink';
      return theme('imagefield_image_imagecache_shadowbox', $presetname, 'original', $item, array(), NULL);
      break;
    case 'lightbox2':
      $style = 'imagelink';
      return theme('imagefield_image_imagecache_lightbox2', $presetname, $element['#field_name'], $item, $element['#node'], 'lightbox', $args = array());
      break;
    case 'none':
    default:

      // No link, return a normal imagecache element.
      $style = 'default';
      $class = "imagecache imagecache-{$presetname} imagecache-{$style} imagecache-{$element['#formatter']}";
      return theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title'], array(
        'class' => $class,
      ));
  }
}