diff --git a/src/Api/Controller/UploadLogoController.php b/src/Api/Controller/UploadLogoController.php index 274463e..d9f113d 100644 --- a/src/Api/Controller/UploadLogoController.php +++ b/src/Api/Controller/UploadLogoController.php @@ -45,7 +45,8 @@ public function data(ServerRequestInterface $request, Document $document) throw new RouteNotFoundException(); } - $this->filenamePrefix = "pwa-icon-{$size}x{$size}"; + $this->filenamePrefix = $size == 'any' ? "pwa-icon-any" : "pwa-icon-{$size}x{$size}"; + $this->fileExtension = $size == 'any' ? 'svg' : 'png'; $this->filePathSettingKey = "askvortsov-pwa.icon_{$size}_path"; return parent::data($request, $document); @@ -54,7 +55,8 @@ public function data(ServerRequestInterface $request, Document $document) protected function makeImage(UploadedFileInterface $file): Image { $manager = new ImageManager(); + $isSVG = $file->getClientMediaType() == 'image/svg+xml'; - return $manager->make($file->getStream())->resize($this->size, $this->size)->encode('png'); + return $isSVG ? $file : $manager->make($file->getStream())->resize($this->size, $this->size)->encode('png'); } } diff --git a/src/PWATrait.php b/src/PWATrait.php index 2c4a82e..8610860 100644 --- a/src/PWATrait.php +++ b/src/PWATrait.php @@ -42,11 +42,19 @@ protected function getIcons(): array $icons = []; foreach (Util::$ICON_SIZES as $size) { if ($path = $settings->get("askvortsov-pwa.icon_{$size}_path")) { - $icons[] = [ - 'src' => $assetsFilesystem->url($path), - 'sizes' => "{$size}x{$size}", - 'type' => 'image/png', - ]; + if ($size != 'any') { + $icons[] = [ + 'src' => $assetsFilesystem->url($path), + 'sizes' => "{$size}x{$size}", + 'type' => 'image/png', + ]; + } else { + $icons[] = [ + 'src' => $assetsFilesystem->url($path), + 'sizes' => "any", + 'type' => 'image/svg+xml', + ]; + } } } diff --git a/src/Util.php b/src/Util.php index 46eac58..7c54a1c 100644 --- a/src/Util.php +++ b/src/Util.php @@ -13,7 +13,7 @@ class Util { - public static array $ICON_SIZES = [48, 72, 96, 144, 196, 256, 512]; + public static array $ICON_SIZES = [48, 72, 96, 144, 196, 256, 512, 'any']; public static function url_encode($data): string {