]> git.agnieray.net Git - galette.git/blobdiff - galette/lib/Galette/IO/FileTrait.php
Resize and crop members picture to a fixed ratio
[galette.git] / galette / lib / Galette / IO / FileTrait.php
index 47fa635049ec5f44ee4c781fded14defd1c065b5..6b79e2a44150d32b12b3ff04dbc55f5edb70b50c 100644 (file)
@@ -76,6 +76,7 @@ trait FileTrait
     protected $allowed_extensions = array();
     protected $allowed_mimes = array();
     protected $maxlenght;
+    protected $mincropsize;
 
     public static $mime_types = array(
         'txt'       => 'text/plain',
@@ -181,10 +182,11 @@ trait FileTrait
     /**
      * Initialization
      *
-     * @param string $dest       File destination directory
-     * @param array  $extensions Array of permitted extensions
-     * @param array  $mimes      Array of permitted mime types
-     * @param int    $maxlenght  Maximum lenght for each file
+     * @param string $dest        File destination directory
+     * @param array  $extensions  Array of permitted extensions
+     * @param array  $mimes       Array of permitted mime types
+     * @param int    $maxlenght   Maximum lenght for each file
+     * @param int    $mincropsize Minimum image side size required for cropping
      *
      * @return void
      */
@@ -192,7 +194,8 @@ trait FileTrait
         $dest,
         $extensions = null,
         $mimes = null,
-        $maxlenght = null
+        $maxlenght = null,
+        $mincropsize = null
     ) {
         if ($dest !== null && substr($dest, -1) !== '/') {
             //normalize path
@@ -210,6 +213,11 @@ trait FileTrait
         } else {
             $this->maxlenght = self::MAX_FILE_SIZE;
         }
+        if ($mincropsize !== null) {
+            $this->mincropsize = $mincropsize;
+        } else {
+            $this->mincropsize = self::MIN_CROP_SIZE;
+        }
     }
 
     /**
@@ -492,6 +500,12 @@ trait FileTrait
                     _T("File is too big. Maximum allowed size is %dKo")
                 );
                 break;
+            case self::IMAGE_TOO_SMALL:
+                $error = sprintf(
+                    _T("Image is too small. The minimum image side size allowed is %spx"),
+                    $this->mincropsize
+                );
+                break;
             case self::MIME_NOT_ALLOWED:
                 /** FIXME: should be more descriptive */
                 $error = _T("Mime-Type not allowed");