penjadwalan-ga/routes/console.php

40 lines
1.3 KiB
PHP

<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use App\Jobs\CompressLogbookImages;
use Illuminate\Support\Facades\Schedule;
use Illuminate\Support\Facades\Log;
use Intervention\Image\Laravel\Facades\Image;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote')->hourly();
//Schedule::call(function () {
// Log::info('Menjalankan CompressLogbookImages via schedule');
// (new CompressLogbookImages)->handle();
//})->everyMinute()->name('compress-logbook-images')->withoutOverlapping();
Artisan::command('resize:all-logbook', function () {
$directory = storage_path('app/public/thumbnail');
$files = glob($directory . '/*.{jpg,jpeg,png,webp}', GLOB_BRACE);
$count = 0;
foreach ($files as $fullPath) {
try {
$image = Image::read($fullPath)
->scaleDown(width: 800)
->save($fullPath, quality: 85);
$count++;
} catch (\Exception $e) {
Log::error("Gagal resize {$fullPath}: " . $e->getMessage());
}
}
Log::info("Resize selesai: {$count} gambar diubah ukurannya menjadi lebar 800px.");
$this->info("Resize selesai: {$count} gambar diubah ukurannya menjadi lebar 800px.");
});