Index: includes/image.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/image.inc,v
retrieving revision 1.25
diff -u -p -r1.25 image.inc
--- includes/image.inc	14 Apr 2008 17:48:33 -0000	1.25
+++ includes/image.inc	14 Jun 2008 13:35:04 -0000
@@ -21,11 +21,12 @@
  * from this problem, but it requires the ISP to have installed additional
  * software.
  *
- * Image toolkits are installed by copying the image.ToolkitName.inc file into
- * Drupal's includes directory. The toolkit must then be enabled using the
- * admin/settings/image-toolkit form.
+ * Image toolkits are discovered based on the "image-toolkit[]" entries in
+ * the associated modules' .info file or can be installed manually by copying
+ * the image.ToolkitName.inc file into Drupal's includes directory. The toolkit
+ * must then be enabled using the admin/settings/image-toolkit form.
  *
- * Only one toolkit maybe selected at a time. If a module author wishes to call
+ * Only one toolkit may be selected at a time. If a module author wishes to call
  * a specific toolkit they can check that it is installed by calling
  * image_get_available_toolkits(), and then calling its functions directly.
  */
@@ -38,12 +39,12 @@
  */
 function image_get_available_toolkits() {
   $toolkits = file_scan_directory('includes', 'image\..*\.inc$');
+  $toolkits = array_merge($toolkits, _get_toolkits_from_module_info());
 
   $output = array();
   foreach ($toolkits as $file => $toolkit) {
-    include_once "./$file";
     $function = str_replace('.', '_', $toolkit->name) . '_info';
-    if (function_exists($function)) {
+    if (drupal_function_exists($function)) {
       $info = $function();
       $output[$info['name']] = $info['title'];
     }
@@ -53,6 +54,44 @@ function image_get_available_toolkits() 
 }
 
 /**
+ * Retrieves image toolkit include file information from the .info file of
+ * enabled modules.  This function is used by the image_get_available_toolkits()
+ * function and provides the information in the same form as the
+ * file_scan_directory() function.
+ * @see file_scan_directory()
+ *
+ * @return
+ *   An associative array (keyed by file path) of objects with "path",
+ *   "basename", and "name" members corresponding to any discovered
+ *   image-toolkit include files.
+ */
+function _get_toolkits_from_module_info() {
+  $output = array();
+  $modules = db_query("SELECT name, info FROM {system} WHERE type = 'module' AND status = 1");
+  while ($module = db_fetch_object($modules)) {
+    // Get the module's info data to see if an image toolkit is specified
+    $info = unserialize($module->info);
+    if (!isset($info['image_toolkit'])) {
+      continue;
+    }
+    // Look for all info files that have image_toolkit keys
+    for ($i = 0; isset($info['image_toolkit'][$i]); $i++) {
+      // Found a toolkit.  Provide the same format of file attributes as is
+      // provided by the file_scan_directory() function so the information can be
+      // merged seamlessly.
+      $path = drupal_get_path('module', $info['name']) . '/' .
+        $info['image_toolkit'][$i];
+      $file = pathinfo($path);
+      $output[$path] = new stdClass();
+      $output[$path]->filename = $path;
+      $output[$path]->basename = $file['basename'];
+      $output[$path]->name = $file['filename'];
+    }
+  }
+  return $output;
+}
+
+/**
  * Retrieve the name of the currently used toolkit.
  *
  * @return
@@ -63,11 +102,11 @@ function image_get_toolkit() {
 
   if (!$toolkit) {
     $toolkit = variable_get('image_toolkit', 'gd');
-    $toolkit_file = './includes/image.' . $toolkit . '.inc';
-    if (isset($toolkit) && file_exists($toolkit_file)) {
-      include_once $toolkit_file;
+    if (isset($toolkit) &&
+      drupal_function_exists("image_" . $toolkit . "_resize")) {
     }
-    elseif (!image_gd_check_settings()) {
+    elseif (!drupal_function_exists("image_gd_check_settings") ||
+      !image_gd_check_settings()) {
       $toolkit = FALSE;
     }
   }
@@ -88,7 +127,7 @@ function image_get_toolkit() {
 function image_toolkit_invoke($method, $params = array()) {
   if ($toolkit = image_get_toolkit()) {
     $function = 'image_' . $toolkit . '_' . $method;
-    if (function_exists($function)) {
+    if (drupal_function_exists($function)) {
       return call_user_func_array($function, $params);
     }
     else {
