Index: imageapi_gd.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi_gd.module,v
retrieving revision 1.12
diff -u -r1.12 imageapi_gd.module
--- imageapi_gd.module	9 Jul 2008 02:49:47 -0000	1.12
+++ imageapi_gd.module	5 Dec 2008 22:00:08 -0000
@@ -27,6 +27,15 @@
     '#default_value' => variable_get('imageapi_jpeg_quality', 75),
     '#field_suffix' => '%',
   );
+  $form['imageapi_crop_background'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Crop background'),
+    '#description' => t('Hex string specifying the background color to use when cropping images. If not provided, will use the default. Examples: "ABC", "ABCD", "AABBCC", "AABBCCDD".'),
+    '#size' => 10,
+    '#maxlength' => 8,
+    '#default_value' => variable_get('imageapi_crop_background', ''),
+    '#field_prefix' => '#',
+  );
   return system_settings_form($form);
 }
 
@@ -44,9 +53,19 @@
 function imageapi_gd_image_crop(&$image, $x, $y, $width, $height) {
   $res = _gd_create_tmp($image, $width, $height);
 
-  if (!imagecopyresampled($res, $image->res, 0, 0, $x, $y, $width, $height, $width, $height)) {
+  // Fill the background color if desired.
+  $background = variable_get('imageapi_crop_background', '');
+  if (!empty($background)) {
+    $background = imageapi_hex2rgba($background);
+    $background = imagecolorallocatealpha($res, $background[0], $background[1], $background[2], $background[3]);
+    imagefill($res, 0, 0, $background);
+  }
+
+  // Copy the source image to the destination.
+  if (!imagecopyresampled($res, $image->res, -$x, -$y, 0, 0, $image->info['width'], $image->info['height'], $image->info['width'], $image->info['height'])) {
     return false;
   }
+
   // destroy the original image and return the modified image.
   imagedestroy($image->res);
   $image->res = $res;
@@ -174,7 +193,7 @@
   ////   
   ////                  Unsharp Mask for PHP - version 2.1.1   
   ////   
-  ////    Unsharp mask algorithm by Torstein H�nsi 2003-07.   
+  ////    Unsharp mask algorithm by Torstein H�nsi 2003-07.   
   ////             thoensi_at_netcom_dot_no.   
   ////               Please leave this notice.   
   ////   
