Index: imagefield/imagefield.module
===================================================================
--- imagefield/imagefield.module	(revision 8)
+++ imagefield/imagefield.module	(working copy)
@@ -31,7 +31,7 @@
   return array(
     // theme an image uploaded to imagefield with alt and title. @todo: switch to core theme image if possible.
     'imagefield_image' => array(
-      'arguments' => array('file' => null, 'alt' => '', 'title' => '', 'attributes' => null, 'getsize' => TRUE),
+      'arguments' => array('file' => null, 'alt' => '', 'title' => '', 'attributes' => null, 'getsize' => TRUE, 'useimagecachepreset' => FALSE, 'imagecachepreset' => ''),
     ),
     // theme an imagefield field item. It calls imagefied_image with the proper item properties as arguments.
     'imagefield_item' => array(
@@ -93,7 +93,7 @@
     // Indicate to FormAPI that this element needs processing and is not simply a render element.
     '#input' => TRUE,
     // specify the return structure of the element (experimental, unused in releases).
-    '#returns' => array('array' => array('fid' => 'int', 'title' => 'string', 'alt' => 'string')),
+    '#returns' => array('array' => array('fid' => 'int', 'title' => 'string', 'alt' => 'string', 'useimagecachepreset' => 'int', 'imagecachepreset' => 'string')),
     // Delegate element processing to filefield. Filefield will include
     '#process' => array('filefield_widget_process', 'imagefield_widget_widget_process'),
     // See imagefield_widget[#process] documentation.
@@ -190,11 +190,13 @@
   // @todo: use CCK's default value callback.
   // add default values to items.
   if (empty($items[$delta])) {
-    $items[$delta] = array('alt' => '', 'title' => '');
+    $items[$delta] = array('alt' => '', 'title' => '', 'useimagecachepreset' => FALSE, 'imagecachepreset' => '');
   }
   $element = filefield_widget($form, $form_state, $field, $items, $delta);
-
   $element['#upload_validators'] += imagefield_widget_upload_validators($field);
+  
+  $element['#default_value']['data']['useimagecachepreset'] = $field['widget']['useimagecachepreset'];
+  $element['#default_value']['data']['imagecachepreset'] = $field['widget']['imagecachepreset'];
 
   return $element;
 }
@@ -272,7 +274,7 @@
  * A temporary home for theme functions until they all get relocated to
  * imagefield_theme.inc?? or should I leave theme here. They aren't that big.
  */
-function theme_imagefield_image($file, $alt = '', $title = '', $attributes = null, $getsize = true) {
+function theme_imagefield_image($file, $alt = '', $title = '', $attributes = null, $getsize = true, $useimagecachepreset = FALSE, $imagecachepreset = '') {
   $file = (array)$file;
   if (!is_file($file['filepath'])) {
     return '<!-- file not found: '. $file['filepath'] .' -->';
@@ -283,14 +285,21 @@
     $alt = empty($alt) ? $file['alt'] : $alt;
     $title = empty($title) ? $file['title'] : $title;
     $url = file_create_url($file['filepath']);
-    return '<img src="'. check_url($url) .'" alt="'.
-        check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />';
+
+    if (module_exists('imagecache') && isset($useimagecachepreset)) {
+      return theme('imagecache', $imagecachepreset, $file['filepath'], $title, $alt, array('class' => $extraclasses));
+    } else
+    {
+      return '<img src="'. check_url($url) .'" alt="'.
+          check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />';
+    }
+    
   }
   return '<!-- could not get imagesize, possibly corrupt or non image. '. $file['filepath'] .' -->';
 }
 
 function theme_imagefield_item($item) {
-  return theme('imagefield_image', $item, $item['alt'], $item['title']);
+  return theme('imagefield_image', $item, $item['alt'], $item['title'], $item['useimagecachepreset'], $item['imagecachepreset']);
 }
 
 function theme_imagefield_widget_preview($item = null) {
@@ -308,8 +317,14 @@
   if (is_null($item) || empty($item['filepath'])) {
     return '<!-- link to default admin thumb -->';
   }
-  $thumb_path = imagefield_file_admin_thumb_path($item);
-  return '<img src="'. file_create_url($thumb_path) .'" />';
+  
+  if (module_exists('imagecache') && isset($item['data']['useimagecachepreset']) && isset($item['data']['imagecachepreset'])) {
+    return theme('imagecache', $item['data']['imagecachepreset'], $item['filepath']);
+  } else
+  {
+    $thumb_path = imagefield_file_admin_thumb_path($item);
+    return '<img src="'. file_create_url($thumb_path) .'" />'; 
+  }
 }
 /**
  * @} End defgroup "Theme Callbacks".
@@ -326,6 +341,8 @@
   foreach($items as $delta => $item) {
     $items[$delta]['data']['title'] = $field['widget']['title'];
     $items[$delta]['data']['alt'] = $field['widget']['alt'];
+    $items[$delta]['data']['useimagecachepreset'] = $field['widget']['useimagecachepreset'];
+    $items[$delta]['data']['imagecachepreset'] = $field['widget']['imagecachepreset'];
   }
   return $items;
 }
Index: imagefield/imagefield_file.inc
===================================================================
--- imagefield/imagefield_file.inc	(revision 8)
+++ imagefield/imagefield_file.inc	(working copy)
@@ -20,6 +20,7 @@
 }
 
 function imagefield_file_insert($file) {
+/*
   // create and admin thumbnail.
   if (imagefield_file_is_image($file)) {
     $info = image_get_info($file->filepath);
@@ -31,12 +32,15 @@
       image_scale($file->filepath, imagefield_file_admin_thumb_path($file), 100, 100);
     }
   }
+*/
 }
 
 function imagefield_file_delete($file) {
+/*
   // delete admin thumbnail.
   if (imagefield_file_is_image($file))
     file_delete(imagefield_file_admin_thumb_path($file));
+*/
 }
 
 
Index: imagefield/imagefield_formatter.inc
===================================================================
--- imagefield/imagefield_formatter.inc	(revision 8)
+++ imagefield/imagefield_formatter.inc	(working copy)
@@ -20,7 +20,7 @@
   if (empty($item['filepath']))  $item = array_merge($item, field_file_load($item['fid']));
 
   $class = 'imagefield imagefield-'. $field['field_name'];
-  return  theme('imagefield_image', $item, $item['data']['alt'], $item['data']['title'], array('class' => $class));
+  return  theme('imagefield_image', $item, $item['data']['alt'], $item['data']['title'], array('class' => $class), $item['data']['useimagecachepreset'], $item['data']['imagecachepreset']);
 }
 
 function theme_imagefield_formatter_image_nodelink($element) {
Index: imagefield/imagefield_widget.inc
===================================================================
--- imagefield/imagefield_widget.inc	(revision 8)
+++ imagefield/imagefield_widget.inc	(working copy)
@@ -95,12 +95,39 @@
     '#description' => t('This value will be used as the image title by default.'),
     '#suffix' =>  theme('token_help', 'file'),
   );
+
+  // imagecache module presets
+  if (module_exists('imagecache')) {
+    $image_sizes = imagecache_presets();
+      foreach ($image_sizes as $key => $size) {
+        $preview_presets_list[$size['presetname']] = t('Image size') .': ' .$size['presetname'];
+      }
+      $form['imagecache_settings']['useimagecachepreset'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Use Imagecache Preset'),
+        '#description' => t('Use imagecache for preview.'),
+        '#default_value' => !empty($widget['useimagecachepreset']) ? $widget['useimagecachepreset'] : '',
+      );
+      $form['imagecache_settings']['imagecachepreset'] = array(
+        '#type' => 'select',
+        '#title' => t('Preview Image Preset'),
+        '#description' => t('This setting is responsible for the way of displaying and handling the preview image which is generated out of the original image. Between different image sizes can be chosen.<br /> If <em>imagecache module</em> is installed and enabled, also its presets (if available) can be used to display the preview image.'),
+        '#options' => $preview_presets_list, // @str_replace: returns correct node type
+        '#default_value' => !empty($widget['imagecachepreset']) ? $widget['imagecachepreset'] : '',
+      );
+  }
+ 
   return $form;
 }
 
 function imagefield_widget_widget_settings_save($widget) {
   //@todo: rename custom_alt and custom_title to alt_custom and title_custom to be OCD.
-  return array('max_resolution', 'min_resolution', 'alt',  'custom_alt', 'title', 'custom_title');
+  if (module_exists('imagecache')) {
+    return array('max_resolution', 'min_resolution', 'alt',  'custom_alt', 'title', 'custom_title', 'useimagecachepreset', 'imagecachepreset', 'extraclasses');
+  } else
+  {
+    return array('max_resolution', 'min_resolution', 'alt',  'custom_alt', 'title', 'custom_title');
+  }
 }
 
 /**
@@ -117,6 +144,19 @@
  * return values will be merged with the filefield callback's.
  */
 function imagefield_widget_widget_value($element, $edit = FALSE) {
+
+  if (module_exists('imagecache')) {
+    if ($edit) {
+        return array(
+          'alt' => isset($edit['alt']) ? $edit['alt'] : '',
+          'title' => isset($edit['title']) ? $edit['title'] : '',
+          'useimagecachepreset' => isset($edit['useimagecachepreset']) ? $edit['useimagecachepreset'] : '',
+          'imagecachepreset' => isset($edit['imagecachepreset']) ? $edit['imagecachepreset'] : '',
+        );
+    }
+    return array('alt' => '', 'title' => '', 'useimagecachepreset' => '', 'imagecachepreset' => '');
+  }
+  
   // handle additional
   if ($edit) {
       return array(
@@ -150,6 +190,20 @@
     $element['data']['title']['#type'] = $file['fid'] ? 'textfield' : 'hidden';
     if (!empty($file['data']['title'])) $element['data']['title']['#value'] =  $file['data']['title'];
   }
+
+  if (module_exists('imagecache')) {
+    $element['data']['useimagecachepreset'] = array(
+      '#type' => 'value',
+      '#title' => t('Use Imagecache Preset'),
+      '#default_value' => $field['widget']['useimagecachepreset'],
+    );
+    $element['data']['imagecachepreset'] = array(
+      '#type' => 'value',
+      '#title' => t('Preview Image Preset'),
+      '#default_value' => $field['widget']['imagecache'],
+    );
+  }
+  
   return $element;
 }
 
