1
0
Fork 0
mirror of https://github.com/archtechx/laravel-seo.git synced 2025-12-14 02:34:04 +00:00

Refactor to command (#13)

* wip

* wip

* wip
This commit is contained in:
Lars Klopstra 2021-11-15 18:07:09 +01:00 committed by GitHub
parent 5ca343a116
commit 7b24a50bd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 113 additions and 34 deletions

View file

@ -0,0 +1,61 @@
<?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;
}
}