Index: extensions/GThumb/main.inc.php
===================================================================
--- extensions/GThumb/main.inc.php	(revision 12924)
+++ extensions/GThumb/main.inc.php	(revision 13652)
@@ -14,5 +14,4 @@
 
 define('GTHUMB_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
-define('GTHUMB_CACHE_DIR', PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb');
 
 $conf['GThumb'] = unserialize($conf['GThumb']);
@@ -26,5 +25,4 @@
 
 add_event_handler('loc_begin_index', 'GThumb_init', 60);
-add_event_handler('ws_add_methods', 'add_gthumb_thumbnails_method');
 add_event_handler('get_admin_plugin_menu_links', 'GThumb_admin_menu');
 
@@ -48,166 +46,13 @@
   $template->assign('GThumb', $conf['GThumb']);
 
-  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
+  $template->assign('GThumb_derivative_params', ImageStdParams::get_custom(9999, $conf['GThumb']['height']));
 
-  foreach ($tpl_vars as $key => &$tpl_var)
+  if ($conf['GThumb']['big_thumb'] and !empty($tpl_vars[0]))
   {
-    $data = get_gthumb_data($pictures[$key]);
-
-    $tpl_var['TN_SRC'] = $data['src'];
-    $tpl_var['TN_WIDTH'] = $data['width'];
-    $tpl_var['TN_HEIGHT'] = $data['height'];
+    $derivative_params = ImageStdParams::get_custom(9999, 2 * $conf['GThumb']['height'] + $conf['GThumb']['margin']);
+    $template->assign('GThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image']));
   }
 
-  if ($conf['GThumb']['big_thumb'])
-  {
-    $ft = &$tpl_vars[0];
-
-    // Small thumb data
-    $small_thumb = array(
-      'id' => $ft['ID'],
-      'src' => $ft['TN_SRC'],
-      'width' => $ft['TN_WIDTH'],
-      'height' => $ft['TN_HEIGHT'],
-    );
-
-    if (empty($small_thumb['src']))
-    {
-      include_once(GTHUMB_PATH.'functions.inc.php');
-      $data = get_gthumb_data($pictures[0]);
-      $result = make_gthumb_image($pictures[0], $data);
-      $small_thumb['src'] = $result['destination'];
-    }
-
-    // Big thumb data
-    $data = get_gthumb_data($pictures[0], 'big');
-
-    $big_thumb = array(
-      'id' => $ft['ID'],
-      'src' => $data['src'],
-      'width' => $data['width'],
-      'height' => $data['height'],
-    );
-    if (empty($big_thumb['src']))
-    {
-      if ($conf['GThumb']['cache_big_thumb'])
-      {
-        include_once(GTHUMB_PATH.'functions.inc.php');
-        $result = make_gthumb_image($pictures[0], $data);
-        $big_thumb['src'] = embellish_url(get_root_url().$result['destination']);
-      }
-      else
-      {
-        $big_thumb['src'] = get_root_url().'ws.php?method=pwg.images.getGThumbPlusThumbnail&image_id='.$ft['ID'].'&size=big&return=true';
-      }
-    }
-
-    $template->assign(
-      array(
-        'small_thumb' => $small_thumb,
-        'big_thumb' => $big_thumb,
-      )
-    );
-    $ft['TN_SRC'] = $big_thumb['src'];
-    $ft['TN_WIDTH'] = $big_thumb['width'];
-    $ft['TN_HEIGHT'] = $big_thumb['height'];
-  }
-  
   return $tpl_vars;
-}
-
-function add_gthumb_thumbnails_method($arr)
-{
-  include_once(GTHUMB_PATH.'functions.inc.php');
-
-  $service = &$arr[0];
-  $service->addMethod(
-    'pwg.images.getGThumbPlusThumbnail',
-    'ws_images_getGThumbPlusThumbnail',
-    array(
-      'image_id' => array(),
-      'size' => array('default'=>'small'),
-      'return' => array('default'=>false),
-    ),
-    'Get thumbnail for GThumb+ plugin. Size parameter can be "small" or "big".'
-  );
-}
-
-function get_gthumb_data($picture, $size='small')
-{
-  global $conf;
-
-  $picture_ext = array('jpg', 'jpeg', 'png', 'gif');
-
-  if (!in_array(strtolower(get_extension($picture['path'])), $picture_ext))
-  {
-    list($width, $height) = getimagesize(get_thumbnail_path($picture));
-
-    return array(
-      'src' => get_thumbnail_url($picture),
-      'width' => $width,
-      'height' => $height,
-    );
-  }
-
-  $new_height = $size == 'small' ? $conf['GThumb']['height'] : $conf['GThumb']['height'] * 2 + $conf['GThumb']['margin'];
-  $file = GTHUMB_CACHE_DIR.'/'.$new_height.'/'.md5($picture['path'].(!empty($picture['md5sum']) ? $picture['md5sum'] : '')).'.'.$picture['tn_ext'];
-
-  if (file_exists($file))
-  {
-    list($width, $height) = getimagesize($file);
-
-    return array(
-      'src' => embellish_url(get_root_url().$file),
-      'width' => $width,
-      'height' => $height,
-    );
-  }
-
-  if ( !empty($picture['tn_ext']) )
-  {
-    $file = substr_replace(get_filename_wo_extension($picture['path']), '/thumbnail/GT-',strrpos($picture['path'],'/'),1).'.'.$picture['tn_ext'];
-    if (file_exists($file))
-    {
-      list($width, $height) = getimagesize($file);
-
-      return array(
-        'src' => embellish_url(get_root_url().$file),
-        'width' => $width,
-        'height' => $height,
-      );
-    }
-  }
-
-  $width = $picture['width'];
-  $height = $picture['height'];
-  $use_high = false;
-
-  if ($height < $new_height and $picture['has_high'] == 'true')
-  {
-    $width = $picture['high_width'];
-    $height = $picture['high_height'];
-    $use_high = true;
-  }
-
-  if ($size == 'big')
-  {
-    $width = min($width, round(max($height, $new_height) * 1.15));
-  }
-
-  $result = pwg_image::get_resize_dimensions($width, $height, 5000, $new_height);
-  $result['src'] = '';
-
-  // Test thumbnail size
-  list($width, $height) = getimagesize(get_thumbnail_path($picture));
-  if ($result['width'] == $width and $result['height'] == $height)
-  {
-    $result['src'] = get_thumbnail_url($picture);
-  }
-
-  $result['use_high'] = $use_high;
-  $result['cache_path'] = GTHUMB_CACHE_DIR.'/'.$new_height.'/';
-  $result['size'] = $size;
-
-  return $result;
 }
 
