Index: /trunk/admin/derivatives.php
===================================================================
--- /trunk/admin/derivatives.php	(revision 13034)
+++ /trunk/admin/derivatives.php	(revision 13035)
@@ -68,5 +68,5 @@
       $errors[$type]['crop'] = '[0..100]';
     }
-    
+
     if ($v!=0)
     {
@@ -82,5 +82,5 @@
       }
     }
-    
+
     if (count($errors)==0)
     {
@@ -88,5 +88,5 @@
       $prev_h = intval($pderivative['h']);
     }
-    
+
     $v = intval($pderivative['sharpen']);
     if ($v<0 || $v>100)
@@ -127,7 +127,7 @@
     $watermark->opacity = intval($pwatermark['opacity']);
     $watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh']));
-    
+
     $old_watermark = ImageStdParams::get_watermark();
-    $watermark_changed = 
+    $watermark_changed =
       $watermark->file != $old_watermark->file
       || $watermark->xpos != $old_watermark->xpos
@@ -136,5 +136,5 @@
       || $watermark->opacity != $old_watermark->opacity;
     ImageStdParams::set_watermark($watermark);
-    
+
     $enabled = ImageStdParams::get_defined_type_map();
     $disabled = @unserialize( @$conf['disabled_derivatives'] );
@@ -144,22 +144,22 @@
     }
     $changed_types = array();
-    
+
     foreach(ImageStdParams::get_all_types() as $type)
     {
       $pderivative = $pderivatives[$type];
-      
+
       if ($pderivative['enabled'])
       {
         $new_params = new DerivativeParams(
-            new SizingParams( 
+            new SizingParams(
               array(intval($pderivative['w']), intval($pderivative['h'])),
               round($pderivative['crop'] / 100, 2),
               array(intval($pderivative['minw']), intval($pderivative['minh']))
-              ) 
+              )
           );
         $new_params->sharpen = intval($pderivative['sharpen']);
         $new_params->quality = intval($pderivative['quality']);
         ImageStdParams::apply_global($new_params);
-        
+
         if (isset($enabled[$type]))
         {
@@ -172,5 +172,5 @@
           }
 
-          if ( $same && $new_params->sizing->max_crop != 0 
+          if ( $same && $new_params->sizing->max_crop != 0
               && !size_equals($old_params->sizing->min_size, $new_params->sizing->min_size) )
           {
@@ -178,5 +178,5 @@
           }
 
-          if ( $same && 
+          if ( $same &&
               ( $new_params->sharpen != $old_params->sharpen
               || $new_params->quality > $old_params->quality)
@@ -185,7 +185,7 @@
             $same = false;
           }
-          
+
           if ($same &&
-            ( $new_params->use_watermark != $old_params->use_watermark 
+            ( $new_params->use_watermark != $old_params->use_watermark
              || $new_params->use_watermark && $watermark_changed )
             )
@@ -193,5 +193,5 @@
             $same = false;
           }
-          
+
           if (!$same)
           {
@@ -229,5 +229,5 @@
         $enabled_by[$type] = $enabled[$type];
       }
-    }    
+    }
     ImageStdParams::set_and_save($enabled_by);
     if (count($disabled)==0)
@@ -241,5 +241,5 @@
     }
     $conf['disabled_derivatives']=serialize($disabled);
-    
+
     if (count($changed_types))
     {
@@ -299,5 +299,5 @@
   }
   $template->assign('derivatives', $tpl_vars);
-  
+
   $wm = ImageStdParams::get_watermark();
   $template->assign('watermark', array(
@@ -317,4 +317,8 @@
   $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
 }
+foreach (glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png') as $file)
+{
+  $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
+}
 $watermark_filemap = array( '' => '---' );
 foreach( $watermark_files as $file)
Index: /trunk/admin/include/image.class.php
===================================================================
--- /trunk/admin/include/image.class.php	(revision 13034)
+++ /trunk/admin/include/image.class.php	(revision 13035)
@@ -424,4 +424,9 @@
   {
     $this->image->setInterlaceScheme(Imagick::INTERLACE_LINE);
+    if ($this->get_width()%2 == 0 && $this->get_height()%2 == 0
+      && $this->get_width() > 3*$width)
+    {
+      $this->image->scaleImage($this->get_width()/2, $this->get_height()/2);
+    }
     return $this->image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9);
   }
Index: /trunk/include/derivative_params.inc.php
===================================================================
--- /trunk/include/derivative_params.inc.php	(revision 13034)
+++ /trunk/include/derivative_params.inc.php	(revision 13035)
@@ -71,5 +71,5 @@
   }
 
-  function crop_h($pixels, $coi, $force)
+  function crop_h($pixels, $coi)
   {
     if ($this->width() <= $pixels)
@@ -83,13 +83,5 @@
       $availableL = $coil > $this->l ? $coil - $this->l : 0;
       $availableR = $coir < $this->r ? $this->r - $coir : 0;
-      if ($availableL + $availableR <= $pixels)
-      {
-        if (!$force)
-        {
-          $pixels = $availableL + $availableR;
-          $tlcrop = $availableL;
-        }
-      }
-      else
+      if ($availableL + $availableR >= $pixels)
       {
         if ($availableL < $tlcrop)
@@ -107,5 +99,5 @@
   }
 
-  function crop_v($pixels, $coi, $force)
+  function crop_v($pixels, $coi)
   {
     if ($this->height() <= $pixels)
@@ -119,13 +111,5 @@
       $availableT = $coit > $this->t ? $coit - $this->t : 0;
       $availableB = $coib < $this->b ? $this->b - $coib : 0;
-      if ($availableT + $availableB <= $pixels)
-      {
-        if (!$force)
-        {
-          $pixels = $availableT + $availableB;
-          $tlcrop = $availableT;
-        }
-      }
-      else
+      if ($availableT + $availableB >= $pixels)
       {
         if ($availableT < $tlcrop)
@@ -199,7 +183,7 @@
           if ($h < $this->min_size[1])
           {
-            $idealCropPx = $destCrop->width() - round($destCrop->height() * $this->ideal_size[0] / $this->min_size[1], 0);
+            $idealCropPx = $destCrop->width() - floor($destCrop->height() * $this->ideal_size[0] / $this->min_size[1]);
             $maxCropPx = round($this->max_crop * $destCrop->width());
-            $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi, false);
+            $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi);
           }
         }
@@ -209,7 +193,7 @@
           if ($w < $this->min_size[0])
           {
-            $idealCropPx = $destCrop->height() - round($destCrop->width() * $this->ideal_size[1] / $this->min_size[0], 0);
+            $idealCropPx = $destCrop->height() - floor($destCrop->width() * $this->ideal_size[1] / $this->min_size[0]);
             $maxCropPx = round($this->max_crop * $destCrop->height());
-            $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi, false);
+            $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi);
           }
         }
@@ -268,5 +252,5 @@
       return array('last_mod_time', 'sizing', 'sharpen', 'quality');
   }
-    
+
   function add_url_tokens(&$tokens)
   {
@@ -289,5 +273,5 @@
     return $this->sizing->ideal_size[1];
   }
-  
+
   function is_identity($in_size)
   {
