Skip to content

Commit 4dea207

Browse files
committed
Add methods to get the file size and the mime type of cover photos
1 parent e33d925 commit 4dea207

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

wcfsetup/install/files/lib/system/image/cover/photo/DefaultCoverPhoto.class.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace wcf\system\image\cover\photo;
44

55
use wcf\system\style\StyleHandler;
6+
use wcf\util\FileUtil;
67

78
/**
89
* Represents the default cover photo as defined in the style configuration.
@@ -41,6 +42,18 @@ public function getHeight(?string $size = null): int
4142
return $this->getDimensions()['height'];
4243
}
4344

45+
#[\Override]
46+
public function getFileSize(?string $size = null): int
47+
{
48+
return \filesize(StyleHandler::getInstance()->getStyle()->getCoverPhotoLocation());
49+
}
50+
51+
#[\Override]
52+
public function getMimeType(?string $size = null): string
53+
{
54+
return FileUtil::getMimeType(StyleHandler::getInstance()->getStyle()->getCoverPhotoLocation());
55+
}
56+
4457
/**
4558
* @return array{height: int, width: int}
4659
*/

wcfsetup/install/files/lib/system/image/cover/photo/FileCoverPhoto.class.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,31 @@ public function getHeight(?string $size = null): int
5454

5555
return $this->file->height;
5656
}
57+
58+
#[\Override]
59+
public function getFileSize(?string $size = null): int
60+
{
61+
if ($size !== null) {
62+
$thumbnail = $this->file->getThumbnail($size);
63+
if ($thumbnail !== null) {
64+
return \filesize($thumbnail->getPathname());
65+
}
66+
}
67+
68+
return $this->file->fileSize;
69+
}
70+
71+
#[\Override]
72+
public function getMimeType(?string $size = null): string
73+
{
74+
if ($size !== null) {
75+
$thumbnail = $this->file->getThumbnail($size);
76+
if ($thumbnail !== null) {
77+
// Thumbnails are always webp.
78+
return 'image/webp';
79+
}
80+
}
81+
82+
return $this->file->mimeType;
83+
}
5784
}

wcfsetup/install/files/lib/system/image/cover/photo/ICoverPhoto.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ public function getUrl(?string $size = null): string;
1717
public function getWidth(?string $size = null): int;
1818

1919
public function getHeight(?string $size = null): int;
20+
21+
public function getFileSize(?string $size = null): int;
22+
23+
public function getMimeType(?string $size = null): string;
2024
}

0 commit comments

Comments
 (0)