Make thumbnauil from artisan
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
|||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Intervention\Image\ImageManagerStatic as Image;
|
||||||
|
|
||||||
class Thumbnail extends Command
|
class Thumbnail extends Command
|
||||||
{
|
{
|
||||||
@@ -39,14 +40,30 @@ class Thumbnail extends Command
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$dir = public_path().'/'.config('app.image.dir').'/backup';
|
$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');
|
$w = config('app.image.thumb_width');
|
||||||
$h = config('app.image.thumb_height');
|
$h = config('app.image.thumb_height');
|
||||||
|
|
||||||
$files = Storage::allFiles(public_path()."/".$dir);
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
|
||||||
|
$output->writeln("<info>Starting make thumb</info>");
|
||||||
|
|
||||||
|
|
||||||
|
$files = \File::allFiles($dir);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$thumb_file = str_replace('backup','thumb',$file);
|
||||||
|
|
||||||
|
$output->write($file);
|
||||||
|
$output->writeln("<info> [OK]</info>");
|
||||||
|
|
||||||
|
$image = Image::make($file)->resize($w, $h);
|
||||||
|
\File::makeDirectory(dirname($thumb_file), $mode = 0775, true, true);
|
||||||
|
$image->save($thumb_file);
|
||||||
|
|
||||||
|
$output->write("<info>[NEW] </info>");
|
||||||
|
$output->write($thumb_file);
|
||||||
|
$output->writeln("<info> [OK]</info>");
|
||||||
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
echo $file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user