From 9c57926952abc0f883833d81cfab716d70ed3c21 Mon Sep 17 00:00:00 2001 From: Sander Goorden <72132494+SanderGo@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:36:50 +0200 Subject: [PATCH] Updates GenerateFavicons Listener so it uses Storage (#6) for loading and saving the favicons --- src/Listeners/GenerateFavicons.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Listeners/GenerateFavicons.php b/src/Listeners/GenerateFavicons.php index 8ef0983..01aeadf 100644 --- a/src/Listeners/GenerateFavicons.php +++ b/src/Listeners/GenerateFavicons.php @@ -5,6 +5,8 @@ use Illuminate\Support\Facades\Artisan; use Statamic\Events\GlobalSetSaved; use Statamic\Globals\GlobalSet; +use Illuminate\Support\Facades\Storage; +use Statamic\Facades\URL; class GenerateFavicons { @@ -38,17 +40,17 @@ public function handle(GlobalSetSaved $event) $svg = $globals->inDefaultSite()->get('svg'); $background = $globals->inDefaultSite()->get('background'); - $this->createThumbnail(public_path('favicons/') . $svg, public_path('favicons/icon-180.png'), 180, 180, $background, 15); - $this->createThumbnail(public_path('favicons/') . $svg, public_path('favicons/icon-512.png'), 512, 512, $background, 15); - $this->createThumbnail(public_path('favicons/') . $svg, public_path('favicons/favicon-16x16.png'), 16, 16, 'transparent', false); - $this->createThumbnail(public_path('favicons/') . $svg, public_path('favicons/favicon-32x32.png'), 32, 32, 'transparent', false); + $this->createThumbnail($svg, 'icon-180.png', 180, 180, $background, 15); + $this->createThumbnail($svg, 'icon-512.png', 512, 512, $background, 15); + $this->createThumbnail($svg, 'favicon-16x16.png', 16, 16, 'transparent', false); + $this->createThumbnail($svg, 'favicon-32x32.png', 32, 32, 'transparent', false); Artisan::call('cache:clear'); } private function createThumbnail($import, $export, $width, $height, $background, $border) { - $svg = file_get_contents($import); + $svg = file_get_contents(URL::makeAbsolute(Storage::disk('favicons')->url($import))); $svgObj = simplexml_load_string($svg); $viewBox = explode(' ', $svgObj['viewBox']); $viewBoxWidth = $viewBox[2]; @@ -81,7 +83,7 @@ private function createThumbnail($import, $export, $width, $height, $background, } $im->setImageFormat('png32'); - file_put_contents($export, $im->getImageBlob()); + Storage::disk('favicons')->put($export, $im->getImageBlob()); $im->clear(); $im->destroy(); }