channel->schemas ->where("type", Type::FILES)->values() ->map([$this, 'rebuildThumbnails']); return 0; } public function rebuildThumbnails(Schema $schema): void { $filesDir = storage_path("app/public/" . $schema->path . "/"); $thumbDir = storage_path("app/public/thumbs/" . $schema->path . "/"); if (!file_exists($thumbDir)) { make_dir_r($thumbDir); } if (!file_exists($filesDir)) { make_dir_r($filesDir); } $filesDirIterator = new DirectoryIterator($filesDir); foreach ($filesDirIterator as $file) { if ($file->isDot()) { continue; } try { $image = $this->imageManager->make($filesDir . $file->getFilename()); } catch (Exception $e) { $this->error($e->getMessage()); continue; } $image->fit(300, 300); try { $image->encode('webp', 75)->save($thumbDir . $file->getFilename()); } catch (Exception $e) { $this->error($e->getMessage()); continue; } $this->info($file->getFilename()); } } }