2 declare(strict_types
=1);
3 namespace TYPO3\CMS\Core\Imaging\ImageManipulation
;
6 * This file is part of the TYPO3 CMS project.
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.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use TYPO3\CMS\Core\
Resource\FileInterface
;
46 * @param float $height
48 public function __construct(float $x, float $y, float $width, float $height)
52 $this->width
= $width;
53 $this->height
= $height;
57 * @param array $config
59 * @throws InvalidConfigurationException
61 public static function createFromConfiguration(array $config): Area
70 } catch (\Throwable
$throwable) {
71 throw new InvalidConfigurationException(sprintf('Invalid type for area property given: %s', $throwable->getMessage()), 1485279226, $throwable);
76 * @param array $config
78 * @throws InvalidConfigurationException
80 public static function createMultipleFromConfiguration(array $config): array
83 foreach ($config as $areaConfig) {
84 $areas[] = self
::createFromConfiguration($areaConfig);
92 public static function createEmpty()
94 return new self(0.0, 0.0, 1.0, 1.0);
101 public function asArray(): array
106 'width' => $this->width
,
107 'height' => $this->height
,
112 * @param FileInterface $file
115 public function makeAbsoluteBasedOnFile(FileInterface
$file)
118 $this->x
* $file->getProperty('width'),
119 $this->y
* $file->getProperty('height'),
120 $this->width
* $file->getProperty('width'),
121 $this->height
* $file->getProperty('height')
126 * @param FileInterface $file
129 public function makeRelativeBasedOnFile(FileInterface
$file)
132 $this->x
/ $file->getProperty('width'),
133 $this->y
/ $file->getProperty('height'),
134 $this->width
/ $file->getProperty('width'),
135 $this->height
/ $file->getProperty('height')
142 public function isEmpty()
144 return $this->x
=== 0.0 && $this->y
=== 0.0 && $this->width
=== 1.0 && $this->height
=== 1.0;
150 public function __toString()
152 if ($this->isEmpty()) {
155 return json_encode($this->asArray());