‪TYPO3CMS  ‪main
ImageProcessingResult.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use TYPO3\CMS\Core\Type\File\ImageInfo;
22 
33 class ImageProcessingResult
34 {
35  public function __construct(
36  private readonly string $filePath,
40  private readonly int $width,
44  private readonly int $height,
45  private readonly ?ImageInfo $imageInfo = null
46  ) {}
47 
48  public function isFile(): bool
49  {
50  return $this->getImageInfoObject()->isFile();
51  }
52 
53  public function getRealPath(): string
54  {
55  return $this->getImageInfoObject()->getRealPath();
56  }
57 
61  public function getWidth(): int
62  {
63  return $this->width;
64  }
65 
69  public function getHeight(): int
70  {
71  return $this->height;
72  }
73 
74  public function getExtension(): string
75  {
76  return $this->getImageInfoObject()->getExtension();
77  }
78 
79  public static function createFromImageInfo(ImageInfo $imageInfo): self
80  {
81  return new self($imageInfo->getRealPath(), $imageInfo->getWidth(), $imageInfo->getHeight(), $imageInfo);
82  }
83 
87  public function toLegacyArray(): array
88  {
89  return [
90  0 => $this->width,
91  1 => $this->height,
92  2 => $this->getExtension(),
93  3 => $this->filePath,
94  ];
95  }
96 
97  private function getImageInfoObject(): ImageInfo
98  {
99  return !$this->imageInfo instanceof ImageInfo
100  ? GeneralUtility::makeInstance(ImageInfo::class, $this->filePath)
101  : $this->imageInfo;
102  }
103 }
‪TYPO3\CMS\Core\Imaging
Definition: Dimension.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52