Index: includes/image.gd.inc
===================================================================
RCS file: includes/image.gd.inc
diff -N includes/image.gd.inc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ includes/image.gd.inc       31 May 2007 21:26:51 -0000
@@ -0,0 +1,158 @@
+<?php
+// $id: $
+/**
+ * GD2 toolkit functions
+ * With the minimal requirements of PHP 4.3 for Drupal, we use the built-in version of GD.
+ */
+
+function image_gd_info() {
+  return array('name' => 'gd', 'title' => 'Build-in GD2 toolkit.');
+}
+/**
+ * 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);
+  }
+}
Index: includes/image.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/image.inc,v
retrieving revision 1.21
diff -u -F^f -r1.21 image.inc
--- includes/image.inc  12 May 2007 05:51:20 -0000      1.21
+++ includes/image.inc  31 May 2007 21:26:51 -0000
@@ -18,31 +18,20 @@ function image_get_available_toolkits() 
       $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;
-    }
+  if ($toolkit = variable_get('image_toolkit', 'gd')) {
+    include_once './includes/image.'. $toolkit .'.inc';
+  }
+  else {
+    $toolkit = FALSE;
   }
-
-  return $toolkit;
 }
 
+
 /**
  * Invokes the given method using the currently selected toolkit.
  *
@@ -62,11 +51,6 @@ function image_toolkit_invoke($method, $
       return FALSE;
     }
   }
-  else {
-    if ($method == 'settings') {
-      return image_gd_settings();
-    }
-  }
 }
 
 
@@ -200,159 +184,3 @@ function image_rotate($source, $destinat
 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);
-  }
-}
-
-