'filesize' => $file->fileSize,
'fileType' => $file->mimeType,
'isImage' => $file->isImage(),
-
- // TODO: Do we want to cache this data?
- 'height' => \getimagesize($file->getPath() . $file->getSourceFilename())[1],
- // TODO: Do we want to cache this data?
- 'width' => \getimagesize($file->getPath() . $file->getSourceFilename())[0],
-
- // TODO: This is awful.
- 'thumbnailType' => $file->getThumbnail('') ? $file->mimeType : '',
- 'thumbnailWidth' => $file->getThumbnail('') ? \getimagesize($file->getThumbnail('')->getPath() . $file->getThumbnail('')->getSourceFilename())[0] : 0,
- 'thumbnailHeight' => $file->getThumbnail('') ? \getimagesize($file->getThumbnail('')->getPath() . $file->getThumbnail('')->getSourceFilename())[1] : 0,
-
- // TODO: This is awful.
- 'tinyThumbnailType' => $file->getThumbnail('tiny') ? $file->mimeType : '',
- 'tinyThumbnailWidth' => $file->getThumbnail('tiny') ? \getimagesize($file->getThumbnail('tiny')->getPath() . $file->getThumbnail('tiny')->getSourceFilename())[0] : 0,
- 'tinyThumbnailHeight' => $file->getThumbnail('tiny') ? \getimagesize($file->getThumbnail('tiny')->getPath() . $file->getThumbnail('tiny')->getSourceFilename())[1] : 0,
-
+ 'height' => $file->height,
+ 'width' => $file->width,
+ 'thumbnailType' => $file->getThumbnail('')?->getMimeType() ?: '',
+ 'thumbnailWidth' => $file->getThumbnail('')?->width ?: 0,
+ 'thumbnailHeight' => $file->getThumbnail('')?->height ?: 0,
+ 'tinyThumbnailType' => $file->getThumbnail('tiny')?->getMimeType() ?: '',
+ 'tinyThumbnailWidth' => $file->getThumbnail('tiny')?->width ?: 0,
+ 'tinyThumbnailHeight' => $file->getThumbnail('tiny')?->height ?: 0,
default => parent::__get($name),
};
}
* @property-read string $fileHash
* @property-read string $typeName
* @property-read string $mimeType
+ * @property-read int|null $width
+ * @property-read int|null $height
*/
class File extends DatabaseObject
{
public static function createFromTemporary(FileTemporary $fileTemporary): File
{
$mimeType = FileUtil::getMimeType($fileTemporary->getPath() . $fileTemporary->getFilename());
+ $isImage = match ($mimeType) {
+ 'image/gif' => true,
+ 'image/jpeg' => true,
+ 'image/png' => true,
+ 'image/webp' => true,
+ default => false,
+ };
+
+ $width = $height = null;
+ if ($isImage) {
+ [$width, $height] = \getimagesize($fileTemporary->getPath() . $fileTemporary->getFilename());
+ }
$fileAction = new FileAction([], 'create', ['data' => [
'filename' => $fileTemporary->filename,
'fileHash' => $fileTemporary->fileHash,
'typeName' => $fileTemporary->typeName,
'mimeType' => $mimeType,
+ 'width' => $width,
+ 'height' => $height,
]]);
$file = $fileAction->executeAction()['returnValues'];
\assert($file instanceof File);
* @property-read string $identifier
* @property-read string $fileHash
* @property-read string $fileExtension
+ * @property-read int $width
+ * @property-read int $height
*/
class FileThumbnail extends DatabaseObject implements ILinkableObject
{
);
}
+ public function getMimeType(): string
+ {
+ return 'image/webp';
+ }
+
private function getRelativePath(): string
{
$folderA = \substr($this->fileHash, 0, 2);
ThumbnailFormat $format,
string $filename
): FileThumbnail {
- $mimeType = FileUtil::getMimeType($filename);
- $fileExtension = match ($mimeType) {
- 'image/gif' => 'gif',
- 'image/jpg', 'image/jpeg' => 'jpg',
- 'image/png' => 'png',
- 'image/webp' => 'webp',
- };
+ [$width, $height] = \getimagesize($filename);
$action = new FileThumbnailAction([], 'create', [
'data' => [
'fileID' => $file->fileID,
'identifier' => $format->identifier,
'fileHash' => hash_file('sha256', $filename),
- 'fileExtension' => $fileExtension,
+ 'fileExtension' => 'webp',
+ 'width' => $width,
+ 'height' => $height,
],
]);
$fileThumbnail = $action->executeAction()['returnValues'];
fileHash CHAR(64) NOT NULL,
typeName VARCHAR(255) NOT NULL,
mimeType VARCHAR(255) NOT NULL,
+ width INT,
+ height INT
);
DROP TABLE IF EXISTS wcf1_file_temporary;
fileID INT NOT NULL,
identifier VARCHAR(50) NOT NULL,
fileHash CHAR(64) NOT NULL,
- fileExtension VARCHAR(10) NOT NULL
+ fileExtension VARCHAR(10) NOT NULL,
+ width INT NOT NULL,
+ height INT NOT NULL
);
/* As the flood control table can be a high traffic table and as it is periodically emptied,