Index: outline_designer.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/outline_designer/outline_designer.module,v
retrieving revision 1.10
diff -u -r1.10 outline_designer.module
--- outline_designer.module	10 Feb 2009 21:45:49 -0000	1.10
+++ outline_designer.module	12 Feb 2009 20:08:54 -0000
@@ -141,7 +141,7 @@
     $base_path = base_path();
     foreach ($form['table'] as $key => $row) {
       if($key != '#theme' && $key != '#tree') {
-        $type = db_result(db_query("SELECT type FROM node WHERE nid=%s",$row['nid']['#value']));
+        $type = db_result(db_query("SELECT type FROM {node} WHERE nid=%s",$row['nid']['#value']));
           $form['table'][$key]['title']['#prefix'] = '<img id="node-'. $row['nid']['#value'] .'-icon" src="'. $base_path . variable_get("outline_designer_". $type ."_icon", $od_path ."/images/node.png") .'"  alt="Nid: '. $row['nid']['#value'] .'" title="Nid: '. $row['nid']['#value'] .'" style="float:left; margin:2px;" /><img src="'. $base_path . $od_path .'/images/edit.png" id="node-'. $row['nid']['#value'] .'" class="outline_designer_edit_button" />';
       }
     }
@@ -250,7 +250,7 @@
       '#size' => '10', 
       '#title' => t("Icon for ". $value['name']), 
       /*'#default_value' => variable_get("outline_designer_". $value['type'] ."_icon",  drupal_get_path('module', 'outline_designer') ."/images/node.png"), */
-      '#description' => t("This is what icon will be associated to each content type in the outline designer. They must be 16x16 gif or png format."), 
+      '#description' => t("This icon will be associated with the %type-name content type in the outline designer. The icon must be 16x16, unless an <a href=@toolkit>image toolkit</a> is installed, and in jpg, gif or png format.", array('%type-name' => $value['type'], '@toolkit'=> url('admin/settings/image-toolkit'))), 
       '#required' => FALSE, 
       );
   }
@@ -266,36 +266,16 @@
   $is_writable = file_check_directory($dir,  1);
   if ($is_writable) { 
     $validators = array(
-      'file_validate_is_image' => array(), 
-      'file_validate_image_resolution' => array('85x85'), 
+      'file_validate_is_image' => array(),
+      '_outline_designer_validate_image_resolution' => array('16x16'),
       'file_validate_size' => array(30 * 1024), 
     );
     $result = db_query("SELECT type, name FROM {node_type}");
-    while ($value = db_fetch_array($result)) {
-        if ($file = file_save_upload($form["outline_designer_". $value['type'] ."_icon"],  $validators, $dir)) {
-          $image_ary = image_get_info($file->filepath);
-          if ($image_ary) {
-            //icons must be 16x16,  png or gif format
-            if ($image_ary['mime_type'] != 'image/png' && $image_ary['mime_type'] != 'image/gif') {
-              file_delete($file->filepath);
-              drupal_set_message('Uploaded file must be PNG or GIF format.', 'error');
+      while ($value = db_fetch_array($result)) {
+        if ($file = file_save_upload("outline_designer_". $value['type'] ."_icon",  $validators, $dir)) {
+              drupal_set_message(t('New '. $value['name'] .' icon saved.'));
+              variable_set("outline_designer_". $value['type'] ."_icon",  $file->filepath);
             }
-            else {
-              if ($image_ary['height'] != 16 || $image_ary['width'] != 16) {
-                file_delete($file->filepath);
-                drupal_set_message('Uploaded image must be 16x16 pixels.', 'error');
-              }
-              else {
-                drupal_set_message(t('New '. $value['name'] .' icon saved.'));
-                variable_set("outline_designer_". $value['type'] ."_icon",  $file->filepath);
-              }
-            }
-          }
-          else {
-            file_delete($file->filepath);
-            drupal_set_message('Uploaded file does not appear to be a valid image file. Please try again.', 'error');
-          }
-        }
         else {
       //this is the case when there is no image uploaded to associate the textfield icon to the icon page to use,  this will allow for references to icons already used
       $icon = $form_state['values']["outline_designer_". $value['type'] ."_icon_link"];
@@ -537,4 +517,27 @@
   }
       
   return ($op .' '. $type .' '. $term);
+}
+
+function _outline_designer_validate_image_resolution(&$file, $dimensions) {
+  $errors = array();
+  // Check first that the file is an image.
+  if ($info = image_get_info($file->filepath)) {
+    // Check if the icon matches the given dimensions.
+    list($width, $height) = explode('x', $dimensions);
+    if ($info['width'] != $width || $info['height'] != $height) {
+      // Try to resize the image to fit the dimensions if it doesn't.
+      if (image_get_toolkit() && image_scale_and_crop($file->filepath, $file->filepath, $width, $height)) {
+        drupal_set_message(t('The image was resized to the allowed dimensions of %dimensions pixels.', array('%dimensions' => $dimensions)));
+       // Clear the cached filesize and refresh the image information.
+       clearstatcache();
+       $info = image_get_info($file->filepath);
+       $file->filesize = $info['file_size'];
+      }
+      else {
+        $errors[] = t('Image dimensions need to be %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
+      }
+    }
+  }
+  return $errors;
 }
\ No newline at end of file

