From 4b4197d3ade97e826d096dcedc528aff70ed9eb4 Mon Sep 17 00:00:00 2001 From: Al Amin Ahamed Date: Sat, 29 Mar 2025 09:41:06 +0600 Subject: [PATCH] fix: update package names and handle Intervention Image versioning in favicon generation --- composer.json | 4 +-- phpstan.neon | 2 +- src/Commands/GenerateFaviconsCommand.php | 43 +++++++++++++++++------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 4aa74ab..1731a6e 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,10 @@ }, "require-dev": { "orchestra/testbench": ">=8.0", - "nunomaduro/larastan": ">=2.4", + "larastan/larastan": ">=2.4", "pestphp/pest": ">=2.0", "pestphp/pest-plugin-laravel": ">=2.0", - "intervention/image": "^2.7" + "intervention/image": "^2.0|^3.0" }, "extra": { "laravel": { diff --git a/phpstan.neon b/phpstan.neon index d8f0cf3..0f34444 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - ./vendor/nunomaduro/larastan/extension.neon + - ./vendor/larastan/larastan/extension.neon parameters: paths: diff --git a/src/Commands/GenerateFaviconsCommand.php b/src/Commands/GenerateFaviconsCommand.php index 6117ef4..75e3ab0 100644 --- a/src/Commands/GenerateFaviconsCommand.php +++ b/src/Commands/GenerateFaviconsCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace ArchTech\SEO\Commands; use Illuminate\Console\Command; -use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\ImageManager; class GenerateFaviconsCommand extends Command @@ -38,22 +37,40 @@ class GenerateFaviconsCommand extends Command return self::FAILURE; } - // GD driver doesn't support .ico, that's why we use ImageMagick. - $manager = new ImageManager(ImagickDriver::class); + // Check Intervention Image version + $isV3 = interface_exists('\Intervention\Image\Interfaces\DriverInterface'); - $this->comment('Generating ico...'); + if ($isV3) { + // v3.x implementation + $manager = new ImageManager( + new \Intervention\Image\Drivers\Imagick\Driver() + ); - $manager - ->make($path) - ->resize(32, 32) - ->save(public_path('favicon.ico')); + $this->comment('Generating ico...'); + $image = $manager->read($path); + $image->resize(32, 32); + $image->save(public_path('favicon.ico')); - $this->comment('Generating png...'); + $this->comment('Generating png...'); + $image = $manager->read($path); + $image->resize(32, 32); + $image->save(public_path('favicon.png')); + } else { + // v2.x implementation + $manager = new ImageManager(['driver' => 'imagick']); // @phpstan-ignore argument.type - $manager - ->make($path) - ->resize(32, 32) - ->save(public_path('favicon.png')); + $this->comment('Generating ico...'); + $manager // @phpstan-ignore method.notFound + ->make($path) + ->resize(32, 32) + ->save(public_path('favicon.ico')); + + $this->comment('Generating png...'); + $manager // @phpstan-ignore method.notFound + ->make($path) + ->resize(32, 32) + ->save(public_path('favicon.png')); + } $this->info('All favicons have been generated!');