Skip to content

Commit

Permalink
Allow upload svg(unverified)
Browse files Browse the repository at this point in the history
  • Loading branch information
DellZHackintosh authored Jul 3, 2024
1 parent d7b0d18 commit f8e0562
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Api/Controller/UploadLogoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
}
}
18 changes: 13 additions & 5 deletions src/PWATrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit f8e0562

Please sign in to comment.