mirror of
https://github.com/archtechx/laravel-seo.git
synced 2025-12-14 02:34:04 +00:00
parent
5ca343a116
commit
7b24a50bd6
5 changed files with 113 additions and 34 deletions
61
src/Commands/GenerateFaviconsCommand.php
Normal file
61
src/Commands/GenerateFaviconsCommand.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue