Theme a image from a CCK Image Field with either theme('image'...) or theme('imagecache'...)


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Theme a image from a CCK Image Field with either theme('image'...) or theme('imagecache'...)
  3.  *
  4.  * @param array $imageCckField The CCK Image field array usually called with: $node->field_tools_image[0] for example
  5.  * @param array $attributes Associative array of attributes to be placed in the img tag for example array('class' => 'link')
  6.  * @param string Imagecache preset
  7.  
  8.  * @return string A string containing the image tag.
  9.  *
  10.  * @link http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_image/6 theme_image
  11.  * @link http://drupal.org/node/163561 Imagecache: dynamic image manipulation
  12.  */
  13. function _fremtidslaboratoriet_themeImage($imageCckField, $attributes = array(), $imagecachePreset = NULL)
  14. {
  15. $returnValue = NULL;
  16. $filepath = $imageCckField['filepath'];
  17. $alt = $imageCckField['data']['alt'];
  18. $title = $imageCckField['data']['title'];
  19.  
  20. if(!$filepath)
  21. {
  22. return NULL;
  23. }
  24.  
  25. if ($imagecachePreset == NULL)
  26. {
  27. $returnValue = theme('image', $filepath, $alt, $title, $attributes);
  28. }
  29. else
  30. {
  31. $returnValue = theme('imagecache', $imagecachePreset,$filepath, $alt, $title, $attributes);
  32. }
  33.  
  34. return $returnValue;
  35. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.