1
0
Fork 0
mirror of https://github.com/archtechx/laravel-seo.git synced 2025-12-12 09:54:03 +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

@ -5,9 +5,7 @@ declare(strict_types=1);
namespace ArchTech\SEO;
use Closure;
use Exception;
use Illuminate\Support\Str;
use Intervention\Image\ImageManager;
/**
* @method $this title(string $title = null, ...$args) Set the title.
@ -179,36 +177,10 @@ class SEOManager
}
/** Enable favicon extension. */
public function favicon(string $path): static
public function favicon(): static
{
if (! class_exists(ImageManager::class)) {
throw new Exception('Intervention not available, please run `composer require intervention/image`');
}
$this->extensions['favicon'] = true;
$doesntHaveFavicon = ! file_exists(public_path('favicon.ico'));
$sourceIconDoesntExist = ! file_exists($path);
if ($sourceIconDoesntExist) {
throw new Exception("Given icon path `{$path}` does not exist.");
}
if ($doesntHaveFavicon) {
// GD driver doesn't support .ico, that's why we use ImageMagick.
$manager = new ImageManager(['driver' => 'imagick']);
$manager
->make($path)
->resize(32, 32)
->save(public_path('favicon.ico'));
$manager
->make($path)
->resize(32, 32)
->save(public_path('favicon.png'));
}
return $this;
}