From 2f61e1342ec6c7e1af246865e610197bf65f5e4b Mon Sep 17 00:00:00 2001 From: root Date: Sun, 26 Sep 2021 20:10:45 +0200 Subject: [PATCH] Make thumbnauil from artisan --- app/Console/Commands/thumbnail.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/thumbnail.php b/app/Console/Commands/thumbnail.php index 7550853..1eb92c6 100644 --- a/app/Console/Commands/thumbnail.php +++ b/app/Console/Commands/thumbnail.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\Storage; +use Intervention\Image\ImageManagerStatic as Image; class Thumbnail extends Command { @@ -39,14 +40,30 @@ class Thumbnail extends Command public function handle() { $dir = public_path().'/'.config('app.image.dir').'/backup'; - $thumb_dir = config('app.image.thumb_dir'); + $thumb_dir = public_path().'/'.config('app.image.thumb_dir').'/thumb'; $w = config('app.image.thumb_width'); $h = config('app.image.thumb_height'); - $files = Storage::allFiles(public_path()."/".$dir); + $output = new \Symfony\Component\Console\Output\ConsoleOutput(); + $output->writeln("Starting make thumb"); + + + $files = \File::allFiles($dir); + foreach ($files as $file) { + $thumb_file = str_replace('backup','thumb',$file); + + $output->write($file); + $output->writeln(" [OK]"); + + $image = Image::make($file)->resize($w, $h); + \File::makeDirectory(dirname($thumb_file), $mode = 0775, true, true); + $image->save($thumb_file); + + $output->write("[NEW] "); + $output->write($thumb_file); + $output->writeln(" [OK]"); + - foreach ($files as $file) { - echo $file; } } }