diff --git a/htdocs/core/ajaxfileupload.php b/htdocs/core/ajaxfileupload.php
index 8af04307419672c2d67eb540bba5049d89d89fdb..3420bda0a951a27004302e112ab40cf0b6966e02 100644
--- a/htdocs/core/ajaxfileupload.php
+++ b/htdocs/core/ajaxfileupload.php
@@ -72,18 +72,14 @@ class UploadHandler
                 // uploaded images. You can also add additional versions with
                 // their own upload directories:
                 /*
-                'large' => array(
+                'small' => array(
                     'upload_dir' => dirname(__FILE__).'/files/',
-                    'upload_url' => dirname($_SERVER['PHP_SELF']).'/files/',
-                    'max_width' => 1920,
-                    'max_height' => 1200
+                    'upload_url' => dirname($_SERVER['PHP_SELF']).'/files/'
                 ),
                 */
-                'thumbnail' => array(
+                'thumbs' => array(
                     'upload_dir' => $conf->$element->dir_output . '/' . $fk_element . '/thumbs/',
-                    'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$fk_element.'/thumbs/',
-                    'max_width' => 40,
-                    'max_height' => 40
+                    'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$fk_element.'/thumbs/'
                 )
             )
         );
@@ -126,6 +122,7 @@ class UploadHandler
      *  options is array('max_width', 'max_height')
      */
     private function create_scaled_image($file_name, $options) {
+        global $maxwidthmini, $maxheightmini;
         $file_path = $this->options['upload_dir'].$file_name;
         $new_file_path = $options['upload_dir'].$file_name;
 
@@ -135,51 +132,8 @@ class UploadHandler
 	        if (!$img_width || !$img_height) {
 	            return false;
 	        }
-	        $scale = min(
-	            $options['max_width'] / $img_width,
-	            $options['max_height'] / $img_height
-	        );
-	        if ($scale > 1) {
-	            $scale = 1;
-	        }
-	        $new_width = $img_width * $scale;
-	        $new_height = $img_height * $scale;
-
-
-	        $res=true;
-	        $res=vignette($file_path,$options['max_width'],$options['max_height'],'_mini');
-            /* Replaced with more efficient function vignette
-	        $new_img = @imagecreatetruecolor($new_width, $new_height);
-	        switch (strtolower(substr(strrchr($file_name, '.'), 1))) {
-	            case 'jpg':
-	            case 'jpeg':
-	                $src_img = @imagecreatefromjpeg($file_path);
-	                $write_image = 'imagejpeg';
-	                break;
-	            case 'gif':
-	                $src_img = @imagecreatefromgif($file_path);
-	                $write_image = 'imagegif';
-	                break;
-	            case 'png':
-	                $src_img = @imagecreatefrompng($file_path);
-	                $write_image = 'imagepng';
-	                break;
-	            default:
-	                $src_img = $image_method = null;
-	        }
-	        $success = $src_img && @imagecopyresampled(
-	            $new_img,
-	            $src_img,
-	            0, 0, 0, 0,
-	            $new_width,
-	            $new_height,
-	            $img_width,
-	            $img_height
-	        ) && $write_image($new_img, $new_file_path);
-	        // Free up memory (imagedestroy does not delete files):
-	        @imagedestroy($src_img);
-	        @imagedestroy($new_img);
-            */
+
+	        $res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini');
 
 	        //return $success;
 	        if (preg_match('/error/i',$res)) return false;
diff --git a/htdocs/lib/images.lib.php b/htdocs/lib/images.lib.php
index d7841216fdb13c94f6df376f0b6fdca21fcd71d4..f561fd772fbbb0f20a0cd8a173df94881bd2ac0c 100644
--- a/htdocs/lib/images.lib.php
+++ b/htdocs/lib/images.lib.php
@@ -21,7 +21,7 @@
 /**
  *  \file		htdocs/lib/images.lib.php
  *  \brief		Set of function for manipulating images
- * 	\version	$Id: images.lib.php,v 1.22 2011/07/05 22:40:36 eldy Exp $
+ * 	\version	$Id: images.lib.php,v 1.23 2011/07/05 22:51:24 eldy Exp $
  */
 
 // Define size of logo small and mini
@@ -275,7 +275,8 @@ function dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $s
 	// Set permissions on file
 	if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
 
-	// Free memory
+	// Free memory. This does not delete image.
+    imagedestroy($img);
 	imagedestroy($imgThumb);
 
 	clearstatcache();	// File was replaced by a modified one, so we clear file caches.
@@ -510,8 +511,9 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
 	// Set permissions on file
 	if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
 
-	// Free memory
-	imagedestroy($imgThumb);
+    // Free memory. This does not delete image.
+    imagedestroy($img);
+    imagedestroy($imgThumb);
 
 	return $imgThumbName;
 }