? .cache
? .project
? .projectOptions
? files
? imageapi.patch
? misc/Thumbs.db
? misc/farbtastic/Thumbs.db
? modules/gd
? sites/all/modules
? sites/default/settings.php
Index: includes/image.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/image.inc,v
retrieving revision 1.21
diff -u -r1.21 image.inc
--- includes/image.inc	12 May 2007 05:51:20 -0000	1.21
+++ includes/image.inc	7 Jun 2007 00:48:29 -0000
@@ -2,45 +2,20 @@
 // $Id: image.inc,v 1.21 2007/05/12 05:51:20 dries Exp $
 
 /**
- * Return a list of available toolkits.
- *
- * @return An array of toolkit name => descriptive title.
- */
-function image_get_available_toolkits() {
-  $toolkits = file_scan_directory('includes', 'image\..*\.inc$');
-
-  $output = array();
-  foreach ($toolkits as $file => $toolkit) {
-    include_once "./$file";
-    $function = str_replace('.', '_', $toolkit->name) .'_info';
-    if (function_exists($function)) {
-      $info = $function();
-      $output[$info['name']] = $info['title'];
-    }
-  }
-  $output['gd'] = t('Built-in GD2 toolkit');
-  return $output;
-}
-
-/**
  * Retrieve the name of the currently used toolkit.
- *
+ * 
  * @return String containing the name of the toolkit.
  */
 function image_get_toolkit() {
-  static $toolkit;
-  if (!$toolkit) {
-    $toolkit = variable_get('image_toolkit', 'gd');
-    $toolkit_file = './includes/image.'. $toolkit .'.inc';
-    if ($toolkit != 'gd' && file_exists($toolkit_file)) {
-      include_once $toolkit_file;
-    }
-    elseif (!image_gd_check_settings()) {
-      $toolkit = FALSE;
-    }
-  }
+  $toolkit = variable_get('image_toolkit', 'gd');
 
-  return $toolkit;
+  // Check existence of the image toolkit
+  if (isset($toolkit) && module_exists($toolkit)) {
+    // The toolkit is found, let's use it
+    return $toolkit;
+  }
+  
+  return FALSE;
 }
 
 /**
@@ -51,21 +26,9 @@
  *
  * @return Mixed values (typically Boolean for successful operation).
  */
-function image_toolkit_invoke($method, $params = array()) {
+function image_toolkit_invoke($method, $source, $dest, $params = array()) {
   if ($toolkit = image_get_toolkit()) {
-    $function = 'image_'. $toolkit .'_'. $method;
-    if (function_exists($function)) {
-      return call_user_func_array($function, $params);
-    }
-    else {
-      watchdog('php', 'The selected image handling toolkit %toolkit can not correctly process %function.', array('%toolkit' => $toolkit, '%function' => $function), WATCHDOG_ERROR);
-      return FALSE;
-    }
-  }
-  else {
-    if ($method == 'settings') {
-      return image_gd_settings();
-    }
+	return module_invoke($toolkit, 'image_toolkit', $method, $source, $dest, $params);
   }
 }
 
@@ -124,8 +87,10 @@
   $x = round(($info['width'] * $scale - $width) / 2);
   $y = round(($info['height'] * $scale - $height) / 2);
 
-  if (image_toolkit_invoke('resize', array($source, $destination, $info['width'] * $scale, $info['height'] * $scale))) {
-    return image_toolkit_invoke('crop', array($destination, $destination, $x, $y, $width, $height));
+  $params = array('width' => $info['width'] * $scale, 'height' => $info['height'] * $scale);
+  if (image_toolkit_invoke('resize', $source, $destination, $params)) {
+    $params = array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height);
+    return image_toolkit_invoke('crop', $destination, $destination, $params);
   }
   return FALSE;
 }
@@ -153,15 +118,15 @@
 
   $aspect = $info['height'] / $info['width'];
   if ($aspect < $height / $width) {
-    $width = (int)min($width, $info['width']);
-    $height = (int)round($width * $aspect);
+    $params['width'] = (int)min($width, $info['width']);
+    $params['height'] = (int)round($width * $aspect);
   }
   else {
-    $height = (int)min($height, $info['height']);
-    $width = (int)round($height / $aspect);
+    $params['height'] = (int)min($height, $info['height']);
+    $params['width'] = (int)round($height / $aspect);
   }
 
-  return image_toolkit_invoke('resize', array($source, $destination, $width, $height));
+  return image_toolkit_invoke('resize', $source, $destination, $params);
 }
 
 /**
@@ -173,7 +138,7 @@
  * @param $height        The target height.
  */
 function image_resize($source, $destination, $width, $height) {
-  return image_toolkit_invoke('resize', array($source, $destination, $width, $height));
+  return image_toolkit_invoke('resize', $source, $destination, array('width' => $width, 'height' => $height));
 }
 
 /**
@@ -184,7 +149,7 @@
  * @param $degrees The number of (clockwise) degrees to rotate the image
  */
 function image_rotate($source, $destination, $degrees) {
-  return image_toolkit_invoke('rotate', array($source, $destination, $degrees));
+  return image_toolkit_invoke('rotate', $source, $destination, array('degrees' => $degrees));
 }
 
 /**
@@ -198,161 +163,5 @@
  * @param $height        The target height
  */
 function image_crop($source, $destination, $x, $y, $width, $height) {
-  return image_toolkit_invoke('crop', array($source, $destination, $x, $y, $width, $height));
-}
-
-/**
- * GD2 toolkit functions
- * With the minimal requirements of PHP 4.3 for Drupal, we use the built-in version of GD.
- */
-
-/**
- * Retrieve settings for the GD2 toolkit.
- */
-function image_gd_settings() {
-  if (image_gd_check_settings()) {
-    $form = array();
-    $form['status'] = array('#value' => t('The built-in GD2 toolkit is installed and working properly.'));
-
-    $form['image_jpeg_quality'] = array(
-      '#type' => 'textfield',
-      '#title' => t('JPEG quality'),
-      '#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'),
-      '#size' => 10,
-      '#maxlength' => 3,
-      '#default_value' => variable_get('image_jpeg_quality', 75),
-      '#field_suffix' => t('%'),
-    );
-
-    return $form;
-  }
-  else {
-    form_set_error('image_toolkit', t('The built-in GD image toolkit requires that the GD module for PHP be installed and configured properly. For more information see <a href="@url">PHP\'s image documentation</a>.', array('@url' => 'http://php.net/image')));
-    return FALSE;
-  }
-}
-
-/**
- * Verify GD2 settings (that the right version is actually installed).
- *
- * @return boolean
- */
-function image_gd_check_settings() {
-  if ($check = get_extension_funcs('gd')) {
-    if (in_array('imagegd2', $check)) {
-      // GD2 support is available.
-      return TRUE;
-    }
-  }
-  return FALSE;
-}
-
-/**
- * Scale an image to the specified size using GD.
- */
-function image_gd_resize($source, $destination, $width, $height) {
-  if (!file_exists($source)) {
-    return FALSE;
-  }
-
-  $info = image_get_info($source);
-  if (!$info) {
-    return FALSE;
-  }
-
-  $im = image_gd_open($source, $info['extension']);
-  if (!$im) {
-    return FALSE;
-  }
-
-  $res = imageCreateTrueColor($width, $height);
-  if ($info['extension'] == 'png') {
-    $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
-    imagealphablending($res, FALSE);
-    imagefilledrectangle($res, 0, 0, $width, $height, $transparency);
-    imagealphablending($res, TRUE);
-    imagesavealpha($res, TRUE);
-  }
-  imageCopyResampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']);
-  $result = image_gd_close($res, $destination, $info['extension']);
-
-  imageDestroy($res);
-  imageDestroy($im);
-
-  return $result;
-}
-
-/**
- * Rotate an image the given number of degrees.
- */
-function image_gd_rotate($source, $destination, $degrees, $bg_color = 0) {
-  if (!function_exists('imageRotate')) {
-    return FALSE;
-  }
-
-  $info = image_get_info($source);
-  if (!$info) {
-    return FALSE;
-  }
-
-  $im = image_gd_open($source, $info['extension']);
-  if (!$im) {
-    return FALSE;
-  }
-
-  $res = imageRotate($im, $degrees, $bg_color);
-  $result = image_gd_close($res, $destination, $info['extension']);
-
-  return $result;
-}
-
-/**
- * Crop an image using the GD toolkit.
- */
-function image_gd_crop($source, $destination, $x, $y, $width, $height) {
-  $info = image_get_info($source);
-  if (!$info) {
-    return FALSE;
-  }
-
-  $im = image_gd_open($source, $info['extension']);
-  $res = imageCreateTrueColor($width, $height);
-  imageCopy($res, $im, 0, 0, $x, $y, $width, $height);
-  $result = image_gd_close($res, $destination, $info['extension']);
-
-  imageDestroy($res);
-  imageDestroy($im);
-
-  return $result;
-}
-
-/**
- * GD helper function to create an image resource from a file.
- */
-function image_gd_open($file, $extension) {
-  $extension = str_replace('jpg', 'jpeg', $extension);
-  $open_func = 'imageCreateFrom'. $extension;
-  if (!function_exists($open_func)) {
-    return FALSE;
-  }
-  return $open_func($file);
-}
-
-/**
- * GD helper to write an image resource to a destination file.
- */
-function image_gd_close($res, $destination, $extension) {
-  $extension = str_replace('jpg', 'jpeg', $extension);
-  $close_func = 'image'. $extension;
-  if (!function_exists($close_func)) {
-    return FALSE;
-  }
-  if ($extension == 'jpeg') {
-    return $close_func($res, $destination, variable_get('image_jpeg_quality', 75));
-  }
-  else {
-    return $close_func($res, $destination);
-  }
-}
-
-
+  return image_toolkit_invoke('crop', $source, $destination, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height));
+}
\ No newline at end of file
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.102
diff -u -r1.102 module.inc
--- includes/module.inc	25 May 2007 12:46:43 -0000	1.102
+++ includes/module.inc	6 Jun 2007 21:41:49 -0000
@@ -419,5 +419,5 @@
  * Array of modules required by core.
  */
 function drupal_required_modules() {
-  return array('block', 'filter', 'node', 'system', 'user');
+  return array('block', 'filter', 'node', 'system', 'user', 'gd');
 }
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.120
diff -u -r1.120 system.install
--- modules/system/system.install	5 Jun 2007 12:13:22 -0000	1.120
+++ modules/system/system.install	7 Jun 2007 01:07:42 -0000
@@ -3350,6 +3350,17 @@
 }
 
 /**
+ * Image toolkits are now modules, and the gd.module is always enabled default
+ */
+function system_update_6024() {
+  if (variable_get('image_toolkit', 'gd') == 'gd') {
+    module_enable(array('gd'));
+  }
+  return array();
+}
+
+ 
+/**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
  */
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.489
diff -u -r1.489 system.module
--- modules/system/system.module	5 Jun 2007 09:15:02 -0000	1.489
+++ modules/system/system.module	6 Jun 2007 23:19:33 -0000
@@ -781,19 +781,38 @@
 }
 
 function system_image_toolkit_settings() {
-  $toolkits_available = image_get_available_toolkits();
-  if (count($toolkits_available) > 1) {
-    $form['image_toolkit'] = array(
+  // @TODO: This is an in-elegant way to get the module's description from the .info 
+  // file. There should be a function to do this.
+  $modules = module_rebuild_cache();
+  $available_toolkits = array();
+
+  foreach (module_implements('image_toolkit', TRUE) as $module) {
+    $available_toolkits[$module] = $modules[$module]->info['description'];
+  }
+
+  if (count($available_toolkits) > 0) {
+    $toolkit = image_get_toolkit();
+
+    $form['image_toolkits'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Image processing toolkits'),
+      '#description' => t('For resizing, cropping and other image manipulations Drupal uses the %toolkit toolkit.', array('%toolkit' => $toolkit)),
+    );
+    $form['image_toolkits']['image_toolkit'] = array(
       '#type' => 'radios',
       '#title' => t('Select an image processing toolkit'),
-      '#default_value' => variable_get('image_toolkit', image_get_toolkit()),
-      '#options' => $toolkits_available
+      '#options' => $available_toolkits,
+      '#default_value' => $toolkit,
     );
+
+    $form = module_invoke($toolkit, 'settings', $form);
   }
   else {
-    $form['image_toolkit'] = array('#value' => '<p>'. t("No image toolkits found. Drupal will use PHP's built-in GD library for image handling.") .'</p>');
+    $form['image_toolkits'] = array(
+      '#description' => '<p>'. t("No image toolkits found. Drupal will use PHP's built-in GD library for image handling.") .'</p>',
+    );
   }
-  $form['image_toolkit_settings'] = image_toolkit_invoke('settings');
+
   return system_settings_form($form);
 }
 
--- modules/gd/gd.info
+++ modules/gd/gd.info
@@ -0,0 +1,5 @@
+; $Id $
+name = GD2
+description = Built-in GD2 image processing support.
+version = "$Name: DRUPAL-6 $"
+package = Core - required

--- modules/gd/gd.module
+++ modules/gd/gd.module
@@ -0,0 +1,103 @@
+<?php
+// $id: $
+/**
+ * GD2 toolkit functions
+ * With the minimal requirements of PHP 4.3 for Drupal, we use
+ * GD2 as the default image processing toolkit.
+ */
+
+/**
+ * Retrieve settings for the GD2 toolkit.
+ */
+function gd_settings($form) {
+  $form['image_toolkit_gd'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('GD2 preferences'),
+  );
+  $form['image_toolkit_gd']['image_jpeg_quality'] = array(
+    '#type' => 'textfield',
+    '#title' => t('JPEG quality'),
+    '#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality, but bigger files.'),
+    '#size' => 10,
+    '#maxlength' => 3,
+    '#default_value' => variable_get('image_jpeg_quality', 75),
+    '#field_suffix' => '%',
+  );
+
+  return $form;
+}
+
+function gd_image_toolkit($op, $source = NULL, $destination = NULL, $params = array()) {
+  if (!file_exists($source)) {
+    return FALSE;
+  }
+  
+  $info = image_get_info($source);
+  if (!$info) {
+    return FALSE;
+  }
+  
+  $im = _gd_open($source, $info['extension']);
+  if (!$im) {
+    return FALSE;
+  }
+  
+  switch ($op) {
+    case 'crop':
+      $res = imageCreateTrueColor($params['width'], $params['height']);
+      imageCopy($res, $im, 0, 0, $params['x'], $params['y'], $params['width'], $params['height']);
+      break;
+      
+    case 'resize':
+      $res = imageCreateTrueColor($params['width'], $params['height']);
+      if ($info['extension'] == 'png') {
+        $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
+        imagealphablending($res, FALSE);
+        imagefilledrectangle($res, 0, 0, $params['width'], $params['height'], $transparency);
+        imagealphablending($res, TRUE);
+        imagesavealpha($res, TRUE);
+      }
+      imageCopyResampled($res, $im, 0, 0, 0, 0, $params['width'], $params['height'], $info['width'], $info['height']);
+      break;
+      
+    case 'rotate':
+      $res = imageRotate($im, $params['degrees'], $bg_color);
+      break;
+
+  }
+  $result = _gd_close($res, $destination, $info['extension']);
+
+  imageDestroy($im);
+  imageDestroy($res);
+
+  return $result;
+}
+
+/**
+ * GD helper function to create an image resource from a file.
+ */
+function _gd_open($file, $extension) {
+  $extension = str_replace('jpg', 'jpeg', $extension);
+  $open_func = 'imageCreateFrom'. $extension;
+  if (!function_exists($open_func)) {
+    return FALSE;
+  }
+  return $open_func($file);
+}
+
+/**
+ * GD helper to write an image resource to a destination file.
+ */
+function _gd_close($res, $destination, $extension) {
+  $extension = str_replace('jpg', 'jpeg', $extension);
+  $close_func = 'image'. $extension;
+  if (!function_exists($close_func)) {
+    return FALSE;
+  }
+  if ($extension == 'jpeg') {
+    return $close_func($res, $destination, variable_get('image_jpeg_quality', 75));
+  }
+  else {
+    return $close_func($res, $destination);
+  }
+}

