예제 #1
0
 /**
  * Create thumbs for file
  *
  * @param File $file
  * @return array
  * @throws \Crip\FileManager\Exceptions\FileManagerException
  */
 public function create(File $file)
 {
     foreach ($this->sizes as $size_key => $size) {
         $img = app(ImageManager::class)->make($file->fullPath());
         $new_path = $file->getPath()->thumbPath($size_key);
         FileSystem::mkdir($new_path, 777, true);
         switch ($size[2]) {
             case 'width':
                 // resize the image to a width of $sizes[ 0 ] and constrain aspect ratio (auto height)
                 $img->resize($size[0], null, function ($constraint) {
                     $constraint->aspectRatio();
                 });
                 break;
             case 'height':
                 // resize the image to a height of $sizes[ 1 ] and constrain aspect ratio (auto width)
                 $img->resize(null, $size[1], function ($constraint) {
                     $constraint->aspectRatio();
                 });
                 break;
                 // 'resize'
             // 'resize'
             default:
                 $img->fit($size[0], $size[1]);
                 break;
         }
         $img->save($file->getPath()->thumbPath($size_key, $file));
     }
     return $this->details($file);
 }
예제 #2
0
 /**
  * Initialise new instance of Path service
  */
 public function __construct()
 {
     $this->thumb_dir = FileManager::package()->config('thumbs_dir', 'thumbs');
     $root_dir = FileSystem::canonical(FileManager::package()->config('target_dir', 'storage/uploads'));
     $this->sys_root_dir = base_path($root_dir);
     if (!FileSystem::exists($this->sys_root_dir)) {
         FileSystem::mkdir($this->sys_root_dir, 777);
     }
     $this->updatePath();
 }
 /**
  * @param Folder $folder
  * @return Folder
  * @throws FileManagerException
  */
 public function createFolder(Folder $folder)
 {
     if (FileSystem::exists($folder->fullPath())) {
         $this->uniqueName->folder($folder);
     }
     // TODO: add this list to config
     if (in_array($folder->name(), ['create', 'delete', 'rename', 'null'])) {
         throw new FileManagerException($this, 'err_folder_this_name_cant_be_used');
     }
     FileSystem::mkdir($folder->fullPath(), 777, true);
     return $folder;
 }