--- image.inc.orig	2005-12-12 08:02:32.000000000 -0800
+++ image.inc	2005-12-12 08:14:47.000000000 -0800
@@ -177,7 +177,9 @@
  */
 function image_gd_settings() {
   if (image_gd_check_settings()) {
-    return t('The built-in GD2 toolkit is installed and working properly.');
+    $ret = t('The built-in GD2 toolkit is installed and working properly.');
+    $ret .= form_textfield(t('GD2 JPEG image quality (1-100)'), 'gd_imagejpeg_quality', variable_get('gd_imagejpeg_quality', 75), 64, 64);
+    return $ret;
   }
   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 %url.", array('%url' => '<a href="http://php.net/image">http://php.net/image</a>')));
@@ -192,6 +194,9 @@
  */
 function image_gd_check_settings() {
   if ($check = get_extension_funcs('gd')) {
+    $qual = variable_get('gd_imagejpeg_quality', 75);
+    if (!is_numeric($qual) || ($qual < 0 || $qual > 100))
+        form_set_error('gd_imagejpeg_quality', t("JPEG quality must be in the range [0, 100]"));
     if (in_array('imagegd2', $check)) {
       // GD2 support is available.
       return true;
@@ -293,6 +298,9 @@
   if (!function_exists($close_func)) {
     return false;
   }
+  if ($close_func == 'imagejpeg') {
+    return imagejpeg($res, $destination, variable_get('gd_imagejpeg_quality', 75));
+  }
   return $close_func($res, $destination);
 }
 
