Index: /trunk/admin/include/functions_upload.inc.php
===================================================================
--- /trunk/admin/include/functions_upload.inc.php	(revision 10551)
+++ /trunk/admin/include/functions_upload.inc.php	(revision 10552)
@@ -26,5 +26,5 @@
 // add default event handler for image and thumbnail resize
 add_event_handler('upload_image_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7);
-add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7);
+add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 9);
 
 function get_upload_form_config()
@@ -89,4 +89,14 @@
       'can_be_null' => false,
       'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'),
+      ),
+
+    'thumb_crop' => array(
+      'default' => false,
+      'can_be_null' => false,
+      ),
+
+    'thumb_follow_orientation' => array(
+      'default' => true,
+      'can_be_null' => false,
       ),
   
@@ -327,5 +337,7 @@
     $conf['upload_form_thumb_maxheight'],
     $conf['upload_form_thumb_quality'],
-    true
+    true,
+    $conf['upload_form_thumb_crop'],
+    $conf['upload_form_thumb_follow_orientation']
     );
   
@@ -518,5 +530,5 @@
 }
 
-function pwg_image_resize($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false)
+function pwg_image_resize($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false, $crop=false, $follow_orientation=true)
 {
   if ($result !== false)
@@ -530,13 +542,13 @@
   if (is_imagick() and $extension != 'gif')
   {
-    return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata);
+    return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata, $crop, $follow_orientation);
   }
   else
   {
-    return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality);
-  }
-}
-
-function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality)
+    return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $crop, $follow_orientation);
+  }
+}
+
+function pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $crop=false, $follow_orientation=true)
 {
   if (!function_exists('gd_info'))
@@ -577,5 +589,11 @@
   $source_width  = imagesx($source_image); 
   $source_height = imagesy($source_image);
-  
+
+  // Crop
+  if ($crop)
+  {
+    $coord = get_crop_coord($source_width, $source_height, $max_width, $max_height, $follow_orientation);
+  }
+
   $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
 
@@ -596,6 +614,6 @@
     0,
     0,
-    0,
-    0,
+    $crop ? $coord['x'] : 0,
+    $crop ? $coord['y'] : 0,
     $resize_dimensions['width'],
     $resize_dimensions['height'],
@@ -631,5 +649,5 @@
 }
 
-function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false)
+function pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false, $crop=false, $follow_orientation=true)
 {
   // extension of the picture filename
@@ -647,4 +665,11 @@
   $source_width  = $image->getImageWidth();
   $source_height = $image->getImageHeight();
+
+  // Crop
+  if ($crop)
+  {
+    $coord = get_crop_coord($source_width, $source_height, $max_width, $max_height, $follow_orientation);
+    $image->cropImage($source_width, $source_height, $coord['x'], $coord['y']);
+  }
   
   $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
@@ -726,4 +751,35 @@
 
   return $rotation;
+}
+
+function get_crop_coord(&$source_width, &$source_height, &$max_width, &$max_height, $follow_orientation)
+{
+  $x = 0;
+  $y = 0;
+
+  if ($source_width < $source_height and $follow_orientation)
+  {
+    list($width, $height) = array($max_height, $max_width);
+    $max_width = $width;
+    $max_height = $height;
+  }
+
+  $img_ratio = $source_width / $source_height;
+  $dest_ratio = $max_width / $max_height;
+
+  if($dest_ratio > $img_ratio)
+  {
+    $destHeight = round($source_width * $max_height / $max_width);
+    $y = round(($source_height - $destHeight) / 2 );
+    $source_height = $destHeight;
+  }
+  elseif ($dest_ratio < $img_ratio)
+  {
+    $destWidth = round($source_height * $max_width / $max_height);
+    $x = round(($source_width - $destWidth) / 2 );
+    $source_width = $destWidth;
+  }
+
+  return array('x' => $x, 'y' => $y);
 }
 
Index: /trunk/admin/photos_add_settings.php
===================================================================
--- /trunk/admin/photos_add_settings.php	(revision 10551)
+++ /trunk/admin/photos_add_settings.php	(revision 10552)
@@ -76,5 +76,7 @@
   $fields[] = 'thumb_maxheight';
   $fields[] = 'thumb_quality';
-  
+  $fields[] = 'thumb_crop';
+  $fields[] = 'thumb_follow_orientation';
+
   foreach ($fields as $field)
   {
Index: /trunk/admin/themes/default/template/photos_add_settings.tpl
===================================================================
--- /trunk/admin/themes/default/template/photos_add_settings.tpl	(revision 10551)
+++ /trunk/admin/themes/default/template/photos_add_settings.tpl	(revision 10552)
@@ -1,8 +1,13 @@
-{footer_script}{literal}
+{footer_script}
+var width = '{'Width'|@translate}';
+var height = '{'Height'|@translate}';
+var max_width = '{'Maximum Width'|@translate}';
+var max_height = '{'Maximum Height'|@translate}';
+
+{literal}
 jQuery(document).ready(function(){
   function toggleResizeFields(prefix) {
     var checkbox = jQuery("#"+prefix+"_resize");
     var needToggle = jQuery("input[name^="+prefix+"_]").not(checkbox).not(jQuery("#hd_keep")).parents('tr');
-
 
     if (jQuery(checkbox).is(':checked')) {
@@ -22,4 +27,18 @@
   }
 
+  function toggleCropFields(prefix) {
+    if (jQuery("#"+prefix+"_crop").is(':checked')) {
+      jQuery("#"+prefix+"_width_th").text(width);
+      jQuery("#"+prefix+"_height_th").text(height);
+      jQuery("#"+prefix+"_follow_orientation_tr").show();
+    }
+    else {
+      jQuery("#"+prefix+"_width_th").text(max_width);
+      jQuery("#"+prefix+"_height_th").text(max_height);
+      jQuery("#"+prefix+"_follow_orientation_tr").hide();
+    }
+
+  }
+
   toggleResizeFields("websize");
   jQuery("#websize_resize").click(function () {toggleResizeFields("websize")});
@@ -27,4 +46,7 @@
   toggleResizeFields("hd");
   jQuery("#hd_resize").click(function () {toggleResizeFields("hd")});
+
+  toggleCropFields("thumb");
+  jQuery("#thumb_crop").click(function () {toggleCropFields("thumb")});
 
   function toggleHdFields() {
@@ -82,9 +104,17 @@
     <table>
       <tr>
-        <th>{'Maximum Width'|@translate}</th>
+        <th><label for="thumb_crop">{'Crop'|@translate}</label></th>
+        <td><input type="checkbox" name="thumb_crop" id="thumb_crop" {$values.thumb_crop}></td>
+      </tr>
+      <tr id="thumb_follow_orientation_tr">
+        <th><label for="thumb_follow_orientation">{'Follow Orientation'|@translate}</label></th>
+        <td><input type="checkbox" name="thumb_follow_orientation" id="thumb_follow_orientation" {$values.thumb_follow_orientation}></td>
+      </tr>
+      <tr>
+        <th id="thumb_width_th">{'Maximum Width'|@translate}</th>
         <td><input type="text" name="thumb_maxwidth" value="{$values.thumb_maxwidth}" size="4" maxlength="4"> {'pixels'|@translate}</td>
       </tr>
       <tr>
-        <th>{'Maximum Height'|@translate}</th>
+        <th id="thumb_height_th">{'Maximum Height'|@translate}</th>
         <td><input type="text" name="thumb_maxheight" value="{$values.thumb_maxheight}" size="4" maxlength="4"> {'pixels'|@translate}</td>
       </tr>
Index: /trunk/language/en_UK/admin.lang.php
===================================================================
--- /trunk/language/en_UK/admin.lang.php	(revision 10551)
+++ /trunk/language/en_UK/admin.lang.php	(revision 10552)
@@ -826,3 +826,7 @@
 $lang['Please wait...'] = 'Please wait...';
 $lang['Ignore All'] = 'Ignore All';
+$lang['Crop'] = 'Crop';
+$lang['Width'] = 'Width';
+$lang['Height'] = 'Height';
+$lang['Follow Orientation'] = 'Follow Orientation';
 ?>
Index: /trunk/language/fr_FR/admin.lang.php
===================================================================
--- /trunk/language/fr_FR/admin.lang.php	(revision 10551)
+++ /trunk/language/fr_FR/admin.lang.php	(revision 10552)
@@ -835,5 +835,9 @@
 $lang['Unable to dump database.'] = 'Impossible de sauvegarder la base de données.';
 $lang['Some upgrades are available for extensions.'] = 'Des mises à jour sont disponibles pour les extensions.';
-$lang['Please wait...'] = 'Please wait...';
+$lang['Please wait...'] = 'Veuillez patienter...';
 $lang['Ignore All'] = 'Tout ignorer';
+$lang['Crop'] = 'Retailler';
+$lang['Width'] = 'Largeur';
+$lang['Height'] = 'Hauteur';
+$lang['Follow Orientation'] = "Respecter l'orientation";
 ?>
