/**
  * Resize uploaded image if necessary
  * if image dimensions are smaller than defined
  * in settings then just save the original
  * and return path to saved image
  *
  * @return mixed string path to saved image
  *
  * @throws \Lampcms\ImageException
  * @throws \Lampcms\DevException
  */
 protected function resize()
 {
     $Editor = \Lampcms\Image\Editor::factory($this->Registry);
     $Editor->loadImage($this->file);
     /**
      * If we get here it means file was an image
      * update USER collection to insert i_last_upload_ts timestamp
      *       will be used to check upload flood
      *       do this now before the actual resize/save
      *       in case resize does not work the upload will still
      *       be counted
      */
     $this->User[Schema::LAST_UPLOAD_TIME] = time();
     $this->User->save();
     $basePath = LAMPCMS_DATA_DIR . 'img';
     $fileName = time();
     $fileExt = $Editor->getExtension();
     $destFolder = Path::prepareByTimestamp($basePath, 'u' . $this->User->getUid(), false);
     $origPath = $destFolder . $fileName . $fileExt;
     if (!copy($this->file, LAMPCMS_DATA_DIR . 'img' . DIRECTORY_SEPARATOR . $origPath)) {
         throw new \Lampcms\DevException('Unable to copy orig file from ' . $this->file . ' to ' . LAMPCMS_DATA_DIR . 'img' . DIRECTORY_SEPARATOR . $origPath);
     }
     $max = $this->EditorOptions['IMAGE_UPLOAD_W_X'];
     list($w, $h) = explode(',', $max);
     $scaleSize = $Editor->getFactor(trim($w), trim($h));
     if ($scaleSize) {
         $resizedPath = $destFolder . $fileName . '_ws' . $fileExt;
         try {
             $Editor->scale($w, $h)->save(LAMPCMS_DATA_DIR . 'img' . DIRECTORY_SEPARATOR . $resizedPath);
             return \str_replace(DIRECTORY_SEPARATOR, '/', $resizedPath);
         } catch (\Exception $e) {
             e('Unable to resize and save uploaded image. ' . $e->getMessage() . ' ' . $e->getFile() . ' on ' . $e->getLine());
             throw new ImageException('@@Unable to resize image@@');
         }
     }
     return \str_replace(DIRECTORY_SEPARATOR, '/', $origPath);
 }