1
0
Fork 0
mirror of https://github.com/archtechx/laravel-seo.git synced 2025-12-12 09:54:03 +00:00
laravel-seo/src/Commands/GenerateFaviconsCommand.php
Lars Klopstra 7b24a50bd6
Refactor to command (#13)
* wip

* wip

* wip
2021-11-15 18:07:09 +01:00

61 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace ArchTech\SEO\Commands;
use Illuminate\Console\Command;
use Intervention\Image\ImageManager;
class GenerateFaviconsCommand extends Command
{
protected $signature = 'seo:generate-favicons {from?}';
protected $description = 'Generate favicons based on a source file';
public function handle(): int
{
$path = $this->argument('from') ?? public_path('assets/logo.png');
if (! is_string($path)) {
$this->error('The `from` argument must be a string.');
return Command::FAILURE;
}
$this->info('Generating favicons...');
if (! class_exists(ImageManager::class)) {
$this->error('Intervention not available, please run `composer require intervention/image`');
return Command::FAILURE;
}
if (! file_exists($path)) {
$this->error("Given icon path `{$path}` does not exist.");
return Command::FAILURE;
}
// GD driver doesn't support .ico, that's why we use ImageMagick.
$manager = new ImageManager(['driver' => 'imagick']);
$this->comment('Generating ico...');
$manager
->make($path)
->resize(32, 32)
->save(public_path('favicon.ico'));
$this->comment('Generating png...');
$manager
->make($path)
->resize(32, 32)
->save(public_path('favicon.png'));
$this->info('All favicons have been generated!');
return Command::SUCCESS;
}
}